X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fcountry.c;h=45d26b82ef49dd156df61b6d66555185c37e5f33;hb=0f0829ef3e265cf8e7df9321e8a6bf7d71a8c7bf;hp=909895047f922eeb5578c016b21f29f51a7af5f2;hpb=a4ba47626015fea7bd2a2d3e3047fea337760fe4;p=people%2Fms%2Flibloc.git diff --git a/src/country.c b/src/country.c index 9098950..45d26b8 100644 --- a/src/country.c +++ b/src/country.c @@ -172,3 +172,22 @@ int loc_country_to_database_v0(struct loc_country* country, return 0; } + +LOC_EXPORT int loc_country_code_is_valid(const char* cc) { + // It cannot be NULL + if (!cc || !*cc) + return 0; + + // It must be 2 characters long + if (strlen(cc) != 2) + return 0; + + // It must only contain A-Z + for (unsigned int i = 0; i < 2; i++) { + if (cc[i] < 'A' || cc[i] > 'Z') + return 0; + } + + // Looks valid + return 1; +}