mirror of
https://github.com/emojisum/emojisum.git
synced 2025-01-09 05:07:08 +00:00
emoji: adding a helper to parse a hex string into codepoint
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
4ef81bbc82
commit
f0d758ab5f
1 changed files with 22 additions and 0 deletions
22
emoji/map.go
22
emoji/map.go
|
@ -1,6 +1,7 @@
|
||||||
package emoji
|
package emoji
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -72,3 +73,24 @@ func CodepointToUnicode(word string) string {
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FromHexString parses string s as two character byte of hexadecimal into
|
||||||
|
// Unicode Codepoint
|
||||||
|
func FromHexString(s string) (string, error) {
|
||||||
|
d, err := hex.DecodeString(s)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret string
|
||||||
|
for _, b := range d {
|
||||||
|
for _, e := range Map(b) {
|
||||||
|
// use the first colon notation word and continue
|
||||||
|
if IsCodepoint(e) {
|
||||||
|
ret = ret + CodepointToUnicode(e)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue