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
26EDELIB_NS_BEGIN
27
31EDELIB_API char* str_trimleft(char* str);
32
36EDELIB_API char* str_trimright(char* str);
37
41EDELIB_API char* str_trim(char* str);
42
46EDELIB_API unsigned char* str_tolower(unsigned char* str);
47
51EDELIB_API unsigned char* str_toupper(unsigned char* str);
52
60EDELIB_API bool str_ends(const char* str, const char* test);
61
69EDELIB_API unsigned int str_hash(const char* str, unsigned int len = 0);
70
85template <typename Container>
86void 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
104EDELIB_NS_END
105#endif
A (relatively simple) string implementation.
Definition String.h:82
String substr(size_type index, size_type num=npos) const
size_type length(void) const
Definition String.h:292
void stringtok(Container &c, const String &str, const char *ws=" \t\n")
Definition StrUtil.h:86
char * str_trimright(char *str)
char * str_trim(char *str)
bool str_ends(const char *str, const char *test)
unsigned char * str_tolower(unsigned char *str)
unsigned int str_hash(const char *str, unsigned int len=0)
char * str_trimleft(char *str)
unsigned char * str_toupper(unsigned char *str)