]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/loc/country.h
location-export: Validate country codes
[people/ms/libloc.git] / src / loc / country.h
index 6dfb47ba3204b0208e3349b3b007544d6ab4316a..9757b2a77d6ff64f03ed14345666ad775da66be6 100644 (file)
@@ -36,6 +36,8 @@ int loc_country_set_name(struct loc_country* country, const char* name);
 
 int loc_country_cmp(struct loc_country* country1, struct loc_country* country2);
 
+int loc_country_code_is_valid(const char* cc);
+
 #ifdef LIBLOC_PRIVATE
 
 #include <string.h>
@@ -45,25 +47,6 @@ int loc_country_new_from_database_v0(struct loc_ctx* ctx, struct loc_stringpool*
 int loc_country_to_database_v0(struct loc_country* country,
     struct loc_stringpool* pool, struct loc_database_country_v0* dbobj);
 
-static inline 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;
-}
-
 static inline void loc_country_code_copy(char* dst, const char* src) {
     for (unsigned int i = 0; i < 2; i++) {
         dst[i] = src[i];