edelib
2.0.0
|
00001 /* 00002 * $Id: StrUtil.h 2839 2009-09-28 11:36:20Z karijes $ 00003 * 00004 * Basic functions for C string handling 00005 * Copyright (c) 2005-2007 edelib authors 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef __EDELIB_STRUTIL_H__ 00022 #define __EDELIB_STRUTIL_H__ 00023 00024 #include "String.h" 00025 00026 EDELIB_NS_BEGIN 00027 00031 EDELIB_API char* str_trimleft(char* str); 00032 00036 EDELIB_API char* str_trimright(char* str); 00037 00041 EDELIB_API char* str_trim(char* str); 00042 00046 EDELIB_API unsigned char* str_tolower(unsigned char* str); 00047 00051 EDELIB_API unsigned char* str_toupper(unsigned char* str); 00052 00060 EDELIB_API bool str_ends(const char* str, const char* test); 00061 00076 template <typename Container> 00077 void stringtok(Container& c, const String& str, const char* ws = " \t\n") { 00078 const String::size_type sz = str.length(); 00079 String::size_type i = 0, j = 0; 00080 00081 while(i < sz) { 00082 while((i < sz) && (strchr(ws, str[i]) != NULL)) 00083 i++; 00084 if(i == sz) 00085 return; 00086 j = i + 1; 00087 while((j < sz) && (strchr(ws, str[j]) == NULL)) 00088 j++; 00089 00090 c.push_back(str.substr(i, j-i)); 00091 i = j + 1; 00092 } 00093 } 00094 00095 EDELIB_NS_END 00096 #endif