9f308fadd2
Rotate AI idle suggestions with optional remote packs, move history/dictionary onto self-sizing Home preview cards, harden clipboard capture/prompting, and simplify keyboard chrome by dropping most liquid-glass shadows.
29 lines
1.0 KiB
Swift
29 lines
1.0 KiB
Swift
// TranscriptOverlapUtilities.swift
|
|
// OSGKeyboard · Shared
|
|
//
|
|
// Shared normalization and raw-prefix mapping for transcript overlap checks.
|
|
|
|
import Foundation
|
|
|
|
enum TranscriptOverlapUtilities {
|
|
static func normalized(_ text: String) -> String {
|
|
text.unicodeScalars.filter {
|
|
!CharacterSet.whitespacesAndNewlines.contains($0)
|
|
&& !CharacterSet.punctuationCharacters.contains($0)
|
|
}.map { Character($0) }.reduce(into: "") { $0.append($1) }
|
|
}
|
|
|
|
static func rawDropCount(in text: String, normalizedPrefixLength: Int) -> Int {
|
|
var normalizedCount = 0
|
|
var rawIndex = text.startIndex
|
|
while rawIndex < text.endIndex, normalizedCount < normalizedPrefixLength {
|
|
let character = text[rawIndex]
|
|
if !character.isWhitespace, !character.isPunctuation {
|
|
normalizedCount += 1
|
|
}
|
|
rawIndex = text.index(after: rawIndex)
|
|
}
|
|
return text.distance(from: text.startIndex, to: rawIndex)
|
|
}
|
|
}
|