TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2015 |
SPMSupports SPM | ✗ |
Maintained by Zhenghong Wang.
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"
}
iOS 8.0
zh-wang, [email protected]
SwiftySurrogate is available under the MIT license. See the LICENSE file for more info.