SwiftySurrogate 1.0.3

SwiftySurrogate 1.0.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2015年9月
SPM支持 SPM

王振宏维护。



SwiftySurrogate

使用方法

在 Swift 中更容易使用 UTF16 代理。

    var emoji1 = SwiftySurrogate.decodeFromSurrogatePair(surrogatePair: "D83D:DCC9")
    var emoji2 = SwiftySurrogate.decodeFromSurrogatePair(high: 0xD83C, low: 0xDF80)

您可以在代理对与 Unicode 标量之间进行转换。

    expect("D83D:DE04") == "\(SwiftySurrogate.convUnicodeScalarToSurrogatePair(0x1F604).0!.hexExpression()):\(SwiftySurrogate.convUnicodeScalarToSurrogatePair(0x1F604).1!.hexExpression())"
    // true

    expect(UInt32(0x1F604)) == SwiftySurrogate.convSurrogateToUnicodeScalar("D83D:DE04")
    // true

通过可选检查捕获解码错误。

    // This will fail
    if let res = SwiftySurrogate.decodeFromSurrogatePair(surrogatePair: "FFFF:DE04") {

    } else {
        // Get the error
        println(SwiftySurrogate.lastError())
        // print -> Optional(Error Domain=SwiftySurrogateErrorDomain Code=504 "High Surrogates (FFFF) must be less than 0xDBFF" 
    }

要求

iOS 8.0

安装

作者

zh-wang, [email protected]

许可证

SwiftySurrogate 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。