import Foundation /// Normalises numeric tokens for the semantic check in `docs/TRANSLATION_OUTPUT.md` ยง9. /// /// Locale separators legitimately change during translation, so `1.5`, `1,5` and `1 5` may all /// represent the same value. Thousands separators are removed and the decimal separator becomes /// `.`. This never edits the translation; it only decides whether a warning is shown. public enum NumericTokenNormalizer { private static let regex = try? NSRegularExpression(pattern: "\\d+(?:[.,\\s]\\d+)*") /// The normalised numeric values in `text`, in source order. public static func numbers(in text: String) -> [String] { guard let regex else { return [] } let nsText = text as NSString let matches = regex.matches(in: text, range: NSRange(location: 0, length: nsText.length)) return matches.map { normalize(nsText.substring(with: $0.range)) } } /// Normalises one numeric token. public static func normalize(_ raw: String) -> String { var value = raw.filter { !$0.isWhitespace } guard !value.isEmpty else { return value } let hasComma = value.contains(",") let hasDot = value.contains(".") if hasComma, hasDot, let comma = value.lastIndex(of: ","), let dot = value.lastIndex(of: ".") { let decimal = comma > dot ? comma : dot let integer = value[..