edelib  2.1.0
StrUtil.h
1 /*
2  * $Id: StrUtil.h 3427 2012-10-08 12:55:32Z 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 
69 EDELIB_API unsigned int str_hash(const char* str, unsigned int len = 0);
70 
85 template <typename Container>
86 void stringtok(Container& c, const String& str, const char* ws = " \t\n") {
87  const String::size_type sz = str.length();
88  String::size_type i = 0, j = 0;
89 
90  while(i < sz) {
91  while((i < sz) && (strchr(ws, str[i]) != NULL))
92  i++;
93  if(i == sz)
94  return;
95  j = i + 1;
96  while((j < sz) && (strchr(ws, str[j]) == NULL))
97  j++;
98 
99  c.push_back(str.substr(i, j-i));
100  i = j + 1;
101  }
102 }
103 
104 EDELIB_NS_END
105 #endif
unsigned char * str_toupper(unsigned char *str)
char * str_trim(char *str)
unsigned int str_hash(const char *str, unsigned int len=0)
unsigned char * str_tolower(unsigned char *str)
char * str_trimleft(char *str)
size_type length(void) const
Definition: String.h:292
String substr(size_type index, size_type num=npos) const
A (relatively simple) string implementation.
Definition: String.h:82
char * str_trimright(char *str)
void stringtok(Container &c, const String &str, const char *ws=" \t\n")
Definition: StrUtil.h:86
bool str_ends(const char *str, const char *test)