Migrated to git.0x0001f346.de/andreas/utils

This commit is contained in:
Andreas Schulte 2023-10-02 23:45:21 +02:00
parent 85767d29a2
commit 87dad2835b
Signed by: andreas
GPG Key ID: DCD1B6A247B69DB6
5 changed files with 12 additions and 43 deletions

View File

@ -2,6 +2,8 @@ package iso639
import (
"fmt"
"git.0x0001f346.de/andreas/utils"
)
var iso639_1CodeToName = map[string]string{
@ -378,12 +380,12 @@ var iso639_1NameToCode = map[string]string{
// GetAllISO639_1Codes returns all ISO 639-1 codes
func GetAllISO639_1Codes() []string {
return getAllKeysOfMap(iso639_1CodeToName)
return utils.GetAllStringKeysOfMap(iso639_1CodeToName)
}
// GetAllISO639_1Names returns all ISO 639-1 language names
func GetAllISO639_1Names() []string {
return getAllKeysOfMap(iso639_1NameToCode)
return utils.GetAllStringKeysOfMap(iso639_1NameToCode)
}
// GetISO639_1CodeForLanguageName tries to match a language name to an ISO 639-1 code

View File

@ -2,6 +2,8 @@ package iso639
import (
"fmt"
"git.0x0001f346.de/andreas/utils"
)
var iso639_2BCodeToName = map[string]string{
@ -378,12 +380,12 @@ var iso639_2BNameToCode = map[string]string{
// GetAllISO639_2BCodes returns all ISO 639-2/B codes
func GetAllISO639_2BCodes() []string {
return getAllKeysOfMap(iso639_2BCodeToName)
return utils.GetAllStringKeysOfMap(iso639_2BCodeToName)
}
// GetAllISO639_2BNames returns all ISO 639-2/B language names
func GetAllISO639_2BNames() []string {
return getAllKeysOfMap(iso639_2BNameToCode)
return utils.GetAllStringKeysOfMap(iso639_2BNameToCode)
}
// GetISO639_2BCodeForLanguageName tries to match a language name to an ISO 639-2/B code

View File

@ -2,6 +2,8 @@ package iso639
import (
"fmt"
"git.0x0001f346.de/andreas/utils"
)
var iso639_2TCodeToName = map[string]string{
@ -378,12 +380,12 @@ var iso639_2TNameToCode = map[string]string{
// GetAllISO639_2TCodes returns all ISO 639-2/T codes
func GetAllISO639_2TCodes() []string {
return getAllKeysOfMap(iso639_2TCodeToName)
return utils.GetAllStringKeysOfMap(iso639_2TCodeToName)
}
// GetAllISO639_2TNames returns all ISO 639-2/T language names
func GetAllISO639_2TNames() []string {
return getAllKeysOfMap(iso639_2TNameToCode)
return utils.GetAllStringKeysOfMap(iso639_2TNameToCode)
}
// GetISO639_2TCodeForLanguageName tries to match a language name to an ISO 639-2/T code

View File

@ -2,7 +2,6 @@ package iso639
import (
"fmt"
"sort"
)
// GetLanguageNameForISO639Code tries get the language name for an ISO 639-1, ISO 639-2/B or ISO 639-2/T code
@ -24,15 +23,3 @@ func GetLanguageNameForISO639Code(s string) (string, error) {
return "", fmt.Errorf("no language name found for ISO 639 code: %s", s)
}
func getAllKeysOfMap(m map[string]string) []string {
keys := make([]string, 0, len(m))
for key := range m {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
}

View File

@ -2,30 +2,6 @@ package iso639
import "testing"
func TestGetAllKeysOfMap(t *testing.T) {
got := getAllKeysOfMap(
map[string]string{
"This": "is",
"just": "a",
"little": "test",
"for": "you",
},
)
want := []string{
"This",
"for",
"just",
"little",
}
for i := 0; i <= 3; i++ {
if got[i] != want[i] {
t.Errorf("got %q, wanted %q", got[i], want[i])
}
}
}
func TestGetLanguageNameForISO639Code(t *testing.T) {
data := map[string]string{
"nl": "Dutch", // ISO 639-1