Skip to content

Commit 9abe49d

Browse files
committed
Moves files.
1 parent 93d4723 commit 9abe49d

9 files changed

Lines changed: 116 additions & 156 deletions

File tree

McBopomofo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@
196196
D43737C82DF9C35100D9707C /* InputMethodController+KeyHandlerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InputMethodController+KeyHandlerDelegate.swift"; sourceTree = "<group>"; };
197197
D43737CA2DF9C48200D9707C /* InputMethodController+CandidateControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InputMethodController+CandidateControllerDelegate.swift"; sourceTree = "<group>"; };
198198
D43FC40A2B23788400ED5A1C /* InputMacro.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMacro.swift; sourceTree = "<group>"; };
199-
D4451AC72E68830000E8F5AB /* SystemCharacterInfo */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = SystemCharacterInfo; sourceTree = "<group>"; };
200199
D449AD5E2B393C00000C5812 /* InputMacroTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputMacroTests.swift; sourceTree = "<group>"; };
201200
D449AD602B39506D000C5812 /* ServiceProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServiceProviderTests.swift; sourceTree = "<group>"; };
202201
D44FB74427915555003C80A6 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
@@ -231,6 +230,7 @@
231230
D4E33D9127A838F7006DB1CF /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
232231
D4E569DA27A34CC100AC2CEF /* KeyHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyHandler.h; sourceTree = "<group>"; };
233232
D4E569DB27A34CC100AC2CEF /* KeyHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyHandler.mm; sourceTree = "<group>"; };
233+
D4E5EEE22E68A9B30068BC58 /* SystemCharacterInfo */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SystemCharacterInfo; path = Packages/SystemCharacterInfo; sourceTree = "<group>"; };
234234
D4E791782B52CDCF00676A68 /* ChineseNumbers */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = ChineseNumbers; path = Packages/ChineseNumbers; sourceTree = "<group>"; };
235235
D4EE67572B39685F00F062DE /* DictionaryServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DictionaryServiceTests.swift; sourceTree = "<group>"; };
236236
D4EE67592B39968900F062DE /* dictionary_service.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = dictionary_service.json; sourceTree = "<group>"; };
@@ -456,6 +456,7 @@
456456
D427F766278C9CBD004A2160 /* Packages */ = {
457457
isa = PBXGroup;
458458
children = (
459+
D4E5EEE22E68A9B30068BC58 /* SystemCharacterInfo */,
459460
D41B626A2B86EAD400583148 /* BopomofoBraille */,
460461
D4E791782B52CDCF00676A68 /* ChineseNumbers */,
461462
D427F768278C9D0D004A2160 /* CandidateUI */,
@@ -465,7 +466,6 @@
465466
D427F7BF27908EAC004A2160 /* OpenCCBridge */,
466467
D47D73C027A71FFA00255A50 /* FSEventStreamHelper */,
467468
D4C9CAAF27AAC8EC0058DFEA /* NSStringUtils */,
468-
D4451AC72E68830000E8F5AB /* SystemCharacterInfo */,
469469
);
470470
name = Packages;
471471
sourceTree = "<group>";
File renamed without changes.

Packages/SystemCharacterInfo/Package.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.1
1+
// swift-tools-version: 5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -11,11 +11,19 @@ let package = Package(
1111
name: "SystemCharacterInfo",
1212
targets: ["SystemCharacterInfo"]),
1313
],
14+
dependencies: [
15+
// SQLite.swift – A type-safe SQLite wrapper for Swift
16+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.15.4")
17+
],
1418
targets: [
1519
// Targets are the basic building blocks of a package, defining a module or a test suite.
1620
// Targets can depend on other targets in this package and products from dependencies.
1721
.target(
18-
name: "SystemCharacterInfo"),
22+
name: "SystemCharacterInfo",
23+
dependencies: [
24+
.product(name: "SQLite", package: "SQLite.swift")
25+
]
26+
),
1927
.testTarget(
2028
name: "SystemCharacterInfoTests",
2129
dependencies: ["SystemCharacterInfo"]
Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
1-
// The Swift Programming Language
2-
// https://docs.swift.org/swift-book
1+
// Copyright (c) 2022 and onwards The McBopomofo Authors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation
5+
// files (the "Software"), to deal in the Software without
6+
// restriction, including without limitation the rights to use,
7+
// copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following
10+
// conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be
13+
// included in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
// OTHER DEALINGS IN THE SOFTWARE.
23+
24+
25+
import SQLite
26+
import Foundation
27+
28+
private let path = "/System/Library/PrivateFrameworks/CoreChineseEngine.framework/Versions/A/Resources/CharacterAccessibilityData.sqlite"
29+
30+
public struct CharacterInfo {
31+
public let character: String?
32+
public let components: String?
33+
public let simplifiedExample: String?
34+
public let traditionalExample: String?
35+
}
36+
37+
public enum SystemCharacterInfoError : Error, LocalizedError {
38+
case notFound
39+
40+
public var errorDescription: String? {
41+
switch self {
42+
case .notFound:
43+
"Not Found"
44+
}
45+
}
46+
}
47+
48+
public class SystemCharacterInfo {
49+
private var db: Connection
50+
51+
public init() throws {
52+
self.db = try Connection(path)
53+
}
54+
55+
public func read(string: String) throws -> CharacterInfo {
56+
let zentry = Table("ZENTRY")
57+
let zcharacter = Expression<String>("ZCHARACTER")
58+
let query = zentry.filter(zcharacter == string).limit(1)
59+
let result = try db.prepare(query)
60+
let rows = Array(result)
61+
guard let row = rows.first else {
62+
throw SystemCharacterInfoError.notFound
63+
}
64+
let ZSIMPLIFIEDEXEMPLAR = Expression<String?>("ZSIMPLIFIEDEXEMPLAR")
65+
let ZTRADITIONALEXEMPLAR = Expression<String?>("ZTRADITIONALEXEMPLAR")
66+
let ZCOMPONENTS = Expression<String?>("ZCOMPONENTS")
67+
let ZCHARACTER = Expression<String?>("ZCHARACTER")
68+
69+
return CharacterInfo(
70+
character: try? row.get(ZCHARACTER),
71+
components: try? row.get(ZCOMPONENTS),
72+
simplifiedExample: try? row.get(ZSIMPLIFIEDEXEMPLAR),
73+
traditionalExample: try? row.get(ZTRADITIONALEXEMPLAR)
74+
)
75+
}
76+
}
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1+
// Copyright (c) 2022 and onwards The McBopomofo Authors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person
4+
// obtaining a copy of this software and associated documentation
5+
// files (the "Software"), to deal in the Software without
6+
// restriction, including without limitation the rights to use,
7+
// copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following
10+
// conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be
13+
// included in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
// OTHER DEALINGS IN THE SOFTWARE.
23+
24+
125
import Testing
226
@testable import SystemCharacterInfo
327

428
@Test func example() async throws {
5-
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
29+
let info = try SystemCharacterInfo()
30+
let result = try info.read(string: "")
31+
#expect(result.character == "")
32+
#expect(result.components == "火登")
633
}

SystemCharacterInfo/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

SystemCharacterInfo/Package.swift

Lines changed: 0 additions & 32 deletions
This file was deleted.

SystemCharacterInfo/Sources/SystemCharacterInfo/SystemCharacterInfo.swift

Lines changed: 0 additions & 76 deletions
This file was deleted.

SystemCharacterInfo/Tests/SystemCharacterInfoTests/SystemCharacterInfoTests.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)