[project @ 2002-08-06 20:48:44 by unknown_lamer]
[clinton/bobotpp.git] / source / String.H
CommitLineData
cb21075d 1// String.H -*- C++ -*-
2// Copyright (c) 1997, 1998 Etienne BERNARD
3// Copyright (c) 2002 Clinton Ebadi
4
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// any later version.
9
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef STRING_H
20#define STRING_H
21
22#include <iostream>
23#include <string>
24
25class String {
26
27 struct srep {
28 char *s; // pointer on the data
29 int n; // reference counter
30 srep()
31 { n = 1; }
32 };
33 srep *p;
34 int len;
35
36public:
37 String();
38 String(const char *);
39 String(const String &);
40 String(const std::string &);
41 String(long);
42 String(char);
43
44 String & operator=(const char *);
45 String & operator=(const String &);
46 String & operator=(const std::string &);
47
48 ~String();
49
50 int length() const;
51 int find(char);
52 void fill(char);
53 String pad(int);
54
55 String subString(int);
56 String subString(int, int);
57
58 String toLower();
59 String toUpper();
60 String trim();
61 int indexOf(char);
62
63 char & operator[](int);
64 const char & operator[](int) const;
65
66 bool operator==(const char *) const;
67 bool operator==(const String &) const;
68 bool operator==(const std::string &) const;
69
70 bool operator!=(const char *) const;
71 bool operator!=(const String &) const;
72 bool operator!=(const std::string &) const;
73
74 bool operator<(const String &) const;
75 bool operator>(const String &) const;
76 bool operator<(const std::string &) const;
77
78 bool operator<=(const String &) const;
79 bool operator<=(const std::string &) const;
80 bool operator>=(const String &) const;
81 bool operator>=(const std::string &) const;
82
83 String operator+(const char *);
84 String operator+(const String &);
85 String operator+(const std::string &);
86
87 friend std::string operator+(const std::string &, const String &);
88
89 operator const char *() const;
90 operator std::string () const;
91
92 friend std::ostream & operator<<(std::ostream &, const String &);
93 friend std::istream & operator>>(std::istream &, String &);
94};
95
96bool operator==(const std::string &, const String &);
97bool operator!=(const std::string &, const String &);
98bool operator>(const std::string &, const String &);
99bool operator<(const std::string &, const String &);
100bool operator<=(const std::string &, const String &);
101bool operator>=(const std::string &, const String &);
102
103#endif