3
** Copyright (C) 2000,2001 by Bernhard Rosenkraenzer
5
** Contributions by A. Seigo and W. Bastian.
10
** This program is free software; you can redistribute it and/or modify
11
** it under the terms of the GNU General Public License as published by
12
** the Free Software Foundation; either version 2 of the License, or
13
** (at your option) any later version.
15
** This program is distributed in the hope that it will be useful,
16
** but WITHOUT ANY WARRANTY; without even the implied warranty of
17
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
** GNU General Public License for more details.
20
** You should have received a copy of the GNU General Public License
21
** along with this program in a file called COPYING; if not, write to
22
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
** MA 02110-1301, USA.
27
** Bug reports and questions can be sent to <kde-devel@kde.org>
29
/* Somewhat more sane string handling functions... *
30
* Should be portable, therefore we aren't simply using QString. */
42
typedef std::list<String> strlist;
44
class String:public std::string {
46
String():std::string("") { }
47
String(char const * const &s):std::string(s) { }
48
String(std::string const &s):std::string(s) { }
49
String const operator +(char const &s);
50
String const operator +(char const * const s);
51
bool operator ==(char s);
52
bool operator !=(char s);
53
operator char * () const { return cstr(); }
55
bool cmp(char const * const s) const;
56
bool casecmp(char const * const s) const;
57
bool contains(String const &s, bool cs=true) const;
58
int locate(String const &s, bool cs=true, unsigned int startat=0) const;
59
void sprintf(const char *format, ...);
60
bool readfile(String filename);
61
String simplifyWhiteSpace() const;
62
String left(unsigned int num=1) const;
63
String right(unsigned int num=1) const;
64
String mid(unsigned int start, unsigned int num=0) const;
65
String ®ex(String const &expr, bool cs=true) const;
66
String &replace(String const &what, String const &with, bool all=true) const;
67
static String escapeForRegExp(String const &s);
68
char chr(unsigned int index) const { if(index>=size()) return 0; else return data()[index]; }
69
int length() const { return size(); } // For compatibility with QString
70
char const *latin1() const { return cstr(); } // For compatibility with QString
73
class StringList:public strlist {
75
StringList() { clear(); }
76
StringList(String const &s);
77
StringList(char **strs, int num=-1);
78
bool readfile(String const &filename);
79
bool writefile(String const &filename) const;
80
void operator +=(String const &s) { insert(end(), s); }
81
void operator +=(char const * const &s) { insert(end(), s); }
82
void operator +=(StringList const &s);
83
void operator +=(StringList const * const s);
84
operator String() const;
85
bool contains(String const &s) const;
86
void remove(String const &s);
87
void add(String const &s) { insert(end(), s); }
88
String const &grep(String const &s) const;
89
void sort(bool cs=true);
92
std::ostream &operator <<(std::ostream &os, String const &s);
93
std::ostream &operator <<(std::ostream &os, String const *s);
94
std::ostream &operator <<(std::ostream &os, StringList const &s);
95
std::ostream &operator <<(std::ostream &os, StringList const *s);