Documentation ¶
Overview ¶
Package variationselector provides utility functions for adding and removing emoji variation selectors (16) that matches the suggestions in the Matrix spec.
Index ¶
Examples ¶
Constants ¶
const VS16 = "\ufe0f"
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add adds emoji variation selectors to all emojis that have multiple forms in the given string.
Variation selectors will be added to everything that is allowed to have both a text presentation and an emoji presentation according to Unicode Technical Standard #51. If you only want to add variation selectors necessary for fully-qualified forms, use FullyQualify instead.
This method uses data from emoji-variation-sequences.txt in the official Unicode emoji data set.
This will remove all variation selectors first to make sure it doesn't add duplicates.
Example ¶
package main import ( "fmt" "strconv" "github.com/EvolutionAPI/go-util/variationselector" ) func main() { fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f44d"))) // thumbs up (needs selector) fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f44d\ufe0f"))) // thumbs up with variation selector (stays as-is) fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f44d\U0001f3fd"))) // thumbs up with skin tone (shouldn't get selector) fmt.Println(strconv.QuoteToASCII(variationselector.Add("\U0001f914"))) // thinking face (shouldn't get selector) }
Output: "\U0001f44d\ufe0f" "\U0001f44d\ufe0f" "\U0001f44d\U0001f3fd" "\U0001f914"
func FullyQualify ¶
FullyQualify converts all emojis to their fully-qualified form by adding variation selectors where necessary.
This will not add variation selectors to all possible emojis, only the ones that require a variation selector to be "fully qualified" according to Unicode Technical Standard #51. If you want to add variation selectors in all allowed cases, use Add instead.
This method uses data from emoji-test.txt in the official Unicode emoji data set.
N.B. This method is not currently used by the Matrix spec, but it is included as bridging to other networks may need it.
Example ¶
package main import ( "fmt" "strconv" "github.com/EvolutionAPI/go-util/variationselector" ) func main() { fmt.Println(strconv.QuoteToASCII(variationselector.FullyQualify("\U0001f44d"))) // thumbs up (already fully qualified) fmt.Println(strconv.QuoteToASCII(variationselector.FullyQualify("\U0001f44d\ufe0f"))) // thumbs up with variation selector (variation selector removed) fmt.Println(strconv.QuoteToASCII(variationselector.FullyQualify("\U0001f44d\U0001f3fd"))) // thumbs up with skin tone (already fully qualified) fmt.Println(strconv.QuoteToASCII(variationselector.FullyQualify("\u263a"))) // smiling face (unqualified, should get selector) fmt.Println(strconv.QuoteToASCII(variationselector.FullyQualify("\U0001f3f3\u200d\U0001f308"))) // rainbow flag (unqualified, should get selector) fmt.Println(strconv.QuoteToASCII(variationselector.FullyQualify("\U0001f3f3\ufe0f\u200d\U0001f308"))) // rainbow flag with variation selector (already fully qualified) }
Output: "\U0001f44d" "\U0001f44d" "\U0001f44d\U0001f3fd" "\u263a\ufe0f" "\U0001f3f3\ufe0f\u200d\U0001f308" "\U0001f3f3\ufe0f\u200d\U0001f308"
func Remove ¶
Remove removes all emoji variation selectors in the given string.
Example ¶
package main import ( "fmt" "strconv" "github.com/EvolutionAPI/go-util/variationselector" ) func main() { fmt.Println(strconv.QuoteToASCII(variationselector.Remove("\U0001f44d"))) fmt.Println(strconv.QuoteToASCII(variationselector.Remove("\U0001f44d\ufe0f"))) }
Output: "\U0001f44d" "\U0001f44d"
Types ¶
This section is empty.