Last active
April 12, 2017 23:15
-
-
Save motooka/de0d0e800b9e2f59f2717bf46580c681 to your computer and use it in GitHub Desktop.
2017.04.11 MySQL勉強会 in 大阪 第10回 https://atnd.org/events/86982 で文字情報を示すために使ったコード
This file contains 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
//: Playground - noun: a place where people can play | |
import UIKit | |
// see http://stackoverflow.com/a/40089462/518639 | |
extension Data { | |
func hexEncodedString() -> String { | |
return map { String(format: "%02hhx", $0) }.joined() | |
} | |
} | |
// UTF16 BE hex を得る | |
extension String { | |
func hex() -> String { | |
return (self.data(using: String.Encoding.utf16BigEndian, allowLossyConversion: false))!.hexEncodedString() | |
} | |
} | |
"0".hex() // ASCII 0x30 / U+0030 | |
" ".hex() // U+3000 全角スペース | |
"👩".hex() | |
"👩🏻".hex() | |
"👩🏼".hex() | |
"👩🏽".hex() | |
"👩🏾".hex() | |
"👩🏿".hex() | |
// modifiers http://www.fileformat.info/info/charset/UTF-16/list.htm?start=55670 | |
"👩".hex() // U+1F469 | |
"👩🏻".hex() // U+1F469 + U+1F3Fb | |
"𤭢".hex() // 何か中国語の漢字 U+24B62 https://en.wiktionary.org/wiki/%F0%A4%AD%A2 | |
// これらはどのようにソートされるのが好都合なのでしょうか? | |
"👩".hex() | |
"👩a".hex() | |
"👩🏻".hex() // U+1F469 + U+1F3Fb | |
"👩𤭢".hex() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment