edelib  0.0
StrUtil.h
1 /*
2  * $Id: StrUtil.h 2839 2009-09-28 11:36:20Z karijes $
3  *
4  * Basic functions for C string handling
5  * Copyright (c) 2005-2007 edelib authors
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __EDELIB_STRUTIL_H__
22 #define __EDELIB_STRUTIL_H__
23 
24 #include "String.h"
25 
26 EDELIB_NS_BEGIN
27 
31 EDELIB_API char* str_trimleft(char* str);
32 
36 EDELIB_API char* str_trimright(char* str);
37 
41 EDELIB_API char* str_trim(char* str);
42 
46 EDELIB_API unsigned char* str_tolower(unsigned char* str);
47 
51 EDELIB_API unsigned char* str_toupper(unsigned char* str);
52 
60 EDELIB_API bool str_ends(const char* str, const char* test);
61 
76 template <typename Container>
77 void stringtok(Container& c, const String& str, const char* ws = " \t\n") {
78  const String::size_type sz = str.length();
79  String::size_type i = 0, j = 0;
80 
81  while(i < sz) {
82  while((i < sz) && (strchr(ws, str[i]) != NULL))
83  i++;
84  if(i == sz)
85  return;
86  j = i + 1;
87  while((j < sz) && (strchr(ws, str[j]) == NULL))
88  j++;
89 
90  c.push_back(str.substr(i, j-i));
91  i = j + 1;
92  }
93 }
94 
95 EDELIB_NS_END
96 #endif