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