mirror of
https://github.com/emojisum/emojisum.git
synced 2025-08-03 13:50:27 +00:00
emoji: fix merged unicode
for several of the emoji "words", they are a union of unicode points. Like flags are the two letters together. Female Detective is a number of connected symbols. This representation needs to be alltogether. With this update the unicode points are joined, and require spliting on the "U+". To help with this and be useful as a library there is a function `emoji.CodepointToUnicode(string) string` to do this now. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
1d0526c5b6
commit
cc9cb5d099
6 changed files with 271 additions and 227 deletions
26
emoji/map.go
26
emoji/map.go
|
@ -2,6 +2,7 @@ package emoji
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -44,11 +45,30 @@ func IsCodepoint(word string) bool {
|
|||
|
||||
var unicodeURL = `http://www.unicode.org/emoji/charts/full-emoji-list.html`
|
||||
|
||||
// UnicodeLink returns a link to unicode.org list for CodePoint, or just the
|
||||
// UnicodeLinkURL returns a link to unicode.org list for CodePoint, or just the
|
||||
// full list if not a codepoint
|
||||
func UnicodeLink(word string) string {
|
||||
func UnicodeLinkURL(word string) string {
|
||||
if !IsCodepoint(word) {
|
||||
return unicodeURL
|
||||
}
|
||||
return fmt.Sprintf("%s#%s", unicodeURL, strings.SplitN(strings.ToLower(word), "+", 2)[1])
|
||||
|
||||
return fmt.Sprintf("%s#%s", unicodeURL, strings.Join(strings.Split(strings.TrimPrefix(strings.ToUpper(word), "U+"), "U+"), "_"))
|
||||
}
|
||||
|
||||
// CodepointToUnicode takes a "U+26CF" style word and returns the `\U00026CF` formated unicode string
|
||||
func CodepointToUnicode(word string) string {
|
||||
if !IsCodepoint(word) {
|
||||
return word
|
||||
}
|
||||
|
||||
var ret string
|
||||
|
||||
for _, chunk := range strings.Split(strings.TrimPrefix(strings.ToUpper(word), "U+"), "U+") {
|
||||
c, err := strconv.ParseInt(chunk, 16, 64)
|
||||
if err != nil {
|
||||
return ret
|
||||
}
|
||||
ret = fmt.Sprintf("%s%c", ret, c)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue