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;
+}
# Country
loc_country_cmp;
+ loc_country_code_is_valid;
loc_country_get_code;
loc_country_get_continent_code;
loc_country_get_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>
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];
asns.append(object)
- elif not len(object) == 2:
- log.error("Invalid argument: %s" % object)
- return 2
+ elif location.country_code_is_valid(object):
+ countries.append(object)
else:
- countries.append(object)
+ log.error("Invalid argument: %s" % object)
+ return 2
# Open the database
try:
return PyLong_FromUnsignedLong(t);
}
+static PyObject* country_code_is_valid(PyObject* m, PyObject* args) {
+ const char* country_code = NULL;
+
+ if (!PyArg_ParseTuple(args, "s", &country_code))
+ return NULL;
+
+ if (loc_country_code_is_valid(country_code))
+ Py_RETURN_TRUE;
+
+ Py_RETURN_FALSE;
+}
+
static PyMethodDef location_module_methods[] = {
+ {
+ "country_code_is_valid",
+ (PyCFunction)country_code_is_valid,
+ METH_VARARGS,
+ NULL,
+ },
{
"discover_latest_version",
(PyCFunction)discover_latest_version,