rllib
1
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
lib
rlstring.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
rlmailbox.cpp - description
3
-------------------
4
begin : Wed Jan 02 2008
5
copyright : (C) Lehrig Software Enigineering
6
email : lehrig@t-online.de
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This library is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13
* published by the Free Software Foundation *
14
* *
15
***************************************************************************/
16
17
#include <stdarg.h>
18
#include "
rlstring.h
"
19
#include "
rlcutil.h
"
20
21
rlString::rlString
(
const
char
*text)
22
{
23
txt
=
new
char
[strlen(text)+1];
24
::strcpy
(
txt
, text);
25
}
26
27
rlString::rlString
(
rlString
&s2)
28
{
29
txt
=
new
char
[strlen(s2.
text
())+1];
30
::strcpy
(
txt
,s2.
text
());
31
}
32
33
rlString::rlString
(
rlString
*s2)
34
{
35
txt
=
new
char
[strlen(s2->
text
())+1];
36
::strcpy
(
txt
,s2->
text
());
37
}
38
39
rlString::~rlString
()
40
{
41
delete
[]
txt
;
42
}
43
44
rlString
&
rlString::operator=
(
const
char
*s2)
45
{
46
this->
setText
(s2);
47
return
*
this
;
48
}
49
50
rlString
&
rlString::operator=
(
rlString
&s2)
51
{
52
this->
setText
(s2.
text
());
53
return
*
this
;
54
}
55
56
rlString
&
rlString::operator+
(
const
char
*s2)
57
{
58
this->
cat
(s2);
59
return
*
this
;
60
}
61
62
rlString
&
rlString::operator+
(
rlString
&s2)
63
{
64
this->
cat
(s2.
text
());
65
return
*
this
;
66
}
67
68
rlString
&
rlString::operator+=
(
const
char
*s2)
69
{
70
this->
cat
(s2);
71
return
*
this
;
72
}
73
74
rlString
&
rlString::operator+=
(
rlString
&s2)
75
{
76
this->
cat
(s2.
text
());
77
return
*
this
;
78
}
79
80
int
rlString::operator==
(
const
char
*s2)
81
{
82
if
(strcmp(
txt
,s2) == 0)
return
1;
83
return
0;
84
}
85
86
int
rlString::operator==
(
rlString
&s2)
87
{
88
if
(strcmp(
txt
,s2.
text
()) == 0)
return
1;
89
return
0;
90
}
91
92
int
rlString::operator!=
(
const
char
*s2)
93
{
94
if
(strcmp(
txt
,s2) != 0)
return
1;
95
return
0;
96
}
97
98
int
rlString::operator!=
(
rlString
&s2)
99
{
100
if
(strcmp(
txt
,s2.
text
()) != 0)
return
1;
101
return
0;
102
}
103
104
char
*
rlString::text
()
105
{
106
return
txt
;
107
}
108
109
int
rlString::setText
(
const
char
*text)
110
{
111
int
ret = strlen(text);
112
delete
[]
txt
;
113
txt
=
new
char
[ret+1];
114
::strcpy
(
txt
, text);
115
return
ret;
116
}
117
118
int
rlString::printf
(
const
char
*format, ...)
119
{
120
int
ret;
121
char
mystring[
rl_PRINTF_LENGTH
];
// should be big enough
122
123
va_list ap;
124
va_start(ap,format);
125
ret =
rlvsnprintf
(mystring,
rl_PRINTF_LENGTH
- 1, format, ap);
126
va_end(ap);
127
if
(ret < 0)
return
ret;
128
delete
[]
txt
;
129
txt
=
new
char
[strlen(mystring)+1];
130
::strcpy
(
txt
, mystring);
131
return
ret;
132
}
133
134
int
rlString::strcpy
(
const
char
*text)
135
{
136
char
*cptr =
txt
;
137
int
len = strlen(text);
138
txt
=
new
char
[len+1];
139
::strcpy
(
txt
, text);
140
delete
[] cptr;
141
return
len;
142
}
143
144
int
rlString::cat
(
const
char
*text)
145
{
146
char
*cptr =
txt
;
147
int
len = strlen(
txt
) + strlen(text);
148
txt
=
new
char
[len+1];
149
::strcpy
(
txt
, cptr);
150
::strcat(
txt
, text);
151
delete
[] cptr;
152
return
len;
153
}
154
155
char
*
rlString::strstr
(
const
char
*substring)
156
{
157
if
(substring == NULL)
return
NULL;
158
return ::strstr(
txt
,substring);
159
}
160
161
int
rlString::upper
()
162
{
163
return ::rlupper
(
txt
);
164
}
165
166
int
rlString::lower
()
167
{
168
return ::rllower
(
txt
);
169
}
170
171
int
rlString::startsWith
(
const
char
*startstr)
172
{
173
return ::rlStartsWith
(
txt
,startstr);
174
}
175
176
int
rlString::strnocasecmp
(
const
char
*other)
177
{
178
rlString
my,o;
179
my.
setText
(
txt
);
180
my.
lower
();
181
o.
setText
(other);
182
o.
lower
();
183
return ::strcmp(my.
text
(),o.
text
());
184
}
185
186
int
rlString::strnnocasecmp
(
const
char
*other,
int
n)
187
{
188
rlString
my,o;
189
my.
setText
(
txt
);
190
my.
lower
();
191
o.
setText
(other);
192
o.
lower
();
193
return ::strncmp(my.
text
(),o.
text
(),n);
194
}
195
196
char
*
rlString::strchr
(
int
c)
197
{
198
return ::strchr(
txt
,c);
199
}
200
201
char
*
rlString::strrchr
(
int
c)
202
{
203
return ::strrchr(
txt
,c);
204
}
205
206
int
rlString::removeQuotas
(
char
q)
207
{
208
char
c;
209
int
state=0, inquotas=0, j=0;
210
int
len = strlen(
txt
);
211
212
for
(
int
i=0;i<len;i++)
213
{
214
c =
txt
[i];
215
switch
(state)
216
{
217
case
0:
//START
218
if
(c==q)
219
{
220
state=1;
221
inquotas=1;
222
break
;
223
}
224
state=1;
225
case
1:
// BODY
226
if
(inquotas==1)
227
{
228
if
(c==q)
229
{
230
inquotas=0;
231
break
;
232
}
233
}
234
txt
[j++]=c;
235
break
;
236
default
:
237
break
;
238
}
239
}
240
txt
[j++]=0;
241
return
j;
242
}
243
Generated by
1.8.2