Use UTF16 surrogate easier in Swift
Swift Ruby Objective-C
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
Pod
Source
SwiftySurrogate.xcodeproj
SwiftySurrogate
SwiftySurrogateTests
.gitignore
.travis.yml
LICENSE
README.md
SwiftySurrogate.podspec
_Pods.xcodeproj

README.md

SwiftySurrogate

CI Status Version License Platform

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

Cocoapods

pod "SwiftySurrogate"

Carthage

github "zh-wang/SwiftySurrogate" >= 1.0.1

Author

zh-wang, viennakanon@gmail.com

License

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