Repo // Name Fix: utf16CharIndex -> charIndexLiteral.
This commit is contained in:
parent
aff3a2014e
commit
75978da72f
|
@ -194,8 +194,8 @@ class InputState {
|
|||
)
|
||||
}
|
||||
|
||||
let exactBegin = composingBuffer.utf16CharIndex(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.utf16CharIndex(from: markedRange.upperBound)
|
||||
let exactBegin = composingBuffer.charIndexLiteral(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.charIndexLiteral(from: markedRange.upperBound)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
let exist = mgrLangModel.checkIfUserPhraseExist(
|
||||
|
@ -295,8 +295,8 @@ class InputState {
|
|||
|
||||
var chkIfUserPhraseExists: Bool {
|
||||
let text = composingBuffer.utf16SubString(with: markedRange)
|
||||
let exactBegin = composingBuffer.utf16CharIndex(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.utf16CharIndex(from: markedRange.upperBound)
|
||||
let exactBegin = composingBuffer.charIndexLiteral(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.charIndexLiteral(from: markedRange.upperBound)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
return mgrLangModel.checkIfUserPhraseExist(
|
||||
|
@ -306,8 +306,8 @@ class InputState {
|
|||
|
||||
var userPhrase: String {
|
||||
let text = composingBuffer.utf16SubString(with: markedRange)
|
||||
let exactBegin = composingBuffer.utf16CharIndex(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.utf16CharIndex(from: markedRange.upperBound)
|
||||
let exactBegin = composingBuffer.charIndexLiteral(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.charIndexLiteral(from: markedRange.upperBound)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
return "\(text) \(joined)"
|
||||
|
@ -316,8 +316,8 @@ class InputState {
|
|||
var userPhraseConverted: String {
|
||||
let text =
|
||||
OpenCCBridge.crossConvert(composingBuffer.utf16SubString(with: markedRange)) ?? ""
|
||||
let exactBegin = composingBuffer.utf16CharIndex(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.utf16CharIndex(from: markedRange.upperBound)
|
||||
let exactBegin = composingBuffer.charIndexLiteral(from: markedRange.lowerBound)
|
||||
let exactEnd = composingBuffer.charIndexLiteral(from: markedRange.upperBound)
|
||||
let selectedReadings = readings[exactBegin..<exactEnd]
|
||||
let joined = selectedReadings.joined(separator: "-")
|
||||
let convertedMark = "#𝙊𝙥𝙚𝙣𝘾𝘾"
|
||||
|
|
|
@ -44,7 +44,7 @@ extension String {
|
|||
/// 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 utf16CharIndex(from utf16Index: Int) -> Int {
|
||||
public func charIndexLiteral(from utf16Index: Int) -> Int {
|
||||
var length = 0
|
||||
for (i, character) in self.enumerated() {
|
||||
length += character.utf16.count
|
||||
|
@ -56,12 +56,12 @@ extension String {
|
|||
}
|
||||
|
||||
public func utf16NextPosition(for index: Int) -> Int {
|
||||
let fixedIndex = min(utf16CharIndex(from: index) + 1, count)
|
||||
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(utf16CharIndex(from: index) - 1, 0)
|
||||
let fixedIndex = max(charIndexLiteral(from: index) - 1, 0)
|
||||
return self[..<self.index(startIndex, offsetBy: fixedIndex)].utf16.count
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue