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
14 ******************************************************************************/
15 #include "../common/dbgnew.hh"
16 // dbgnew must come before Mstring.hh which includes common/memory.hh
22 #include <stdlib.h> // only for abort
24 const Mstring empty_string
;
30 Mstring::Mstring(const Mstring
& other
)
31 : text(mcopystr(other
.text
)) {
34 Mstring::Mstring(const char * s
)
38 Mstring::Mstring(size_t len
, const char *s
)
39 : text((expstring_t
) Malloc(len
+ 1)) {
44 Mstring::Mstring(char c
)
46 text
= mputc(text
, c
);
53 bool Mstring::empty() const {
54 return mstrlen(text
) == 0;
57 size_t Mstring::size() const {
61 void Mstring::clear() {
66 const char * Mstring::c_str() const {
70 void Mstring::eraseChar(size_t pos
) {
72 for (size_t i
= 0; i
!= size(); ++i
)
73 if (i
!= pos
) temp
+= text
[i
];
75 text
= mcopystr(temp
.text
);
78 void Mstring::insertChar(size_t pos
, char c
) {
80 for (size_t i
= 0; i
!= size(); ++i
)
84 } else temp
+= text
[i
];
86 text
= mcopystr(temp
.text
);
89 bool Mstring::isFound(const Mstring
& s
) {
90 return strstr(text
, s
.text
);
93 bool Mstring::isFound(const char * s
) {
94 return strstr(text
, s
);
97 bool Mstring::isFound(char c
) {
98 return strchr(text
, c
);
101 char * Mstring::foundAt(const char * s
) {
102 return strstr(text
, s
);
105 void Mstring::setCapitalized() {
106 text
[0] = toupper(text
[0]);
109 void Mstring::setUncapitalized() {
110 text
[0] = tolower(text
[0]);
113 Mstring
Mstring::getPrefix(const char delimiter
) const {
115 char * pos
= strchr(text
, delimiter
);
116 if (pos
!= NULL
) for (int i
= 0; text
+ i
!= pos
; ++i
) result
+= text
[i
];
120 Mstring
Mstring::getValueWithoutPrefix(const char delimiter
) const {
121 char * pos
= strrchr(text
, delimiter
);
122 if (pos
!= NULL
) return Mstring(pos
+ 1);
126 void Mstring::removeWSfromBegin() {
128 size_t s
= mstrlen(text
);
130 if (!isspace((const unsigned char) text
[i
])) break;
131 memmove(text
, text
+ i
, s
- i
);
132 text
= mtruncstr(text
, s
- i
);
135 void Mstring::removeWSfromEnd() {
136 int i
= mstrlen(text
);
138 if (!isspace((const unsigned char) text
[i
- 1])) break;
139 text
= mtruncstr(text
, i
);
142 char & Mstring::operator[](size_t pos
) {
143 size_t s
= mstrlen(text
);
147 fputs("String index overflow\n", stderr
);
152 const char & Mstring::operator[](size_t pos
) const {
153 size_t s
= mstrlen(text
);
157 fputs("String index overflow\n", stderr
);
162 Mstring
& Mstring::operator=(const Mstring
& other
) {
163 if (&other
!= this) {
165 text
= mcopystr(other
.text
);
170 Mstring
& Mstring::operator=(const char * s
) {
176 Mstring
& Mstring::operator=(char c
) {
179 text
= mputc(text
, c
);
183 Mstring
& Mstring::operator+=(const Mstring
& other
) {
184 text
= mputstr(text
, other
.text
);
188 Mstring
& Mstring::operator+=(const char * s
) {
189 text
= mputstr(text
, s
);
193 Mstring
& Mstring::operator+=(char c
) {
194 text
= mputc(text
, c
);
198 const Mstring
operator+(const Mstring
& lhs
, const Mstring
& rhs
) {
199 return Mstring(lhs
) += rhs
;
202 const Mstring
operator+(const char * lhs
, const Mstring
& rhs
) {
203 return Mstring(lhs
) += rhs
;
206 const Mstring
operator+(char lhs
, const Mstring
& rhs
) {
207 return Mstring(lhs
) += rhs
;
210 const Mstring
operator+(const Mstring
& lhs
, const char * rhs
) {
211 return Mstring(lhs
) += rhs
;
214 const Mstring
operator+(const Mstring
& lhs
, char rhs
) {
215 return Mstring(lhs
) += rhs
;
218 bool operator==(const Mstring
& lhs
, const Mstring
& rhs
) {
219 if (strcmp(lhs
.text
, rhs
.text
) == 0) // they are equal
225 bool operator==(const char * lhs
, const Mstring
& rhs
) {
226 if (strcmp(lhs
, rhs
.text
) == 0) // they are equal
232 bool operator==(const Mstring
& lhs
, const char * rhs
) {
233 if (strcmp(lhs
.text
, rhs
) == 0) // they are equal
239 bool operator!=(const Mstring
& lhs
, const Mstring
& rhs
) {
240 if (strcmp(lhs
.text
, rhs
.text
) != 0) // they are NOT equal
246 bool operator!=(const char * lhs
, const Mstring
& rhs
) {
247 if (strcmp(lhs
, rhs
.text
) != 0) // they are NOT equal
253 bool operator!=(const Mstring
& lhs
, const char * rhs
) {
254 if (strcmp(lhs
.text
, rhs
) != 0) // they are NOT equal
260 bool operator<(const Mstring
& lhs
, const Mstring
& rhs
) {
261 if (strcmp(lhs
.text
, rhs
.text
) < 0)
267 bool operator<(const char * lhs
, const Mstring
& rhs
) {
268 if (strcmp(lhs
, rhs
.text
) < 0)
274 bool operator<(const Mstring
& lhs
, const char * rhs
) {
275 if (strcmp(lhs
.text
, rhs
) < 0)
281 bool operator>(const Mstring
& lhs
, const Mstring
& rhs
) {
282 if (strcmp(lhs
.text
, rhs
.text
) > 0)
288 bool operator>(const char * lhs
, const Mstring
& rhs
) {
289 if (strcmp(lhs
, rhs
.text
) > 0)
295 bool operator>(const Mstring
& lhs
, const char * rhs
) {
296 if (strcmp(lhs
.text
, rhs
) > 0)
302 bool operator<=(const Mstring
& lhs
, const Mstring
& rhs
) {
303 if (strcmp(lhs
.text
, rhs
.text
) <= 0)
309 bool operator<=(const char * lhs
, const Mstring
& rhs
) {
310 if (strcmp(lhs
, rhs
.text
) <= 0)
316 bool operator<=(const Mstring
& lhs
, const char * rhs
) {
317 if (strcmp(lhs
.text
, rhs
) <= 0)
323 bool operator>=(const Mstring
& lhs
, const Mstring
& rhs
) {
324 if (strcmp(lhs
.text
, rhs
.text
) >= 0)
330 bool operator>=(const char * lhs
, const Mstring
& rhs
) {
331 if (strcmp(lhs
, rhs
.text
) >= 0)
337 bool operator>=(const Mstring
& lhs
, const char * rhs
) {
338 if (strcmp(lhs
.text
, rhs
) >= 0)
This page took 0.038947 seconds and 5 git commands to generate.