gemojicountries

package module
v0.0.0-...-f194853 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 9 Imported by: 0

README

GemojiCountries

Go package to extract country names and codes from emoji in text

Install
  • Make sure you have your $GOPATH set and install
$ export GOPATH=~/go # Or your gopath location
$ go get -u github.com/octohedron/gemojicountries
Overview

For example, let's say you have the string "Bonjour la france 🇫🇷 🇫🇷 c'est bon, aussi la chine 🇨🇳"

  • GetAmountCountryNamesMatched will return map[china:1 france:2]
  • GetAmountCountryCodesMatched will return map[cn:1 fr:2]

Note that it only matches emoji, not the country names

If you want to get the country codes and you have the country names, i.e. "russia", you can also use the util func

  • GetCountryCodeByCountry will return "ru"

For getting a string with flag emoji with the flags replaced with their string format i.e. "Bonjour la 🇫🇷 "

  • GetStringReplacedEmoji will return "Bonjour la france"

Example with test

package main

import (
	"testing"

	"github.com/octohedron/gemojicountries"
)

// example with test
func TestCountriesString(t *testing.T) {
	const s = "Bonjour la france 🇫🇷  🇫🇷 c'est bon aussi 🇨🇳 la chine"
	t.Logf("%v", gemojicountries.GetAmountCountryCodesMatched(s))
}

Will print

=== RUN   TestCountriesString
--- PASS: TestCountriesString (0.00s)
	../utils_test.go:132: map[china:1 france:2]
PASS
ok 	0.090s
Success: Tests passed.

Contributing? Adding countries and features? Improving performance? Yes. Send PRs 👍

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmojiCountryData []EmojiCountry

EmojiCountryData is a slice of EmojiCountry

Functions

func GetAmountCountryCodesMatched

func GetAmountCountryCodesMatched(s string) map[string]int

GetAmountCountryCodesMatched returns the countries matched represented by their country codes and the amount of each

func GetAmountCountryNamesMatched

func GetAmountCountryNamesMatched(s string) map[string]int

GetAmountCountryNamesMatched returns the names of the countries matched and the amount of each

func GetCountryByCountryCode

func GetCountryByCountryCode(countryCode string) string

GetCountryByCountryCode returns the country code by passing a string i.e. "fr" would return "france"

func GetCountryCodeByCountry

func GetCountryCodeByCountry(country string) string

GetCountryCodeByCountry returns the country code by passing a string i.e. "france" would return "fr"

func GetEncodedUTF8StringLower

func GetEncodedUTF8StringLower(s string) string

GetEncodedUTF8StringLower returns a string encoded in UTF8, i.e. the code points in lower case for using with the emoji_countries.csv file, which is in upper case, as the ones generated from several emoji libraries and used in other programming languages, in Go it's lower case.

func GetStringReplacedEmoji

func GetStringReplacedEmoji(s string) string

GetStringReplacedEmoji returns the original string replacing each emoji flag with their corresponding name, i.e. "Bonjour la 🇫🇷" would return "Bonjour la france"

Types

type EmojiCountry

type EmojiCountry struct {
	Country     string
	EmojiRegex  *regexp.Regexp
	EmojiCode   string
	CountryCode string
}

EmojiCountry is a type for working with emoji country flags country names and country codes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL