utils: is_alpha, is_digit, is_numeric, is_alphanum, is_whitespace utility functions
authorMichael Moon <triffid.hunter@gmail.com>
Fri, 18 Jan 2013 03:06:13 +0000 (14:06 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Fri, 18 Jan 2013 03:10:14 +0000 (14:10 +1100)
src/libs/utils.cpp
src/libs/utils.h

index bd6dd51..58d3842 100644 (file)
@@ -42,6 +42,39 @@ void get_checksums(uint16_t check_sums[], const string key){
     }
 }
 
+bool is_alpha(int c)
+{
+    if ((c >= 'a') && (c <= 'z')) return true;
+    if ((c >= 'A') && (c <= 'Z')) return true;
+    if ((c == '_')) return true;
+    return false;
+}
+
+bool is_digit(int c)
+{
+    if ((c >= '0') && (c <= '9')) return true;
+    return false;
+}
+
+bool is_numeric(int c)
+{
+    if (is_digit(c)) return true;
+    if ((c == '.') || (c == '-')) return true;
+    if ((c == 'e')) return true;
+    return false;
+}
+
+bool is_alphanum(int c)
+{
+    return is_alpha(c) || is_numeric(c);
+}
+
+bool is_whitespace(int c)
+{
+    if ((c == ' ') || (c == '\t')) return true;
+    return false;
+}
+
 // Convert to lowercase
 string lc(string str){
     for (unsigned int i=0; i<strlen(str.c_str()); i++)
index e54d61c..23b2801 100644 (file)
@@ -11,6 +11,12 @@ extern volatile bool _isr_context;
 
 string lc(string str);
 
+bool is_alpha( int );
+bool is_digit( int );
+bool is_numeric( int );
+bool is_alphanum( int );
+bool is_whitespace( int );
+
 string remove_non_number( string str );
 
 uint16_t get_checksum(const string to_check);