]> git.tdb.fi Git - libs/core.git/blobdiff - source/utils.cpp
Add utility functions to check the contents of a string
[libs/core.git] / source / utils.cpp
index d67cc7e8bcd3947f62947be762af28aa60bf3f30..baf1333138b82807864df7bb1f04ebc7365e3f33 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspstrings
 /* $Id$
 
 This file is part of libmspstrings
-Copyright © 2006-2007 Mikko Rasa
+Copyright © 2006-2008 Mikko Rasa
 Distributed under the LGPL
 */
 
 Distributed under the LGPL
 */
 
@@ -46,6 +46,14 @@ vector<string> do_split(const string &str, const string &sep, int max_split)
        return result;
 }
 
        return result;
 }
 
+bool check_str(const std::string &str, int (*pred)(int))
+{
+       for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
+               if(!pred(*i))
+                       return false;
+       return true;
+}
+
 }
 
 namespace Msp {
 }
 
 namespace Msp {
@@ -79,6 +87,21 @@ string toupper(const string &str)
        return result;
 }
 
        return result;
 }
 
+bool isnumrc(const string &str)
+{
+       return check_str(str, isdigit);
+}
+
+bool isalpha(const string &str)
+{
+       return check_str(str, isalpha);
+}
+
+bool isalnum(const string &str)
+{
+       return check_str(str, isalnum);
+}
+
 vector<string> split(const string &str, const string &sep, int max_split)
 {
        return do_split<false, false>(str, sep, max_split);
 vector<string> split(const string &str, const string &sep, int max_split)
 {
        return do_split<false, false>(str, sep, max_split);