1package govalidator
2
3import (
4	"reflect"
5	"regexp"
6	"sort"
7	"sync"
8)
9
10// Validator is a wrapper for a validator function that returns bool and accepts string.
11type Validator func(str string) bool
12
13// CustomTypeValidator is a wrapper for validator functions that returns bool and accepts any type.
14// The second parameter should be the context (in the case of validating a struct: the whole object being validated).
15type CustomTypeValidator func(i interface{}, o interface{}) bool
16
17// ParamValidator is a wrapper for validator functions that accepts additional parameters.
18type ParamValidator func(str string, params ...string) bool
19type tagOptionsMap map[string]tagOption
20
21func (t tagOptionsMap) orderedKeys() []string {
22	var keys []string
23	for k := range t {
24		keys = append(keys, k)
25	}
26
27	sort.Slice(keys, func(a, b int) bool {
28		return t[keys[a]].order < t[keys[b]].order
29	})
30
31	return keys
32}
33
34type tagOption struct {
35	name               string
36	customErrorMessage string
37	order              int
38}
39
40// UnsupportedTypeError is a wrapper for reflect.Type
41type UnsupportedTypeError struct {
42	Type reflect.Type
43}
44
45// stringValues is a slice of reflect.Value holding *reflect.StringValue.
46// It implements the methods to sort by string.
47type stringValues []reflect.Value
48
49// ParamTagMap is a map of functions accept variants parameters
50var ParamTagMap = map[string]ParamValidator{
51	"length":       ByteLength,
52	"range":        Range,
53	"runelength":   RuneLength,
54	"stringlength": StringLength,
55	"matches":      StringMatches,
56	"in":           isInRaw,
57	"rsapub":       IsRsaPub,
58}
59
60// ParamTagRegexMap maps param tags to their respective regexes.
61var ParamTagRegexMap = map[string]*regexp.Regexp{
62	"range":        regexp.MustCompile("^range\\((\\d+)\\|(\\d+)\\)$"),
63	"length":       regexp.MustCompile("^length\\((\\d+)\\|(\\d+)\\)$"),
64	"runelength":   regexp.MustCompile("^runelength\\((\\d+)\\|(\\d+)\\)$"),
65	"stringlength": regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"),
66	"in":           regexp.MustCompile(`^in\((.*)\)`),
67	"matches":      regexp.MustCompile(`^matches\((.+)\)$`),
68	"rsapub":       regexp.MustCompile("^rsapub\\((\\d+)\\)$"),
69}
70
71type customTypeTagMap struct {
72	validators map[string]CustomTypeValidator
73
74	sync.RWMutex
75}
76
77func (tm *customTypeTagMap) Get(name string) (CustomTypeValidator, bool) {
78	tm.RLock()
79	defer tm.RUnlock()
80	v, ok := tm.validators[name]
81	return v, ok
82}
83
84func (tm *customTypeTagMap) Set(name string, ctv CustomTypeValidator) {
85	tm.Lock()
86	defer tm.Unlock()
87	tm.validators[name] = ctv
88}
89
90// CustomTypeTagMap is a map of functions that can be used as tags for ValidateStruct function.
91// Use this to validate compound or custom types that need to be handled as a whole, e.g.
92// `type UUID [16]byte` (this would be handled as an array of bytes).
93var CustomTypeTagMap = &customTypeTagMap{validators: make(map[string]CustomTypeValidator)}
94
95// TagMap is a map of functions, that can be used as tags for ValidateStruct function.
96var TagMap = map[string]Validator{
97	"email":              IsEmail,
98	"url":                IsURL,
99	"dialstring":         IsDialString,
100	"requrl":             IsRequestURL,
101	"requri":             IsRequestURI,
102	"alpha":              IsAlpha,
103	"utfletter":          IsUTFLetter,
104	"alphanum":           IsAlphanumeric,
105	"utfletternum":       IsUTFLetterNumeric,
106	"numeric":            IsNumeric,
107	"utfnumeric":         IsUTFNumeric,
108	"utfdigit":           IsUTFDigit,
109	"hexadecimal":        IsHexadecimal,
110	"hexcolor":           IsHexcolor,
111	"rgbcolor":           IsRGBcolor,
112	"lowercase":          IsLowerCase,
113	"uppercase":          IsUpperCase,
114	"int":                IsInt,
115	"float":              IsFloat,
116	"null":               IsNull,
117	"uuid":               IsUUID,
118	"uuidv3":             IsUUIDv3,
119	"uuidv4":             IsUUIDv4,
120	"uuidv5":             IsUUIDv5,
121	"creditcard":         IsCreditCard,
122	"isbn10":             IsISBN10,
123	"isbn13":             IsISBN13,
124	"json":               IsJSON,
125	"multibyte":          IsMultibyte,
126	"ascii":              IsASCII,
127	"printableascii":     IsPrintableASCII,
128	"fullwidth":          IsFullWidth,
129	"halfwidth":          IsHalfWidth,
130	"variablewidth":      IsVariableWidth,
131	"base64":             IsBase64,
132	"datauri":            IsDataURI,
133	"ip":                 IsIP,
134	"port":               IsPort,
135	"ipv4":               IsIPv4,
136	"ipv6":               IsIPv6,
137	"dns":                IsDNSName,
138	"host":               IsHost,
139	"mac":                IsMAC,
140	"latitude":           IsLatitude,
141	"longitude":          IsLongitude,
142	"ssn":                IsSSN,
143	"semver":             IsSemver,
144	"rfc3339":            IsRFC3339,
145	"rfc3339WithoutZone": IsRFC3339WithoutZone,
146	"ISO3166Alpha2":      IsISO3166Alpha2,
147	"ISO3166Alpha3":      IsISO3166Alpha3,
148	"ISO4217":            IsISO4217,
149}
150
151// ISO3166Entry stores country codes
152type ISO3166Entry struct {
153	EnglishShortName string
154	FrenchShortName  string
155	Alpha2Code       string
156	Alpha3Code       string
157	Numeric          string
158}
159
160//ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"
161var ISO3166List = []ISO3166Entry{
162	{"Afghanistan", "Afghanistan (l')", "AF", "AFG", "004"},
163	{"Albania", "Albanie (l')", "AL", "ALB", "008"},
164	{"Antarctica", "Antarctique (l')", "AQ", "ATA", "010"},
165	{"Algeria", "Algérie (l')", "DZ", "DZA", "012"},
166	{"American Samoa", "Samoa américaines (les)", "AS", "ASM", "016"},
167	{"Andorra", "Andorre (l')", "AD", "AND", "020"},
168	{"Angola", "Angola (l')", "AO", "AGO", "024"},
169	{"Antigua and Barbuda", "Antigua-et-Barbuda", "AG", "ATG", "028"},
170	{"Azerbaijan", "Azerbaïdjan (l')", "AZ", "AZE", "031"},
171	{"Argentina", "Argentine (l')", "AR", "ARG", "032"},
172	{"Australia", "Australie (l')", "AU", "AUS", "036"},
173	{"Austria", "Autriche (l')", "AT", "AUT", "040"},
174	{"Bahamas (the)", "Bahamas (les)", "BS", "BHS", "044"},
175	{"Bahrain", "Bahreïn", "BH", "BHR", "048"},
176	{"Bangladesh", "Bangladesh (le)", "BD", "BGD", "050"},
177	{"Armenia", "Arménie (l')", "AM", "ARM", "051"},
178	{"Barbados", "Barbade (la)", "BB", "BRB", "052"},
179	{"Belgium", "Belgique (la)", "BE", "BEL", "056"},
180	{"Bermuda", "Bermudes (les)", "BM", "BMU", "060"},
181	{"Bhutan", "Bhoutan (le)", "BT", "BTN", "064"},
182	{"Bolivia (Plurinational State of)", "Bolivie (État plurinational de)", "BO", "BOL", "068"},
183	{"Bosnia and Herzegovina", "Bosnie-Herzégovine (la)", "BA", "BIH", "070"},
184	{"Botswana", "Botswana (le)", "BW", "BWA", "072"},
185	{"Bouvet Island", "Bouvet (l'Île)", "BV", "BVT", "074"},
186	{"Brazil", "Brésil (le)", "BR", "BRA", "076"},
187	{"Belize", "Belize (le)", "BZ", "BLZ", "084"},
188	{"British Indian Ocean Territory (the)", "Indien (le Territoire britannique de l'océan)", "IO", "IOT", "086"},
189	{"Solomon Islands", "Salomon (Îles)", "SB", "SLB", "090"},
190	{"Virgin Islands (British)", "Vierges britanniques (les Îles)", "VG", "VGB", "092"},
191	{"Brunei Darussalam", "Brunéi Darussalam (le)", "BN", "BRN", "096"},
192	{"Bulgaria", "Bulgarie (la)", "BG", "BGR", "100"},
193	{"Myanmar", "Myanmar (le)", "MM", "MMR", "104"},
194	{"Burundi", "Burundi (le)", "BI", "BDI", "108"},
195	{"Belarus", "Bélarus (le)", "BY", "BLR", "112"},
196	{"Cambodia", "Cambodge (le)", "KH", "KHM", "116"},
197	{"Cameroon", "Cameroun (le)", "CM", "CMR", "120"},
198	{"Canada", "Canada (le)", "CA", "CAN", "124"},
199	{"Cabo Verde", "Cabo Verde", "CV", "CPV", "132"},
200	{"Cayman Islands (the)", "Caïmans (les Îles)", "KY", "CYM", "136"},
201	{"Central African Republic (the)", "République centrafricaine (la)", "CF", "CAF", "140"},
202	{"Sri Lanka", "Sri Lanka", "LK", "LKA", "144"},
203	{"Chad", "Tchad (le)", "TD", "TCD", "148"},
204	{"Chile", "Chili (le)", "CL", "CHL", "152"},
205	{"China", "Chine (la)", "CN", "CHN", "156"},
206	{"Taiwan (Province of China)", "Taïwan (Province de Chine)", "TW", "TWN", "158"},
207	{"Christmas Island", "Christmas (l'Île)", "CX", "CXR", "162"},
208	{"Cocos (Keeling) Islands (the)", "Cocos (les Îles)/ Keeling (les Îles)", "CC", "CCK", "166"},
209	{"Colombia", "Colombie (la)", "CO", "COL", "170"},
210	{"Comoros (the)", "Comores (les)", "KM", "COM", "174"},
211	{"Mayotte", "Mayotte", "YT", "MYT", "175"},
212	{"Congo (the)", "Congo (le)", "CG", "COG", "178"},
213	{"Congo (the Democratic Republic of the)", "Congo (la République démocratique du)", "CD", "COD", "180"},
214	{"Cook Islands (the)", "Cook (les Îles)", "CK", "COK", "184"},
215	{"Costa Rica", "Costa Rica (le)", "CR", "CRI", "188"},
216	{"Croatia", "Croatie (la)", "HR", "HRV", "191"},
217	{"Cuba", "Cuba", "CU", "CUB", "192"},
218	{"Cyprus", "Chypre", "CY", "CYP", "196"},
219	{"Czech Republic (the)", "tchèque (la République)", "CZ", "CZE", "203"},
220	{"Benin", "Bénin (le)", "BJ", "BEN", "204"},
221	{"Denmark", "Danemark (le)", "DK", "DNK", "208"},
222	{"Dominica", "Dominique (la)", "DM", "DMA", "212"},
223	{"Dominican Republic (the)", "dominicaine (la République)", "DO", "DOM", "214"},
224	{"Ecuador", "Équateur (l')", "EC", "ECU", "218"},
225	{"El Salvador", "El Salvador", "SV", "SLV", "222"},
226	{"Equatorial Guinea", "Guinée équatoriale (la)", "GQ", "GNQ", "226"},
227	{"Ethiopia", "Éthiopie (l')", "ET", "ETH", "231"},
228	{"Eritrea", "Érythrée (l')", "ER", "ERI", "232"},
229	{"Estonia", "Estonie (l')", "EE", "EST", "233"},
230	{"Faroe Islands (the)", "Féroé (les Îles)", "FO", "FRO", "234"},
231	{"Falkland Islands (the) [Malvinas]", "Falkland (les Îles)/Malouines (les Îles)", "FK", "FLK", "238"},
232	{"South Georgia and the South Sandwich Islands", "Géorgie du Sud-et-les Îles Sandwich du Sud (la)", "GS", "SGS", "239"},
233	{"Fiji", "Fidji (les)", "FJ", "FJI", "242"},
234	{"Finland", "Finlande (la)", "FI", "FIN", "246"},
235	{"Åland Islands", "Åland(les Îles)", "AX", "ALA", "248"},
236	{"France", "France (la)", "FR", "FRA", "250"},
237	{"French Guiana", "Guyane française (la )", "GF", "GUF", "254"},
238	{"French Polynesia", "Polynésie française (la)", "PF", "PYF", "258"},
239	{"French Southern Territories (the)", "Terres australes françaises (les)", "TF", "ATF", "260"},
240	{"Djibouti", "Djibouti", "DJ", "DJI", "262"},
241	{"Gabon", "Gabon (le)", "GA", "GAB", "266"},
242	{"Georgia", "Géorgie (la)", "GE", "GEO", "268"},
243	{"Gambia (the)", "Gambie (la)", "GM", "GMB", "270"},
244	{"Palestine, State of", "Palestine, État de", "PS", "PSE", "275"},
245	{"Germany", "Allemagne (l')", "DE", "DEU", "276"},
246	{"Ghana", "Ghana (le)", "GH", "GHA", "288"},
247	{"Gibraltar", "Gibraltar", "GI", "GIB", "292"},
248	{"Kiribati", "Kiribati", "KI", "KIR", "296"},
249	{"Greece", "Grèce (la)", "GR", "GRC", "300"},
250	{"Greenland", "Groenland (le)", "GL", "GRL", "304"},
251	{"Grenada", "Grenade (la)", "GD", "GRD", "308"},
252	{"Guadeloupe", "Guadeloupe (la)", "GP", "GLP", "312"},
253	{"Guam", "Guam", "GU", "GUM", "316"},
254	{"Guatemala", "Guatemala (le)", "GT", "GTM", "320"},
255	{"Guinea", "Guinée (la)", "GN", "GIN", "324"},
256	{"Guyana", "Guyana (le)", "GY", "GUY", "328"},
257	{"Haiti", "Haïti", "HT", "HTI", "332"},
258	{"Heard Island and McDonald Islands", "Heard-et-Îles MacDonald (l'Île)", "HM", "HMD", "334"},
259	{"Holy See (the)", "Saint-Siège (le)", "VA", "VAT", "336"},
260	{"Honduras", "Honduras (le)", "HN", "HND", "340"},
261	{"Hong Kong", "Hong Kong", "HK", "HKG", "344"},
262	{"Hungary", "Hongrie (la)", "HU", "HUN", "348"},
263	{"Iceland", "Islande (l')", "IS", "ISL", "352"},
264	{"India", "Inde (l')", "IN", "IND", "356"},
265	{"Indonesia", "Indonésie (l')", "ID", "IDN", "360"},
266	{"Iran (Islamic Republic of)", "Iran (République Islamique d')", "IR", "IRN", "364"},
267	{"Iraq", "Iraq (l')", "IQ", "IRQ", "368"},
268	{"Ireland", "Irlande (l')", "IE", "IRL", "372"},
269	{"Israel", "Israël", "IL", "ISR", "376"},
270	{"Italy", "Italie (l')", "IT", "ITA", "380"},
271	{"Côte d'Ivoire", "Côte d'Ivoire (la)", "CI", "CIV", "384"},
272	{"Jamaica", "Jamaïque (la)", "JM", "JAM", "388"},
273	{"Japan", "Japon (le)", "JP", "JPN", "392"},
274	{"Kazakhstan", "Kazakhstan (le)", "KZ", "KAZ", "398"},
275	{"Jordan", "Jordanie (la)", "JO", "JOR", "400"},
276	{"Kenya", "Kenya (le)", "KE", "KEN", "404"},
277	{"Korea (the Democratic People's Republic of)", "Corée (la République populaire démocratique de)", "KP", "PRK", "408"},
278	{"Korea (the Republic of)", "Corée (la République de)", "KR", "KOR", "410"},
279	{"Kuwait", "Koweït (le)", "KW", "KWT", "414"},
280	{"Kyrgyzstan", "Kirghizistan (le)", "KG", "KGZ", "417"},
281	{"Lao People's Democratic Republic (the)", "Lao, République démocratique populaire", "LA", "LAO", "418"},
282	{"Lebanon", "Liban (le)", "LB", "LBN", "422"},
283	{"Lesotho", "Lesotho (le)", "LS", "LSO", "426"},
284	{"Latvia", "Lettonie (la)", "LV", "LVA", "428"},
285	{"Liberia", "Libéria (le)", "LR", "LBR", "430"},
286	{"Libya", "Libye (la)", "LY", "LBY", "434"},
287	{"Liechtenstein", "Liechtenstein (le)", "LI", "LIE", "438"},
288	{"Lithuania", "Lituanie (la)", "LT", "LTU", "440"},
289	{"Luxembourg", "Luxembourg (le)", "LU", "LUX", "442"},
290	{"Macao", "Macao", "MO", "MAC", "446"},
291	{"Madagascar", "Madagascar", "MG", "MDG", "450"},
292	{"Malawi", "Malawi (le)", "MW", "MWI", "454"},
293	{"Malaysia", "Malaisie (la)", "MY", "MYS", "458"},
294	{"Maldives", "Maldives (les)", "MV", "MDV", "462"},
295	{"Mali", "Mali (le)", "ML", "MLI", "466"},
296	{"Malta", "Malte", "MT", "MLT", "470"},
297	{"Martinique", "Martinique (la)", "MQ", "MTQ", "474"},
298	{"Mauritania", "Mauritanie (la)", "MR", "MRT", "478"},
299	{"Mauritius", "Maurice", "MU", "MUS", "480"},
300	{"Mexico", "Mexique (le)", "MX", "MEX", "484"},
301	{"Monaco", "Monaco", "MC", "MCO", "492"},
302	{"Mongolia", "Mongolie (la)", "MN", "MNG", "496"},
303	{"Moldova (the Republic of)", "Moldova , République de", "MD", "MDA", "498"},
304	{"Montenegro", "Monténégro (le)", "ME", "MNE", "499"},
305	{"Montserrat", "Montserrat", "MS", "MSR", "500"},
306	{"Morocco", "Maroc (le)", "MA", "MAR", "504"},
307	{"Mozambique", "Mozambique (le)", "MZ", "MOZ", "508"},
308	{"Oman", "Oman", "OM", "OMN", "512"},
309	{"Namibia", "Namibie (la)", "NA", "NAM", "516"},
310	{"Nauru", "Nauru", "NR", "NRU", "520"},
311	{"Nepal", "Népal (le)", "NP", "NPL", "524"},
312	{"Netherlands (the)", "Pays-Bas (les)", "NL", "NLD", "528"},
313	{"Curaçao", "Curaçao", "CW", "CUW", "531"},
314	{"Aruba", "Aruba", "AW", "ABW", "533"},
315	{"Sint Maarten (Dutch part)", "Saint-Martin (partie néerlandaise)", "SX", "SXM", "534"},
316	{"Bonaire, Sint Eustatius and Saba", "Bonaire, Saint-Eustache et Saba", "BQ", "BES", "535"},
317	{"New Caledonia", "Nouvelle-Calédonie (la)", "NC", "NCL", "540"},
318	{"Vanuatu", "Vanuatu (le)", "VU", "VUT", "548"},
319	{"New Zealand", "Nouvelle-Zélande (la)", "NZ", "NZL", "554"},
320	{"Nicaragua", "Nicaragua (le)", "NI", "NIC", "558"},
321	{"Niger (the)", "Niger (le)", "NE", "NER", "562"},
322	{"Nigeria", "Nigéria (le)", "NG", "NGA", "566"},
323	{"Niue", "Niue", "NU", "NIU", "570"},
324	{"Norfolk Island", "Norfolk (l'Île)", "NF", "NFK", "574"},
325	{"Norway", "Norvège (la)", "NO", "NOR", "578"},
326	{"Northern Mariana Islands (the)", "Mariannes du Nord (les Îles)", "MP", "MNP", "580"},
327	{"United States Minor Outlying Islands (the)", "Îles mineures éloignées des États-Unis (les)", "UM", "UMI", "581"},
328	{"Micronesia (Federated States of)", "Micronésie (États fédérés de)", "FM", "FSM", "583"},
329	{"Marshall Islands (the)", "Marshall (Îles)", "MH", "MHL", "584"},
330	{"Palau", "Palaos (les)", "PW", "PLW", "585"},
331	{"Pakistan", "Pakistan (le)", "PK", "PAK", "586"},
332	{"Panama", "Panama (le)", "PA", "PAN", "591"},
333	{"Papua New Guinea", "Papouasie-Nouvelle-Guinée (la)", "PG", "PNG", "598"},
334	{"Paraguay", "Paraguay (le)", "PY", "PRY", "600"},
335	{"Peru", "Pérou (le)", "PE", "PER", "604"},
336	{"Philippines (the)", "Philippines (les)", "PH", "PHL", "608"},
337	{"Pitcairn", "Pitcairn", "PN", "PCN", "612"},
338	{"Poland", "Pologne (la)", "PL", "POL", "616"},
339	{"Portugal", "Portugal (le)", "PT", "PRT", "620"},
340	{"Guinea-Bissau", "Guinée-Bissau (la)", "GW", "GNB", "624"},
341	{"Timor-Leste", "Timor-Leste (le)", "TL", "TLS", "626"},
342	{"Puerto Rico", "Porto Rico", "PR", "PRI", "630"},
343	{"Qatar", "Qatar (le)", "QA", "QAT", "634"},
344	{"Réunion", "Réunion (La)", "RE", "REU", "638"},
345	{"Romania", "Roumanie (la)", "RO", "ROU", "642"},
346	{"Russian Federation (the)", "Russie (la Fédération de)", "RU", "RUS", "643"},
347	{"Rwanda", "Rwanda (le)", "RW", "RWA", "646"},
348	{"Saint Barthélemy", "Saint-Barthélemy", "BL", "BLM", "652"},
349	{"Saint Helena, Ascension and Tristan da Cunha", "Sainte-Hélène, Ascension et Tristan da Cunha", "SH", "SHN", "654"},
350	{"Saint Kitts and Nevis", "Saint-Kitts-et-Nevis", "KN", "KNA", "659"},
351	{"Anguilla", "Anguilla", "AI", "AIA", "660"},
352	{"Saint Lucia", "Sainte-Lucie", "LC", "LCA", "662"},
353	{"Saint Martin (French part)", "Saint-Martin (partie française)", "MF", "MAF", "663"},
354	{"Saint Pierre and Miquelon", "Saint-Pierre-et-Miquelon", "PM", "SPM", "666"},
355	{"Saint Vincent and the Grenadines", "Saint-Vincent-et-les Grenadines", "VC", "VCT", "670"},
356	{"San Marino", "Saint-Marin", "SM", "SMR", "674"},
357	{"Sao Tome and Principe", "Sao Tomé-et-Principe", "ST", "STP", "678"},
358	{"Saudi Arabia", "Arabie saoudite (l')", "SA", "SAU", "682"},
359	{"Senegal", "Sénégal (le)", "SN", "SEN", "686"},
360	{"Serbia", "Serbie (la)", "RS", "SRB", "688"},
361	{"Seychelles", "Seychelles (les)", "SC", "SYC", "690"},
362	{"Sierra Leone", "Sierra Leone (la)", "SL", "SLE", "694"},
363	{"Singapore", "Singapour", "SG", "SGP", "702"},
364	{"Slovakia", "Slovaquie (la)", "SK", "SVK", "703"},
365	{"Viet Nam", "Viet Nam (le)", "VN", "VNM", "704"},
366	{"Slovenia", "Slovénie (la)", "SI", "SVN", "705"},
367	{"Somalia", "Somalie (la)", "SO", "SOM", "706"},
368	{"South Africa", "Afrique du Sud (l')", "ZA", "ZAF", "710"},
369	{"Zimbabwe", "Zimbabwe (le)", "ZW", "ZWE", "716"},
370	{"Spain", "Espagne (l')", "ES", "ESP", "724"},
371	{"South Sudan", "Soudan du Sud (le)", "SS", "SSD", "728"},
372	{"Sudan (the)", "Soudan (le)", "SD", "SDN", "729"},
373	{"Western Sahara*", "Sahara occidental (le)*", "EH", "ESH", "732"},
374	{"Suriname", "Suriname (le)", "SR", "SUR", "740"},
375	{"Svalbard and Jan Mayen", "Svalbard et l'Île Jan Mayen (le)", "SJ", "SJM", "744"},
376	{"Swaziland", "Swaziland (le)", "SZ", "SWZ", "748"},
377	{"Sweden", "Suède (la)", "SE", "SWE", "752"},
378	{"Switzerland", "Suisse (la)", "CH", "CHE", "756"},
379	{"Syrian Arab Republic", "République arabe syrienne (la)", "SY", "SYR", "760"},
380	{"Tajikistan", "Tadjikistan (le)", "TJ", "TJK", "762"},
381	{"Thailand", "Thaïlande (la)", "TH", "THA", "764"},
382	{"Togo", "Togo (le)", "TG", "TGO", "768"},
383	{"Tokelau", "Tokelau (les)", "TK", "TKL", "772"},
384	{"Tonga", "Tonga (les)", "TO", "TON", "776"},
385	{"Trinidad and Tobago", "Trinité-et-Tobago (la)", "TT", "TTO", "780"},
386	{"United Arab Emirates (the)", "Émirats arabes unis (les)", "AE", "ARE", "784"},
387	{"Tunisia", "Tunisie (la)", "TN", "TUN", "788"},
388	{"Turkey", "Turquie (la)", "TR", "TUR", "792"},
389	{"Turkmenistan", "Turkménistan (le)", "TM", "TKM", "795"},
390	{"Turks and Caicos Islands (the)", "Turks-et-Caïcos (les Îles)", "TC", "TCA", "796"},
391	{"Tuvalu", "Tuvalu (les)", "TV", "TUV", "798"},
392	{"Uganda", "Ouganda (l')", "UG", "UGA", "800"},
393	{"Ukraine", "Ukraine (l')", "UA", "UKR", "804"},
394	{"Macedonia (the former Yugoslav Republic of)", "Macédoine (l'ex‑République yougoslave de)", "MK", "MKD", "807"},
395	{"Egypt", "Égypte (l')", "EG", "EGY", "818"},
396	{"United Kingdom of Great Britain and Northern Ireland (the)", "Royaume-Uni de Grande-Bretagne et d'Irlande du Nord (le)", "GB", "GBR", "826"},
397	{"Guernsey", "Guernesey", "GG", "GGY", "831"},
398	{"Jersey", "Jersey", "JE", "JEY", "832"},
399	{"Isle of Man", "Île de Man", "IM", "IMN", "833"},
400	{"Tanzania, United Republic of", "Tanzanie, République-Unie de", "TZ", "TZA", "834"},
401	{"United States of America (the)", "États-Unis d'Amérique (les)", "US", "USA", "840"},
402	{"Virgin Islands (U.S.)", "Vierges des États-Unis (les Îles)", "VI", "VIR", "850"},
403	{"Burkina Faso", "Burkina Faso (le)", "BF", "BFA", "854"},
404	{"Uruguay", "Uruguay (l')", "UY", "URY", "858"},
405	{"Uzbekistan", "Ouzbékistan (l')", "UZ", "UZB", "860"},
406	{"Venezuela (Bolivarian Republic of)", "Venezuela (République bolivarienne du)", "VE", "VEN", "862"},
407	{"Wallis and Futuna", "Wallis-et-Futuna", "WF", "WLF", "876"},
408	{"Samoa", "Samoa (le)", "WS", "WSM", "882"},
409	{"Yemen", "Yémen (le)", "YE", "YEM", "887"},
410	{"Zambia", "Zambie (la)", "ZM", "ZMB", "894"},
411}
412
413// ISO4217List is the list of ISO currency codes
414var ISO4217List = []string{
415	"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN",
416	"BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD",
417	"CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK",
418	"DJF", "DKK", "DOP", "DZD",
419	"EGP", "ERN", "ETB", "EUR",
420	"FJD", "FKP",
421	"GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD",
422	"HKD", "HNL", "HRK", "HTG", "HUF",
423	"IDR", "ILS", "INR", "IQD", "IRR", "ISK",
424	"JMD", "JOD", "JPY",
425	"KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT",
426	"LAK", "LBP", "LKR", "LRD", "LSL", "LYD",
427	"MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN",
428	"NAD", "NGN", "NIO", "NOK", "NPR", "NZD",
429	"OMR",
430	"PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG",
431	"QAR",
432	"RON", "RSD", "RUB", "RWF",
433	"SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SVC", "SYP", "SZL",
434	"THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS",
435	"UAH", "UGX", "USD", "USN", "UYI", "UYU", "UZS",
436	"VEF", "VND", "VUV",
437	"WST",
438	"XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX",
439	"YER",
440	"ZAR", "ZMW", "ZWL",
441}
442
443// ISO693Entry stores ISO language codes
444type ISO693Entry struct {
445	Alpha3bCode string
446	Alpha2Code  string
447	English     string
448}
449
450//ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json
451var ISO693List = []ISO693Entry{
452	{Alpha3bCode: "aar", Alpha2Code: "aa", English: "Afar"},
453	{Alpha3bCode: "abk", Alpha2Code: "ab", English: "Abkhazian"},
454	{Alpha3bCode: "afr", Alpha2Code: "af", English: "Afrikaans"},
455	{Alpha3bCode: "aka", Alpha2Code: "ak", English: "Akan"},
456	{Alpha3bCode: "alb", Alpha2Code: "sq", English: "Albanian"},
457	{Alpha3bCode: "amh", Alpha2Code: "am", English: "Amharic"},
458	{Alpha3bCode: "ara", Alpha2Code: "ar", English: "Arabic"},
459	{Alpha3bCode: "arg", Alpha2Code: "an", English: "Aragonese"},
460	{Alpha3bCode: "arm", Alpha2Code: "hy", English: "Armenian"},
461	{Alpha3bCode: "asm", Alpha2Code: "as", English: "Assamese"},
462	{Alpha3bCode: "ava", Alpha2Code: "av", English: "Avaric"},
463	{Alpha3bCode: "ave", Alpha2Code: "ae", English: "Avestan"},
464	{Alpha3bCode: "aym", Alpha2Code: "ay", English: "Aymara"},
465	{Alpha3bCode: "aze", Alpha2Code: "az", English: "Azerbaijani"},
466	{Alpha3bCode: "bak", Alpha2Code: "ba", English: "Bashkir"},
467	{Alpha3bCode: "bam", Alpha2Code: "bm", English: "Bambara"},
468	{Alpha3bCode: "baq", Alpha2Code: "eu", English: "Basque"},
469	{Alpha3bCode: "bel", Alpha2Code: "be", English: "Belarusian"},
470	{Alpha3bCode: "ben", Alpha2Code: "bn", English: "Bengali"},
471	{Alpha3bCode: "bih", Alpha2Code: "bh", English: "Bihari languages"},
472	{Alpha3bCode: "bis", Alpha2Code: "bi", English: "Bislama"},
473	{Alpha3bCode: "bos", Alpha2Code: "bs", English: "Bosnian"},
474	{Alpha3bCode: "bre", Alpha2Code: "br", English: "Breton"},
475	{Alpha3bCode: "bul", Alpha2Code: "bg", English: "Bulgarian"},
476	{Alpha3bCode: "bur", Alpha2Code: "my", English: "Burmese"},
477	{Alpha3bCode: "cat", Alpha2Code: "ca", English: "Catalan; Valencian"},
478	{Alpha3bCode: "cha", Alpha2Code: "ch", English: "Chamorro"},
479	{Alpha3bCode: "che", Alpha2Code: "ce", English: "Chechen"},
480	{Alpha3bCode: "chi", Alpha2Code: "zh", English: "Chinese"},
481	{Alpha3bCode: "chu", Alpha2Code: "cu", English: "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic"},
482	{Alpha3bCode: "chv", Alpha2Code: "cv", English: "Chuvash"},
483	{Alpha3bCode: "cor", Alpha2Code: "kw", English: "Cornish"},
484	{Alpha3bCode: "cos", Alpha2Code: "co", English: "Corsican"},
485	{Alpha3bCode: "cre", Alpha2Code: "cr", English: "Cree"},
486	{Alpha3bCode: "cze", Alpha2Code: "cs", English: "Czech"},
487	{Alpha3bCode: "dan", Alpha2Code: "da", English: "Danish"},
488	{Alpha3bCode: "div", Alpha2Code: "dv", English: "Divehi; Dhivehi; Maldivian"},
489	{Alpha3bCode: "dut", Alpha2Code: "nl", English: "Dutch; Flemish"},
490	{Alpha3bCode: "dzo", Alpha2Code: "dz", English: "Dzongkha"},
491	{Alpha3bCode: "eng", Alpha2Code: "en", English: "English"},
492	{Alpha3bCode: "epo", Alpha2Code: "eo", English: "Esperanto"},
493	{Alpha3bCode: "est", Alpha2Code: "et", English: "Estonian"},
494	{Alpha3bCode: "ewe", Alpha2Code: "ee", English: "Ewe"},
495	{Alpha3bCode: "fao", Alpha2Code: "fo", English: "Faroese"},
496	{Alpha3bCode: "fij", Alpha2Code: "fj", English: "Fijian"},
497	{Alpha3bCode: "fin", Alpha2Code: "fi", English: "Finnish"},
498	{Alpha3bCode: "fre", Alpha2Code: "fr", English: "French"},
499	{Alpha3bCode: "fry", Alpha2Code: "fy", English: "Western Frisian"},
500	{Alpha3bCode: "ful", Alpha2Code: "ff", English: "Fulah"},
501	{Alpha3bCode: "geo", Alpha2Code: "ka", English: "Georgian"},
502	{Alpha3bCode: "ger", Alpha2Code: "de", English: "German"},
503	{Alpha3bCode: "gla", Alpha2Code: "gd", English: "Gaelic; Scottish Gaelic"},
504	{Alpha3bCode: "gle", Alpha2Code: "ga", English: "Irish"},
505	{Alpha3bCode: "glg", Alpha2Code: "gl", English: "Galician"},
506	{Alpha3bCode: "glv", Alpha2Code: "gv", English: "Manx"},
507	{Alpha3bCode: "gre", Alpha2Code: "el", English: "Greek, Modern (1453-)"},
508	{Alpha3bCode: "grn", Alpha2Code: "gn", English: "Guarani"},
509	{Alpha3bCode: "guj", Alpha2Code: "gu", English: "Gujarati"},
510	{Alpha3bCode: "hat", Alpha2Code: "ht", English: "Haitian; Haitian Creole"},
511	{Alpha3bCode: "hau", Alpha2Code: "ha", English: "Hausa"},
512	{Alpha3bCode: "heb", Alpha2Code: "he", English: "Hebrew"},
513	{Alpha3bCode: "her", Alpha2Code: "hz", English: "Herero"},
514	{Alpha3bCode: "hin", Alpha2Code: "hi", English: "Hindi"},
515	{Alpha3bCode: "hmo", Alpha2Code: "ho", English: "Hiri Motu"},
516	{Alpha3bCode: "hrv", Alpha2Code: "hr", English: "Croatian"},
517	{Alpha3bCode: "hun", Alpha2Code: "hu", English: "Hungarian"},
518	{Alpha3bCode: "ibo", Alpha2Code: "ig", English: "Igbo"},
519	{Alpha3bCode: "ice", Alpha2Code: "is", English: "Icelandic"},
520	{Alpha3bCode: "ido", Alpha2Code: "io", English: "Ido"},
521	{Alpha3bCode: "iii", Alpha2Code: "ii", English: "Sichuan Yi; Nuosu"},
522	{Alpha3bCode: "iku", Alpha2Code: "iu", English: "Inuktitut"},
523	{Alpha3bCode: "ile", Alpha2Code: "ie", English: "Interlingue; Occidental"},
524	{Alpha3bCode: "ina", Alpha2Code: "ia", English: "Interlingua (International Auxiliary Language Association)"},
525	{Alpha3bCode: "ind", Alpha2Code: "id", English: "Indonesian"},
526	{Alpha3bCode: "ipk", Alpha2Code: "ik", English: "Inupiaq"},
527	{Alpha3bCode: "ita", Alpha2Code: "it", English: "Italian"},
528	{Alpha3bCode: "jav", Alpha2Code: "jv", English: "Javanese"},
529	{Alpha3bCode: "jpn", Alpha2Code: "ja", English: "Japanese"},
530	{Alpha3bCode: "kal", Alpha2Code: "kl", English: "Kalaallisut; Greenlandic"},
531	{Alpha3bCode: "kan", Alpha2Code: "kn", English: "Kannada"},
532	{Alpha3bCode: "kas", Alpha2Code: "ks", English: "Kashmiri"},
533	{Alpha3bCode: "kau", Alpha2Code: "kr", English: "Kanuri"},
534	{Alpha3bCode: "kaz", Alpha2Code: "kk", English: "Kazakh"},
535	{Alpha3bCode: "khm", Alpha2Code: "km", English: "Central Khmer"},
536	{Alpha3bCode: "kik", Alpha2Code: "ki", English: "Kikuyu; Gikuyu"},
537	{Alpha3bCode: "kin", Alpha2Code: "rw", English: "Kinyarwanda"},
538	{Alpha3bCode: "kir", Alpha2Code: "ky", English: "Kirghiz; Kyrgyz"},
539	{Alpha3bCode: "kom", Alpha2Code: "kv", English: "Komi"},
540	{Alpha3bCode: "kon", Alpha2Code: "kg", English: "Kongo"},
541	{Alpha3bCode: "kor", Alpha2Code: "ko", English: "Korean"},
542	{Alpha3bCode: "kua", Alpha2Code: "kj", English: "Kuanyama; Kwanyama"},
543	{Alpha3bCode: "kur", Alpha2Code: "ku", English: "Kurdish"},
544	{Alpha3bCode: "lao", Alpha2Code: "lo", English: "Lao"},
545	{Alpha3bCode: "lat", Alpha2Code: "la", English: "Latin"},
546	{Alpha3bCode: "lav", Alpha2Code: "lv", English: "Latvian"},
547	{Alpha3bCode: "lim", Alpha2Code: "li", English: "Limburgan; Limburger; Limburgish"},
548	{Alpha3bCode: "lin", Alpha2Code: "ln", English: "Lingala"},
549	{Alpha3bCode: "lit", Alpha2Code: "lt", English: "Lithuanian"},
550	{Alpha3bCode: "ltz", Alpha2Code: "lb", English: "Luxembourgish; Letzeburgesch"},
551	{Alpha3bCode: "lub", Alpha2Code: "lu", English: "Luba-Katanga"},
552	{Alpha3bCode: "lug", Alpha2Code: "lg", English: "Ganda"},
553	{Alpha3bCode: "mac", Alpha2Code: "mk", English: "Macedonian"},
554	{Alpha3bCode: "mah", Alpha2Code: "mh", English: "Marshallese"},
555	{Alpha3bCode: "mal", Alpha2Code: "ml", English: "Malayalam"},
556	{Alpha3bCode: "mao", Alpha2Code: "mi", English: "Maori"},
557	{Alpha3bCode: "mar", Alpha2Code: "mr", English: "Marathi"},
558	{Alpha3bCode: "may", Alpha2Code: "ms", English: "Malay"},
559	{Alpha3bCode: "mlg", Alpha2Code: "mg", English: "Malagasy"},
560	{Alpha3bCode: "mlt", Alpha2Code: "mt", English: "Maltese"},
561	{Alpha3bCode: "mon", Alpha2Code: "mn", English: "Mongolian"},
562	{Alpha3bCode: "nau", Alpha2Code: "na", English: "Nauru"},
563	{Alpha3bCode: "nav", Alpha2Code: "nv", English: "Navajo; Navaho"},
564	{Alpha3bCode: "nbl", Alpha2Code: "nr", English: "Ndebele, South; South Ndebele"},
565	{Alpha3bCode: "nde", Alpha2Code: "nd", English: "Ndebele, North; North Ndebele"},
566	{Alpha3bCode: "ndo", Alpha2Code: "ng", English: "Ndonga"},
567	{Alpha3bCode: "nep", Alpha2Code: "ne", English: "Nepali"},
568	{Alpha3bCode: "nno", Alpha2Code: "nn", English: "Norwegian Nynorsk; Nynorsk, Norwegian"},
569	{Alpha3bCode: "nob", Alpha2Code: "nb", English: "Bokmål, Norwegian; Norwegian Bokmål"},
570	{Alpha3bCode: "nor", Alpha2Code: "no", English: "Norwegian"},
571	{Alpha3bCode: "nya", Alpha2Code: "ny", English: "Chichewa; Chewa; Nyanja"},
572	{Alpha3bCode: "oci", Alpha2Code: "oc", English: "Occitan (post 1500); Provençal"},
573	{Alpha3bCode: "oji", Alpha2Code: "oj", English: "Ojibwa"},
574	{Alpha3bCode: "ori", Alpha2Code: "or", English: "Oriya"},
575	{Alpha3bCode: "orm", Alpha2Code: "om", English: "Oromo"},
576	{Alpha3bCode: "oss", Alpha2Code: "os", English: "Ossetian; Ossetic"},
577	{Alpha3bCode: "pan", Alpha2Code: "pa", English: "Panjabi; Punjabi"},
578	{Alpha3bCode: "per", Alpha2Code: "fa", English: "Persian"},
579	{Alpha3bCode: "pli", Alpha2Code: "pi", English: "Pali"},
580	{Alpha3bCode: "pol", Alpha2Code: "pl", English: "Polish"},
581	{Alpha3bCode: "por", Alpha2Code: "pt", English: "Portuguese"},
582	{Alpha3bCode: "pus", Alpha2Code: "ps", English: "Pushto; Pashto"},
583	{Alpha3bCode: "que", Alpha2Code: "qu", English: "Quechua"},
584	{Alpha3bCode: "roh", Alpha2Code: "rm", English: "Romansh"},
585	{Alpha3bCode: "rum", Alpha2Code: "ro", English: "Romanian; Moldavian; Moldovan"},
586	{Alpha3bCode: "run", Alpha2Code: "rn", English: "Rundi"},
587	{Alpha3bCode: "rus", Alpha2Code: "ru", English: "Russian"},
588	{Alpha3bCode: "sag", Alpha2Code: "sg", English: "Sango"},
589	{Alpha3bCode: "san", Alpha2Code: "sa", English: "Sanskrit"},
590	{Alpha3bCode: "sin", Alpha2Code: "si", English: "Sinhala; Sinhalese"},
591	{Alpha3bCode: "slo", Alpha2Code: "sk", English: "Slovak"},
592	{Alpha3bCode: "slv", Alpha2Code: "sl", English: "Slovenian"},
593	{Alpha3bCode: "sme", Alpha2Code: "se", English: "Northern Sami"},
594	{Alpha3bCode: "smo", Alpha2Code: "sm", English: "Samoan"},
595	{Alpha3bCode: "sna", Alpha2Code: "sn", English: "Shona"},
596	{Alpha3bCode: "snd", Alpha2Code: "sd", English: "Sindhi"},
597	{Alpha3bCode: "som", Alpha2Code: "so", English: "Somali"},
598	{Alpha3bCode: "sot", Alpha2Code: "st", English: "Sotho, Southern"},
599	{Alpha3bCode: "spa", Alpha2Code: "es", English: "Spanish; Castilian"},
600	{Alpha3bCode: "srd", Alpha2Code: "sc", English: "Sardinian"},
601	{Alpha3bCode: "srp", Alpha2Code: "sr", English: "Serbian"},
602	{Alpha3bCode: "ssw", Alpha2Code: "ss", English: "Swati"},
603	{Alpha3bCode: "sun", Alpha2Code: "su", English: "Sundanese"},
604	{Alpha3bCode: "swa", Alpha2Code: "sw", English: "Swahili"},
605	{Alpha3bCode: "swe", Alpha2Code: "sv", English: "Swedish"},
606	{Alpha3bCode: "tah", Alpha2Code: "ty", English: "Tahitian"},
607	{Alpha3bCode: "tam", Alpha2Code: "ta", English: "Tamil"},
608	{Alpha3bCode: "tat", Alpha2Code: "tt", English: "Tatar"},
609	{Alpha3bCode: "tel", Alpha2Code: "te", English: "Telugu"},
610	{Alpha3bCode: "tgk", Alpha2Code: "tg", English: "Tajik"},
611	{Alpha3bCode: "tgl", Alpha2Code: "tl", English: "Tagalog"},
612	{Alpha3bCode: "tha", Alpha2Code: "th", English: "Thai"},
613	{Alpha3bCode: "tib", Alpha2Code: "bo", English: "Tibetan"},
614	{Alpha3bCode: "tir", Alpha2Code: "ti", English: "Tigrinya"},
615	{Alpha3bCode: "ton", Alpha2Code: "to", English: "Tonga (Tonga Islands)"},
616	{Alpha3bCode: "tsn", Alpha2Code: "tn", English: "Tswana"},
617	{Alpha3bCode: "tso", Alpha2Code: "ts", English: "Tsonga"},
618	{Alpha3bCode: "tuk", Alpha2Code: "tk", English: "Turkmen"},
619	{Alpha3bCode: "tur", Alpha2Code: "tr", English: "Turkish"},
620	{Alpha3bCode: "twi", Alpha2Code: "tw", English: "Twi"},
621	{Alpha3bCode: "uig", Alpha2Code: "ug", English: "Uighur; Uyghur"},
622	{Alpha3bCode: "ukr", Alpha2Code: "uk", English: "Ukrainian"},
623	{Alpha3bCode: "urd", Alpha2Code: "ur", English: "Urdu"},
624	{Alpha3bCode: "uzb", Alpha2Code: "uz", English: "Uzbek"},
625	{Alpha3bCode: "ven", Alpha2Code: "ve", English: "Venda"},
626	{Alpha3bCode: "vie", Alpha2Code: "vi", English: "Vietnamese"},
627	{Alpha3bCode: "vol", Alpha2Code: "vo", English: "Volapük"},
628	{Alpha3bCode: "wel", Alpha2Code: "cy", English: "Welsh"},
629	{Alpha3bCode: "wln", Alpha2Code: "wa", English: "Walloon"},
630	{Alpha3bCode: "wol", Alpha2Code: "wo", English: "Wolof"},
631	{Alpha3bCode: "xho", Alpha2Code: "xh", English: "Xhosa"},
632	{Alpha3bCode: "yid", Alpha2Code: "yi", English: "Yiddish"},
633	{Alpha3bCode: "yor", Alpha2Code: "yo", English: "Yoruba"},
634	{Alpha3bCode: "zha", Alpha2Code: "za", English: "Zhuang; Chuang"},
635	{Alpha3bCode: "zul", Alpha2Code: "zu", English: "Zulu"},
636}
637