Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Text.h
Go to the documentation of this file.
1
/* Project FoundationEx
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: FoundationEx
6
FILE: Text.h
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Declaration of the Text class
13
*/
14
15
#ifndef Text_h
16
#define Text_h
17
18
#include <string.h>
19
#include <windows.h>
20
#include "
ThreadSync.h
"
21
22
// +-------------------------------------------------------------------+
23
24
class
TextRep
25
{
26
friend
class
Text
;
27
28
public
:
29
TextRep
();
30
~TextRep
();
31
32
private
:
33
TextRep
(
const
char
* s);
34
TextRep
(
const
char
* s,
int
len);
35
TextRep
(
char
c,
int
len);
36
TextRep
(
const
TextRep
* rep);
37
38
void
addref();
39
long
deref();
40
41
void
dohash();
42
43
char
*
data
;
44
long
ref;
45
int
length
;
46
unsigned
hash
;
47
bool
sensitive;
48
49
static
ThreadSync
sync;
50
static
TextRep
nullrep;
51
};
52
53
// +-------------------------------------------------------------------+
54
55
class
Text
56
{
57
public
:
58
static
const
char
*
TYPENAME
() {
return
"Text"
; }
59
60
Text
();
61
Text
(
char
c);
62
Text
(
const
char
* s);
63
Text
(
const
char
* s,
int
len);
64
Text
(
char
c,
int
len);
65
Text
(
const
Text
& s);
66
~Text
();
67
68
// case sensitivity
69
bool
isSensitive
()
const
;
70
void
setSensitive
(
bool
s);
71
72
// comparison
73
int
compare
(
const
char
* s)
const
;
74
int
compare
(
const
Text
& s)
const
;
75
76
// assignment
77
Text
&
operator=
(
const
char
* s);
78
Text
&
operator=
(
const
Text
& s);
79
80
// catenation
81
Text
&
append
(
char
c);
82
Text
&
append
(
const
char
* s);
83
Text
&
append
(
const
Text
& s);
84
85
Text
operator+
(
char
c);
86
Text
operator+
(
const
char
* s);
87
Text
operator+
(
const
Text
& s);
88
89
Text
&
operator+=
(
char
c) {
return
append
(c); }
90
Text
&
operator+=
(
const
char
* s) {
return
append
(s); }
91
Text
&
operator+=
(
const
Text
& s) {
return
append
(s); }
92
93
// indexing
94
char
operator[]
(
int
index)
const
;
95
char
operator()
(
int
index)
const
;
96
char
&
operator[]
(
int
index);
97
char
&
operator()
(
int
index);
98
99
Text
operator()
(
int
start,
int
len)
const
;
100
101
// access
102
int
length
()
const
{
return
rep->length; }
103
unsigned
hash
()
const
{
return
rep->hash; }
104
105
const
char
*
data
()
const
{
return
sym; }
106
operator
const
char
* ()
const
{
return
sym; }
107
108
bool
contains
(
char
c)
const
;
109
bool
contains
(
const
char
* s)
const
;
110
111
bool
containsAnyOf
(
const
char
* charSet)
const
;
112
113
int
indexOf
(
char
c)
const
;
114
int
indexOf
(
const
char
* s)
const
;
115
116
// mutation
117
void
toLower
();
118
void
toUpper
();
119
120
// substring
121
Text
substring
(
int
start,
int
length
);
122
Text
trim
();
123
Text
replace
(
const
char
* pattern,
const
char
* substitution);
124
125
private
:
126
void
clone();
127
128
const
char
* sym;
129
TextRep
* rep;
130
};
131
132
// +-------------------------------------------------------------------+
133
134
inline
int
Text::compare
(
const
char
* s)
const
135
{
136
if
(rep->sensitive)
137
return
strcmp(sym, s);
138
else
139
return
_stricmp(sym, s);
140
}
141
142
inline
int
Text::compare
(
const
Text
& s)
const
143
{
144
if
(rep->sensitive && s.rep->sensitive)
145
return
strcmp(sym, s.sym);
146
else
147
return
_stricmp(sym, s.sym);
148
}
149
150
// +-------------------------------------------------------------------+
151
152
inline
int
operator==
(
const
Text
& l,
const
Text
& r) {
153
return
(l.
length
() == r.
length
()) && (l.
compare
(r) == 0); }
154
inline
int
operator!=
(
const
Text
& l,
const
Text
& r) {
return
l.
compare
(r) != 0; }
155
inline
int
operator<
(
const
Text
& l,
const
Text
& r) {
return
l.
compare
(r) < 0; }
156
inline
int
operator<=
(
const
Text
& l,
const
Text
& r) {
return
l.
compare
(r) <= 0; }
157
inline
int
operator>
(
const
Text
& l,
const
Text
& r) {
return
l.
compare
(r) > 0; }
158
inline
int
operator>=
(
const
Text
& l,
const
Text
& r) {
return
l.
compare
(r) >= 0; }
159
160
inline
int
operator==
(
const
char
* l,
const
Text
& r) {
return
r.
compare
(l) == 0; }
161
inline
int
operator!=
(
const
char
* l,
const
Text
& r) {
return
r.
compare
(l) != 0; }
162
inline
int
operator<
(
const
char
* l,
const
Text
& r) {
return
r.
compare
(l) < 0; }
163
inline
int
operator<=
(
const
char
* l,
const
Text
& r) {
return
r.
compare
(l) <= 0; }
164
inline
int
operator>
(
const
char
* l,
const
Text
& r) {
return
r.
compare
(l) > 0; }
165
inline
int
operator>=
(
const
char
* l,
const
Text
& r) {
return
r.
compare
(l) >= 0; }
166
167
inline
int
operator==
(
char
* l,
const
Text
& r) {
return
r.
compare
(l) == 0; }
168
inline
int
operator!=
(
char
* l,
const
Text
& r) {
return
r.
compare
(l) != 0; }
169
inline
int
operator<
(
char
* l,
const
Text
& r) {
return
r.
compare
(l) < 0; }
170
inline
int
operator<=
(
char
* l,
const
Text
& r) {
return
r.
compare
(l) <= 0; }
171
inline
int
operator>
(
char
* l,
const
Text
& r) {
return
r.
compare
(l) > 0; }
172
inline
int
operator>=
(
char
* l,
const
Text
& r) {
return
r.
compare
(l) >= 0; }
173
174
inline
int
operator==
(
const
Text
& l,
const
char
* r) {
return
l.
compare
(r) == 0; }
175
inline
int
operator!=
(
const
Text
& l,
const
char
* r) {
return
l.
compare
(r) != 0; }
176
inline
int
operator<
(
const
Text
& l,
const
char
* r) {
return
l.
compare
(r) < 0; }
177
inline
int
operator<=
(
const
Text
& l,
const
char
* r) {
return
l.
compare
(r) <= 0; }
178
inline
int
operator>
(
const
Text
& l,
const
char
* r) {
return
l.
compare
(r) > 0; }
179
inline
int
operator>=
(
const
Text
& l,
const
char
* r) {
return
l.
compare
(r) >= 0; }
180
181
inline
int
operator==
(
const
Text
& l,
char
* r) {
return
l.
compare
(r) == 0; }
182
inline
int
operator!=
(
const
Text
& l,
char
* r) {
return
l.
compare
(r) != 0; }
183
inline
int
operator<
(
const
Text
& l,
char
* r) {
return
l.
compare
(r) < 0; }
184
inline
int
operator<=
(
const
Text
& l,
char
* r) {
return
l.
compare
(r) <= 0; }
185
inline
int
operator>
(
const
Text
& l,
char
* r) {
return
l.
compare
(r) > 0; }
186
inline
int
operator>=
(
const
Text
& l,
char
* r) {
return
l.
compare
(r) >= 0; }
187
188
inline
Text
operator+
(
const
char
* l,
const
Text
& r) {
return
Text
(l) + r; }
189
inline
Text
operator+
(
char
* l,
const
Text
& r) {
return
Text
(l) + r; }
190
191
// +-------------------------------------------------------------------+
192
193
#endif Text_h
FoundationEx
Text.h
Generated on Tue Jun 5 2012 20:46:14 for Starshatter_Open by
1.8.1