Skip to content
Permalink
Browse files

emoji: adding a helper to parse a hex string into codepoint

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
  • Loading branch information...
vbatts committed Oct 22, 2018
1 parent 4ef81bb commit f0d758ab5f82c408589c28fc965d3233cb1bc624
Showing with 22 additions and 0 deletions.
  1. +22 −0 emoji/map.go
@@ -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
}

0 comments on commit f0d758a

Please sign in to comment.
You can’t perform that action at this time.