Added debugger documentation to reference guide and user guide
[deliverable/titan.core.git] / xsdconvert / Mstring.cc
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Godar, Marton
11 * Raduly, Csaba
12 * Szabo, Bence Janos
13 *
14 ******************************************************************************/
15 #include "../common/dbgnew.hh"
16 // dbgnew must come before Mstring.hh which includes common/memory.hh
17 #include "Mstring.hh"
18
19 #include <string.h>
20 #include <ctype.h>
21 #include <stdio.h>
22 #include <stdlib.h> // only for abort
23
24 const Mstring empty_string;
25
26 Mstring::Mstring()
27 : text(memptystr()) {
28 }
29
30 Mstring::Mstring(const Mstring & other)
31 : text(mcopystr(other.text)) {
32 }
33
34 Mstring::Mstring(const char * s)
35 : text(mcopystr(s)) {
36 }
37
38 Mstring::Mstring(size_t len, const char *s)
39 : text((expstring_t) Malloc(len + 1)) {
40 memcpy(text, s, len);
41 text[len] = 0;
42 }
43
44 Mstring::Mstring(char c)
45 : text(memptystr()) {
46 text = mputc(text, c);
47 }
48
49 Mstring::~Mstring() {
50 Free(text);
51 }
52
53 bool Mstring::empty() const {
54 return mstrlen(text) == 0;
55 }
56
57 size_t Mstring::size() const {
58 return mstrlen(text);
59 }
60
61 void Mstring::clear() {
62 Free(text);
63 text = memptystr();
64 }
65
66 const char * Mstring::c_str() const {
67 return text;
68 }
69
70 void Mstring::eraseChar(size_t pos) {
71 Mstring temp;
72 for (size_t i = 0; i != size(); ++i)
73 if (i != pos) temp += text[i];
74 Free(text);
75 text = mcopystr(temp.text);
76 }
77
78 void Mstring::insertChar(size_t pos, char c) {
79 Mstring temp;
80 for (size_t i = 0; i != size(); ++i)
81 if (i == pos) {
82 temp += c;
83 temp += text[i];
84 } else temp += text[i];
85 Free(text);
86 text = mcopystr(temp.text);
87 }
88
89 bool Mstring::isFound(const Mstring & s) {
90 return strstr(text, s.text);
91 }
92
93 bool Mstring::isFound(const char * s) {
94 return strstr(text, s);
95 }
96
97 bool Mstring::isFound(char c) {
98 return strchr(text, c);
99 }
100
101 char * Mstring::foundAt(const char * s) {
102 return strstr(text, s);
103 }
104
105 void Mstring::setCapitalized() {
106 text[0] = toupper(text[0]);
107 }
108
109 void Mstring::setUncapitalized() {
110 text[0] = tolower(text[0]);
111 }
112
113 Mstring Mstring::getPrefix(const char delimiter) const {
114 Mstring result;
115 char * pos = strchr(text, delimiter);
116 if (pos != NULL) for (int i = 0; text + i != pos; ++i) result += text[i];
117 return result;
118 }
119
120 Mstring Mstring::getValueWithoutPrefix(const char delimiter) const {
121 char * pos = strrchr(text, delimiter);
122 if (pos != NULL) return Mstring(pos + 1);
123 else return *this;
124 }
125
126 void Mstring::removeWSfromBegin() {
127 size_t i = 0;
128 size_t s = mstrlen(text);
129 for (; i < s; ++i)
130 if (!isspace((const unsigned char) text[i])) break;
131 memmove(text, text + i, s - i);
132 text = mtruncstr(text, s - i);
133 }
134
135 void Mstring::removeWSfromEnd() {
136 int i = mstrlen(text);
137 for (; i > 0; --i)
138 if (!isspace((const unsigned char) text[i - 1])) break;
139 text = mtruncstr(text, i);
140 }
141
142 char & Mstring::operator[](size_t pos) {
143 size_t s = mstrlen(text);
144 if (pos < s)
145 return text[pos];
146 else {
147 fputs("String index overflow\n", stderr);
148 abort();
149 }
150 }
151
152 const char & Mstring::operator[](size_t pos) const {
153 size_t s = mstrlen(text);
154 if (pos < s)
155 return text[pos];
156 else {
157 fputs("String index overflow\n", stderr);
158 abort();
159 }
160 }
161
162 Mstring & Mstring::operator=(const Mstring & other) {
163 if (&other != this) {
164 Free(text);
165 text = mcopystr(other.text);
166 }
167 return *this;
168 }
169
170 Mstring & Mstring::operator=(const char * s) {
171 Free(text);
172 text = mcopystr(s);
173 return *this;
174 }
175
176 Mstring & Mstring::operator=(char c) {
177 Free(text);
178 text = memptystr();
179 text = mputc(text, c);
180 return *this;
181 }
182
183 Mstring & Mstring::operator+=(const Mstring & other) {
184 text = mputstr(text, other.text);
185 return *this;
186 }
187
188 Mstring & Mstring::operator+=(const char * s) {
189 text = mputstr(text, s);
190 return *this;
191 }
192
193 Mstring & Mstring::operator+=(char c) {
194 text = mputc(text, c);
195 return *this;
196 }
197
198 const Mstring operator+(const Mstring & lhs, const Mstring & rhs) {
199 return Mstring(lhs) += rhs;
200 }
201
202 const Mstring operator+(const char * lhs, const Mstring & rhs) {
203 return Mstring(lhs) += rhs;
204 }
205
206 const Mstring operator+(char lhs, const Mstring & rhs) {
207 return Mstring(lhs) += rhs;
208 }
209
210 const Mstring operator+(const Mstring & lhs, const char * rhs) {
211 return Mstring(lhs) += rhs;
212 }
213
214 const Mstring operator+(const Mstring & lhs, char rhs) {
215 return Mstring(lhs) += rhs;
216 }
217
218 bool operator==(const Mstring & lhs, const Mstring & rhs) {
219 if (strcmp(lhs.text, rhs.text) == 0) // they are equal
220 return true;
221 else
222 return false;
223 }
224
225 bool operator==(const char * lhs, const Mstring & rhs) {
226 if (strcmp(lhs, rhs.text) == 0) // they are equal
227 return true;
228 else
229 return false;
230 }
231
232 bool operator==(const Mstring & lhs, const char * rhs) {
233 if (strcmp(lhs.text, rhs) == 0) // they are equal
234 return true;
235 else
236 return false;
237 }
238
239 bool operator!=(const Mstring & lhs, const Mstring & rhs) {
240 if (strcmp(lhs.text, rhs.text) != 0) // they are NOT equal
241 return true;
242 else
243 return false;
244 }
245
246 bool operator!=(const char * lhs, const Mstring & rhs) {
247 if (strcmp(lhs, rhs.text) != 0) // they are NOT equal
248 return true;
249 else
250 return false;
251 }
252
253 bool operator!=(const Mstring & lhs, const char * rhs) {
254 if (strcmp(lhs.text, rhs) != 0) // they are NOT equal
255 return true;
256 else
257 return false;
258 }
259
260 bool operator<(const Mstring & lhs, const Mstring & rhs) {
261 if (strcmp(lhs.text, rhs.text) < 0)
262 return true;
263 else
264 return false;
265 }
266
267 bool operator<(const char * lhs, const Mstring & rhs) {
268 if (strcmp(lhs, rhs.text) < 0)
269 return true;
270 else
271 return false;
272 }
273
274 bool operator<(const Mstring & lhs, const char * rhs) {
275 if (strcmp(lhs.text, rhs) < 0)
276 return true;
277 else
278 return false;
279 }
280
281 bool operator>(const Mstring & lhs, const Mstring & rhs) {
282 if (strcmp(lhs.text, rhs.text) > 0)
283 return true;
284 else
285 return false;
286 }
287
288 bool operator>(const char * lhs, const Mstring & rhs) {
289 if (strcmp(lhs, rhs.text) > 0)
290 return true;
291 else
292 return false;
293 }
294
295 bool operator>(const Mstring & lhs, const char * rhs) {
296 if (strcmp(lhs.text, rhs) > 0)
297 return true;
298 else
299 return false;
300 }
301
302 bool operator<=(const Mstring & lhs, const Mstring & rhs) {
303 if (strcmp(lhs.text, rhs.text) <= 0)
304 return true;
305 else
306 return false;
307 }
308
309 bool operator<=(const char * lhs, const Mstring & rhs) {
310 if (strcmp(lhs, rhs.text) <= 0)
311 return true;
312 else
313 return false;
314 }
315
316 bool operator<=(const Mstring & lhs, const char * rhs) {
317 if (strcmp(lhs.text, rhs) <= 0)
318 return true;
319 else
320 return false;
321 }
322
323 bool operator>=(const Mstring & lhs, const Mstring & rhs) {
324 if (strcmp(lhs.text, rhs.text) >= 0)
325 return true;
326 else
327 return false;
328 }
329
330 bool operator>=(const char * lhs, const Mstring & rhs) {
331 if (strcmp(lhs, rhs.text) >= 0)
332 return true;
333 else
334 return false;
335 }
336
337 bool operator>=(const Mstring & lhs, const char * rhs) {
338 if (strcmp(lhs.text, rhs) >= 0)
339 return true;
340 else
341 return false;
342 }
This page took 0.038947 seconds and 5 git commands to generate.