Merge pull request #30 from emojisum/helper

emoji: adding a helper to parse a hex string into codepoint
This commit is contained in:
Vincent Batts 2018-10-22 18:57:08 +01:00 committed by GitHub
commit 2e152064f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package emoji
import (
"encoding/hex"
"fmt"
"strconv"
"strings"
@ -72,3 +73,24 @@ func CodepointToUnicode(word string) string {
}
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
}