diff --git a/iso_639-1.go b/iso_639-1.go index 2dadb66..45cb767 100644 --- a/iso_639-1.go +++ b/iso_639-1.go @@ -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 diff --git a/iso_639-2b.go b/iso_639-2b.go index 74adb1f..6add215 100644 --- a/iso_639-2b.go +++ b/iso_639-2b.go @@ -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 diff --git a/iso_639-2t.go b/iso_639-2t.go index 718939f..f9bdce0 100644 --- a/iso_639-2t.go +++ b/iso_639-2t.go @@ -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 diff --git a/iso_639.go b/iso_639.go index 88c5e8d..ee70218 100644 --- a/iso_639.go +++ b/iso_639.go @@ -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 -} diff --git a/iso_639_test.go b/iso_639_test.go index f891503..4d06ae5 100644 --- a/iso_639_test.go +++ b/iso_639_test.go @@ -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