Name
loc_country_code_is_valid, loc_country_special_code_to_flag - Check country codes
Synopsis
#include <libloc/country.h> int loc_country_code_is_valid(const char* country_code); int loc_country_special_code_to_flag(const char* country_code);
Description
loc_country_code_is_valid() checks whether country_code can be the code of a country: two upper case letters, which do not start with X, because those codes are reserved for private use.
loc_country_special_code_to_flag() returns the flag for one of the special codes A1, A2, A3 and XD (see loc_network_get_asn(3)), which are not countries.
These are useful to check input before passing it to the functions that take a country code, for example loc_database_get_country(3) or loc_network_get_asn(3).
Return Value
loc_country_code_is_valid() returns 1 if the code is valid, and zero otherwise.
loc_country_special_code_to_flag() returns the flag, zero if country_code is not a special code, or -EINVAL if it is NULL or empty.
Example
if (loc_country_special_code_to_flag(code) > 0)
printf("%s is a flag\n", code);
else if (loc_country_code_is_valid(code))
printf("%s is a country\n", code);
else
printf("%s is not a country code\n", code);
See Also
Authors
Michael Tremer