Avatar
within: が何かはやってるのか
8:32 AM
public init?( _ sourcePosition: String.Index, within target: String ) { guard target.unicodeScalars._isOnGraphemeClusterBoundary(sourcePosition) else { return nil } self = target.characters._index( atEncodedOffset: sourcePosition.encodedOffset) }
8:38 AM
let str = "こんにちは!" let u16Str = str.utf16 let u8Str = str.utf8 str[u16Str.index(u16Str.startIndex, offsetBy: 0)] let i1: String.Index = u16Str.index(u16Str.startIndex, offsetBy: 1) str[i1] // ん u8Str[u8Str.index(i1, offsetBy: 0)] u8Str[u8Str.index(i1, offsetBy: 1)] u8Str[u8Str.index(i1, offsetBy: 2)] let i2: String.Index = u8Str.index(i1, offsetBy: 3) print(str[i2]) // に
8:38 AM
なるほど・・・どうなってんだ・・・