Skip to content

Instantly share code, notes, and snippets.

@motooka
Last active April 12, 2017 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motooka/de0d0e800b9e2f59f2717bf46580c681 to your computer and use it in GitHub Desktop.
Save motooka/de0d0e800b9e2f59f2717bf46580c681 to your computer and use it in GitHub Desktop.
2017.04.11 MySQL勉強会 in 大阪 第10回 https://atnd.org/events/86982 で文字情報を示すために使ったコード
//: 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