CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

SwiftySurrogate 1.0.3

SwiftySurrogate 1.0.3

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2015
SPMSupports SPM

Maintained by Zhenghong Wang.



SwiftySurrogate

Usage

Use UTF16 surrogate easier in Swift.

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

You can convert between surrogate pair to unicode scalar.

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

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

Catch decoding error by optional check.

    // 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" 
    }

Requirements

iOS 8.0

Installation

Author

zh-wang, [email protected]

License

SwiftySurrogate is available under the MIT license. See the LICENSE file for more info.