Repo // Deprecating Zonble's NSStringUtils.

AUTHORS // Remove attribution of Zonble's NSStringUtils.
This commit is contained in:
ShikiSuen 2022-09-05 00:41:18 +08:00
parent 5f89fdf9b2
commit 3ca12542c2
4 changed files with 11 additions and 67 deletions

View File

@ -18,7 +18,7 @@ $ Contributors and volunteers of the upstream repo, having no responsibility in
- McBopomofo for macOS 2.x architect.
- Voltaire candidate window MK2 (massively modified as MK3 in vChewing by Shiki Suen).
- Notifier window and Tooltip UI.
- NSStringUtils and FSEventStreamHelper.
- FSEventStreamHelper.
- App-style installer (only preserved for developer purposes).
- InputSource Helper.
- mgrPrefs (userdefaults manager).

View File

@ -1,62 +0,0 @@
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
// All possible vChewing-specific modifications are of:
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
// ... with NTL restriction stating that:
// No trademark license is granted to use the trade names, trademarks, service
// marks, or product names of Contributor, except as required to fulfill notice
// requirements defined in MIT License.
import Foundation
/// Shiki's Notes: The cursor index in the IMK inline composition buffer
/// still uses UTF16 index measurements. This means that any attempt of
/// using Swift native UTF8 handlings to replace Zonble's NSString (or
/// .utf16) handlings below will still result in unavoidable necessities
/// of solving the UTF16->UTF8 conversions in another approach. Therefore,
/// I strongly advise against any attempt of such until the day that IMK is
/// capable of handling the cursor index in its inline composition buffer using
/// UTF8 measurements.
extension String {
/// Converts the index in an NSString or .utf16 to the index in a Swift string.
///
/// An Emoji might be compose by more than one UTF-16 code points. However,
/// the length of an NSString is only the sum of the UTF-16 code points. It
/// causes that the NSString and Swift string representation of the same
/// string have different lengths once the string contains such Emoji. The
/// method helps to find the index in a Swift string by passing the index
/// in an NSString (or .utf16).
public func charIndexLiteral(from utf16Index: Int) -> Int {
var length = 0
for (i, character) in enumerated() {
length += character.utf16.count
if length > utf16Index {
return (i)
}
}
return count
}
public func utf16NextPosition(for index: Int) -> Int {
let fixedIndex = min(charIndexLiteral(from: index) + 1, count)
return self[..<self.index(startIndex, offsetBy: fixedIndex)].utf16.count
}
public func utf16PreviousPosition(for index: Int) -> Int {
let fixedIndex = max(charIndexLiteral(from: index) - 1, 0)
return self[..<self.index(startIndex, offsetBy: fixedIndex)].utf16.count
}
internal func utf16SubString(with r: Range<Int>) -> String {
let arr = Array(utf16)[r].map { $0 }
return String(utf16CodeUnits: arr, count: arr.count)
}
public var charComponents: [String] { map { String($0) } }
}
extension Array where Element == String.Element {
public var charComponents: [String] { map { String($0) } }
}

View File

@ -382,6 +382,16 @@ extension RangeReplaceableCollection where Element: Hashable {
}
}
// MARK: - String charComponents Extension
extension String {
public var charComponents: [String] { map { String($0) } }
}
extension Array where Element == String.Element {
public var charComponents: [String] { map { String($0) } }
}
// MARK: - String Tildes Expansion Extension
extension String {

View File

@ -34,7 +34,6 @@
5B62A32927AE77D100A19448 /* FSEventStreamHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A32827AE77D100A19448 /* FSEventStreamHelper.swift */; };
5B62A33227AE792F00A19448 /* InputSourceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33127AE792F00A19448 /* InputSourceHelper.swift */; };
5B62A33627AE795800A19448 /* mgrPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33527AE795800A19448 /* mgrPrefs.swift */; };
5B62A33827AE79CD00A19448 /* StringUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33727AE79CD00A19448 /* StringUtils.swift */; };
5B62A33D27AE7CC100A19448 /* ctlAboutWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A33C27AE7CC100A19448 /* ctlAboutWindow.swift */; };
5B62A34727AE7CD900A19448 /* ctlCandidate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34027AE7CD900A19448 /* ctlCandidate.swift */; };
5B62A34927AE7CD900A19448 /* TooltipController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B62A34327AE7CD900A19448 /* TooltipController.swift */; };
@ -251,7 +250,6 @@
5B62A32827AE77D100A19448 /* FSEventStreamHelper.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = FSEventStreamHelper.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B62A33127AE792F00A19448 /* InputSourceHelper.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = InputSourceHelper.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B62A33527AE795800A19448 /* mgrPrefs.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = mgrPrefs.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B62A33727AE79CD00A19448 /* StringUtils.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = StringUtils.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B62A33C27AE7CC100A19448 /* ctlAboutWindow.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = ctlAboutWindow.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B62A34027AE7CD900A19448 /* ctlCandidate.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = ctlCandidate.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
5B62A34327AE7CD900A19448 /* TooltipController.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = TooltipController.swift; sourceTree = "<group>"; tabWidth = 2; usesTabs = 0; };
@ -508,7 +506,6 @@
5B7F225C2808501000DDD3CB /* KeyHandler_HandleInput.swift */,
5B3133BE280B229700A4A505 /* KeyHandler_States.swift */,
5BF0B84B28C070B000795FC6 /* NSEventExtension.swift */,
5B62A33727AE79CD00A19448 /* StringUtils.swift */,
5BAA8FBD282CAF380066C406 /* SyllableComposer.swift */,
);
path = ControllerModules;
@ -1250,7 +1247,6 @@
5B62A33627AE795800A19448 /* mgrPrefs.swift in Sources */,
5BAEFAD028012565001F42C9 /* mgrLangModel.swift in Sources */,
5B782EC4280C243C007276DE /* KeyHandler_HandleCandidate.swift in Sources */,
5B62A33827AE79CD00A19448 /* StringUtils.swift in Sources */,
5B2170E3289FACAD00BE7304 /* 3_KeyValuePaired.swift in Sources */,
5BA9FD0F27FEDB6B002DE248 /* suiPrefPaneGeneral.swift in Sources */,
5B2170E6289FACAD00BE7304 /* 4_Span.swift in Sources */,