X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Futils.cpp;h=675a2b1094b44f05d44b8cdb3e25cd732b2f72a0;hb=53a9d24ac42a042eedcacf00e906a989b6773bb0;hp=2232527dbdbab79696a3f6011935a690f3201bae;hpb=a3bf8b72faa5fce99f0f6384d6d9b6588a1de072;p=libs%2Fcore.git diff --git a/source/utils.cpp b/source/utils.cpp index 2232527..675a2b1 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,10 +1,11 @@ /* $Id$ This file is part of libmspstrings -Copyright © 2006-2007 Mikko Rasa +Copyright © 2006-2008 Mikko Rasa Distributed under the LGPL */ +#include #include #include #include "utils.h" @@ -45,6 +46,14 @@ vector do_split(const string &str, const string &sep, int max_split) 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 { @@ -78,6 +87,21 @@ string toupper(const string &str) 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 split(const string &str, const string &sep, int max_split) { return do_split(str, sep, max_split); @@ -115,13 +139,13 @@ vector split(const string &str, const string &sep, bool allow_empty) { vector result; - unsigned start=0; + string::size_type start=0; if(!allow_empty) start=str.find_first_not_of(sep); while(start(*i)<' ' || (escape_8bit && (*i&0x80))) { - char buf[4]={'\\', '0'+((*i>>6)&7), '0'+((*i>>3)&7), '0'+(*i&7)}; + char buf[4]={'\\', '0'+((*i>>6)&3), '0'+((*i>>3)&7), '0'+(*i&7)}; result.append(buf, 4); } else