Last active
February 6, 2017 08:10
-
-
Save ukitaka/c8a745c569cccab871ed417eef3a6b2b to your computer and use it in GitHub Desktop.
utf8mb4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UTF8 { | |
| static func byteCount(_ input: UnicodeScalar) -> Int { | |
| var count = 0 | |
| encode(input, into: { _ in count = count + 1 }) | |
| return count | |
| } | |
| static func is4Bytes(_ input: UnicodeScalar) -> Bool { | |
| return byteCount(input) == 4 | |
| } | |
| } | |
| extension String { | |
| var contains4BytesCharacterByUTF8Encoding: Bool { | |
| return unicodeScalars.contains(where: UTF8.is4Bytes) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment