Skip to content

Commit

Permalink
add dependency SwiftCF
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddxxx committed Oct 8, 2019
1 parent 160205a commit 4a383ce
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 773 deletions.
37 changes: 25 additions & 12 deletions LyricsX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
BB0BE95E1F44508F0068FF67 /* Fabric.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB0BE95C1F44508F0068FF67 /* Fabric.framework */; };
BB1A3185207B261500406E32 /* Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1A3184207B261500406E32 /* Regex.swift */; };
BB1B2FFD20E8780A002F1AF8 /* CFExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B2FFC20E8780A002F1AF8 /* CFExtension.swift */; };
BB1B2FFF20E87838002F1AF8 /* CTExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B2FFE20E87838002F1AF8 /* CTExtension.swift */; };
BB1B300120E8788C002F1AF8 /* CGExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B300020E8788C002F1AF8 /* CGExtension.swift */; };
BB1B300320E878AE002F1AF8 /* StdExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B300220E878AE002F1AF8 /* StdExtension.swift */; };
BB1B300520E87CC9002F1AF8 /* KaraokeLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B300420E87CC9002F1AF8 /* KaraokeLabel.swift */; };
BB1B631B1E8CD7CA004CC9E0 /* ScrollLyricsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B631A1E8CD7CA004CC9E0 /* ScrollLyricsView.swift */; };
BB22681C234C9085008FAFED /* SwiftCF in Frameworks */ = {isa = PBXBuildFile; productRef = BB22681B234C9085008FAFED /* SwiftCF */; };
BB22681E234C908D008FAFED /* SwiftCF in Frameworks */ = {isa = PBXBuildFile; productRef = BB22681D234C908D008FAFED /* SwiftCF */; };
BB34F4A91EFFBCBC008B9E4B /* MASShortcut.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BB34F4A81EFFBCBC008B9E4B /* MASShortcut.framework */; };
BB34F4AA1EFFBCBC008B9E4B /* MASShortcut.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BB34F4A81EFFBCBC008B9E4B /* MASShortcut.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
BB34F7E61F21911700B7C484 /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB34F7E51F21911700B7C484 /* Updater.swift */; };
Expand All @@ -60,11 +60,9 @@
BB50786E22014C3900B695C3 /* DragNDropView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBD03C361E9B2C7200EFB975 /* DragNDropView.swift */; };
BB50786F22014C3900B695C3 /* Observation.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9EBDA2421115A150019FDF9 /* Observation.swift */; };
BB50787022014C3900B695C3 /* TouchBarLyricsItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5863F221EFFD9F0084D2C0 /* TouchBarLyricsItem.swift */; };
BB50787122014C3900B695C3 /* CGExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B300020E8788C002F1AF8 /* CGExtension.swift */; };
BB50787222014C3900B695C3 /* CFExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B2FFC20E8780A002F1AF8 /* CFExtension.swift */; };
BB50787322014C3900B695C3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB4141AD1E458BA800A51775 /* AppDelegate.swift */; };
BB50787422014C3900B695C3 /* LyricsMetaData+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB458C62201C5F4500740C3B /* LyricsMetaData+Extension.swift */; };
BB50787522014C3900B695C3 /* CTExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1B2FFE20E87838002F1AF8 /* CTExtension.swift */; };
BB50787622014C3900B695C3 /* PreferenceGeneralViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBC7C5541E6AE28600E3EC4F /* PreferenceGeneralViewController.swift */; };
BB50787722014C3900B695C3 /* Then.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBE8FC741F6BEA6200122AFA /* Then.swift */; };
BB50787822014C3900B695C3 /* Updater.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB34F7E51F21911700B7C484 /* Updater.swift */; };
Expand Down Expand Up @@ -211,8 +209,6 @@
BB0BE95C1F44508F0068FF67 /* Fabric.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Fabric.framework; path = LyricsX/Frameworks/Fabric.framework; sourceTree = "<group>"; };
BB1A3184207B261500406E32 /* Regex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Regex.swift; sourceTree = "<group>"; };
BB1B2FFC20E8780A002F1AF8 /* CFExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CFExtension.swift; sourceTree = "<group>"; };
BB1B2FFE20E87838002F1AF8 /* CTExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CTExtension.swift; sourceTree = "<group>"; };
BB1B300020E8788C002F1AF8 /* CGExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGExtension.swift; sourceTree = "<group>"; };
BB1B300220E878AE002F1AF8 /* StdExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StdExtension.swift; sourceTree = "<group>"; };
BB1B300420E87CC9002F1AF8 /* KaraokeLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KaraokeLabel.swift; sourceTree = "<group>"; };
BB1B631A1E8CD7CA004CC9E0 /* ScrollLyricsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollLyricsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -301,6 +297,7 @@
BBB03F3A2331D8A800A3879E /* OpenCC in Frameworks */,
BBB03F30232FB40400A3879E /* Semver in Frameworks */,
BB34F4A91EFFBCBC008B9E4B /* MASShortcut.framework in Frameworks */,
BB22681C234C9085008FAFED /* SwiftCF in Frameworks */,
BBB03F2D232FB3AF00A3879E /* GenericID in Frameworks */,
BBB03F3D2331DACD00A3879E /* LyricsKit in Frameworks */,
);
Expand All @@ -316,6 +313,7 @@
BB50788D22014C3900B695C3 /* DFRPrivate.framework in Frameworks */,
BBB03F3F2331DBB000A3879E /* GenericID in Frameworks */,
BBB03F452331DBB000A3879E /* LyricsKit in Frameworks */,
BB22681E234C908D008FAFED /* SwiftCF in Frameworks */,
BBB03F412331DBB000A3879E /* Semver in Frameworks */,
BB9C3D8523435A6300860698 /* MusicPlayer in Frameworks */,
BB50788F22014C3900B695C3 /* SnapKit.framework in Frameworks */,
Expand Down Expand Up @@ -439,9 +437,7 @@
E97593E52150F6FB00D80616 /* IBInspection.swift */,
BB9BCEB91E843157001BC54B /* Extension.swift */,
BB1B300220E878AE002F1AF8 /* StdExtension.swift */,
BB1B300020E8788C002F1AF8 /* CGExtension.swift */,
BB1B2FFC20E8780A002F1AF8 /* CFExtension.swift */,
BB1B2FFE20E87838002F1AF8 /* CTExtension.swift */,
E9EBDA2421115A150019FDF9 /* Observation.swift */,
BB1A3184207B261500406E32 /* Regex.swift */,
BBE8FC741F6BEA6200122AFA /* Then.swift */,
Expand Down Expand Up @@ -518,6 +514,7 @@
BBB03F392331D8A800A3879E /* OpenCC */,
BBB03F3C2331DACD00A3879E /* LyricsKit */,
BB9C3D8223435A5700860698 /* MusicPlayer */,
BB22681B234C9085008FAFED /* SwiftCF */,
);
productName = LyricsX;
productReference = BB4141AA1E458BA800A51775 /* LyricsX.app */;
Expand Down Expand Up @@ -548,6 +545,7 @@
BBB03F422331DBB000A3879E /* OpenCC */,
BBB03F442331DBB000A3879E /* LyricsKit */,
BB9C3D8423435A6300860698 /* MusicPlayer */,
BB22681D234C908D008FAFED /* SwiftCF */,
);
productName = LyricsX;
productReference = BB5078AD22014C3900B695C3 /* LyricsX.app */;
Expand Down Expand Up @@ -644,6 +642,7 @@
BBB03F382331D8A800A3879E /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */,
BBB03F3B2331DACD00A3879E /* XCRemoteSwiftPackageReference "LyricsKit" */,
BB9C3D8123435A5700860698 /* XCRemoteSwiftPackageReference "MusicPlayer" */,
BB22681A234C9085008FAFED /* XCRemoteSwiftPackageReference "SwiftCF" */,
);
productRefGroup = BB4141AB1E458BA800A51775 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -871,11 +870,9 @@
BBD03C371E9B2C7200EFB975 /* DragNDropView.swift in Sources */,
E9EBDA2521115A150019FDF9 /* Observation.swift in Sources */,
BB5863F321EFFD9F0084D2C0 /* TouchBarLyricsItem.swift in Sources */,
BB1B300120E8788C002F1AF8 /* CGExtension.swift in Sources */,
BB1B2FFD20E8780A002F1AF8 /* CFExtension.swift in Sources */,
BB4141AE1E458BA800A51775 /* AppDelegate.swift in Sources */,
BB458C63201C5F4500740C3B /* LyricsMetaData+Extension.swift in Sources */,
BB1B2FFF20E87838002F1AF8 /* CTExtension.swift in Sources */,
BBC7C5551E6AE28600E3EC4F /* PreferenceGeneralViewController.swift in Sources */,
BBE8FC751F6BEA6200122AFA /* Then.swift in Sources */,
BB34F7E61F21911700B7C484 /* Updater.swift in Sources */,
Expand Down Expand Up @@ -916,11 +913,9 @@
BB50786E22014C3900B695C3 /* DragNDropView.swift in Sources */,
BB50786F22014C3900B695C3 /* Observation.swift in Sources */,
BB50787022014C3900B695C3 /* TouchBarLyricsItem.swift in Sources */,
BB50787122014C3900B695C3 /* CGExtension.swift in Sources */,
BB50787222014C3900B695C3 /* CFExtension.swift in Sources */,
BB50787322014C3900B695C3 /* AppDelegate.swift in Sources */,
BB50787422014C3900B695C3 /* LyricsMetaData+Extension.swift in Sources */,
BB50787522014C3900B695C3 /* CTExtension.swift in Sources */,
BB50787622014C3900B695C3 /* PreferenceGeneralViewController.swift in Sources */,
BB50787722014C3900B695C3 /* Then.swift in Sources */,
BB50787822014C3900B695C3 /* Updater.swift in Sources */,
Expand Down Expand Up @@ -1356,6 +1351,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
BB22681A234C9085008FAFED /* XCRemoteSwiftPackageReference "SwiftCF" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ddddxxx/SwiftCF.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.1.0;
};
};
BB9C3D8123435A5700860698 /* XCRemoteSwiftPackageReference "MusicPlayer" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ddddxxx/MusicPlayer";
Expand Down Expand Up @@ -1399,6 +1402,16 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
BB22681B234C9085008FAFED /* SwiftCF */ = {
isa = XCSwiftPackageProductDependency;
package = BB22681A234C9085008FAFED /* XCRemoteSwiftPackageReference "SwiftCF" */;
productName = SwiftCF;
};
BB22681D234C908D008FAFED /* SwiftCF */ = {
isa = XCSwiftPackageProductDependency;
package = BB22681A234C9085008FAFED /* XCRemoteSwiftPackageReference "SwiftCF" */;
productName = SwiftCF;
};
BB9C3D8223435A5700860698 /* MusicPlayer */ = {
isa = XCSwiftPackageProductDependency;
package = BB9C3D8123435A5700860698 /* XCRemoteSwiftPackageReference "MusicPlayer" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
"version": "0.1.2"
}
},
{
"package": "SwiftCF",
"repositoryURL": "https://github.com/ddddxxx/SwiftCF.git",
"state": {
"branch": null,
"revision": "97d353849f530d6c3df47f5e429e021514edce2d",
"version": "0.1.0"
}
},
{
"package": "SwiftyOpenCC",
"repositoryURL": "https://github.com/ddddxxx/SwiftyOpenCC.git",
Expand Down
1 change: 1 addition & 0 deletions LyricsX/Controller/KaraokeLyricsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import LyricsCore
import MusicPlayer
import OpenCC
import SnapKit
import SwiftCF

class KaraokeLyricsWindowController: NSWindowController {

Expand Down
4 changes: 2 additions & 2 deletions LyricsX/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.5.1</string>
<key>CFBundleVersion</key>
<string>2202</string>
<string>2209</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
Expand All @@ -43,7 +43,7 @@
<key>LSUIElement</key>
<true/>
<key>LX_BUILD_TIME</key>
<integer>1570527258</integer>
<integer>1570533589</integer>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
Expand Down
71 changes: 2 additions & 69 deletions LyricsX/Utility/CFExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,71 +32,11 @@ extension NSString {

extension CFStringTokenizer {

struct Attribute: RawRepresentable {

var rawValue: CFOptionFlags

init(rawValue: CFOptionFlags) {
self.rawValue = rawValue
}

static let latinTranscription = Attribute(rawValue: kCFStringTokenizerAttributeLatinTranscription)
static let language = Attribute(rawValue: kCFStringTokenizerAttributeLanguage)
}

struct Unit: RawRepresentable {

var rawValue: CFOptionFlags

init(rawValue: CFOptionFlags) {
self.rawValue = rawValue
}

static let word = Unit(rawValue: kCFStringTokenizerUnitWord)
static let sentence = Unit(rawValue: kCFStringTokenizerUnitSentence)
static let paragraph = Unit(rawValue: kCFStringTokenizerUnitParagraph)
static let lineBreak = Unit(rawValue: kCFStringTokenizerUnitLineBreak)
static let wordBoundary = Unit(rawValue: kCFStringTokenizerUnitWordBoundary)
}

static func create(_ string: NSString, range: NSRange? = nil, unit: Unit = .wordBoundary, locale: NSLocale? = nil) -> CFStringTokenizer {
let cfStr = string as CFString
return CFStringTokenizerCreate(nil, cfStr, range?.asCF ?? cfStr.fullRange, unit.rawValue, locale as CFLocale?)
}

func nextToken() -> CFStringTokenizerTokenType? {
let token = CFStringTokenizerAdvanceToNextToken(self)
if token.isEmpty { return nil }
return token
}

func token(at index: CFIndex) -> CFStringTokenizerTokenType? {
let token = CFStringTokenizerGoToTokenAtIndex(self, index)
if token.isEmpty { return nil }
return token
}

func currentTokenRange() -> NSRange {
return CFStringTokenizerGetCurrentTokenRange(self).asNS
}

func currentTokenAttribute(_ attribute: Attribute) -> NSString? {
// swiftlint:disable:next force_cast
return CFStringTokenizerCopyCurrentTokenAttribute(self, attribute.rawValue) as! NSString?
}

func currentSubTokens() -> [CFStringTokenizerTokenType] {
let arr = NSMutableArray()
CFStringTokenizerGetCurrentSubTokens(self, nil, 0, arr as CFMutableArray)
// swiftlint:disable:next force_cast
return arr as! [CFStringTokenizerTokenType]
}

func currentFuriganaAnnotation(in string: NSString) -> (NSString, NSRange)? {
let range = currentTokenRange()
let tokenStr = string.substring(with: range)
let tokenStr = string.substring(with: range.asNS)
guard tokenStr.unicodeScalars.contains(where: CharacterSet.kanji.contains),
let latin = currentTokenAttribute(.latinTranscription),
let latin = currentTokenAttribute(.latinTranscription)?.asNS,
let hiragana = latin.applyingTransform(.latinToHiragana, reverse: false),
let (rangeToAnnotate, rangeInAnnotation) = rangeOfUncommonContent(tokenStr, hiragana) else {
return nil
Expand Down Expand Up @@ -134,10 +74,3 @@ private func rangeOfUncommonContent(_ s1: String, _ s2: String) -> (Range<String
let range2 = (l2...r2).relative(to: s2.indices)
return (range1, range2)
}

extension CFStringTokenizer: IteratorProtocol, Sequence {

public func next() -> CFStringTokenizerTokenType? {
return nextToken()
}
}
Loading

0 comments on commit 4a383ce

Please sign in to comment.