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 ******************************************************************************/
18 #include "../common/memory.h"
25 * Construct Mstring object
29 * Content is initialized to an empty (non-NULL) Mstring via memptystr()
34 * Content is initialized to a copy of the Mstring object str.
36 Mstring(const Mstring & str);
39 * Content is initialized to a copy of the string
40 * formed by the null-terminated character sequence (C string) pointed by s.
41 * The length of the character sequence is determined by the first occurrence of a null character.
42 * If s is NULL, content is initialized to an empty Mstring
44 explicit Mstring(const char * s);
47 * Content is initialized to a single character c.
49 explicit Mstring(char c);
51 /** Construct from \a len characters at \a s (may not be null-terminated) */
52 Mstring(size_t len, const char *s);
55 * Destruct Mstring object
60 * Test if Mstring is empty
61 * true if the Mstring size is 0
67 * Return length of Mstring
72 * The Mstring content is set to an empty Mstring,
73 * erasing any previous content and thus leaving its size at 0 characters.
78 * Generates a null-terminated sequence of characters (c-string)
79 * with the same content as the Mstring object and
80 * returns it as a pointer to an array of characters.
82 const char * c_str() const;
85 * The function deletes one character at position pos from the Mstring content
86 * Size is reduced by one
88 void eraseChar(size_t pos);
91 * The function inserts one character before position into the Mstring content
92 * Size is increments by one
94 void insertChar(size_t pos, char c);
97 * Look for s Mstring content
101 bool isFound(const Mstring & s);
104 * Look for s c-string content
108 bool isFound(const char * s);
111 * Look for c character content
115 bool isFound(char c);
118 * Look for c-string content
119 * and returns a pointer to the first
120 * character where the matching found,
121 * returns null otherwise
123 char * foundAt(const char * c);
126 * The first character of the Mstring is set to uppercase
128 void setCapitalized();
131 * The first character of the Mstring is set to lowercase
133 void setUncapitalized();
136 * Creates a new Mstring object
137 * Looks for the first occurence of the give character (delimiter)
138 * If delimiter is found: * the prefix is found in the string *
139 * the content of the new object will be the part before the found char
140 * If delimiter is not found: * the prefix is not found in the string *
141 * the new object will be an empty Mstring
143 Mstring getPrefix(const char delimiter) const;
146 * Creates a new Mstring object
147 * Looks for the last occurence of the give character (delimiter)
148 * If delimiter is found: * the prefix is found in the string *
149 * the content of the new object will be the part after the found char
150 * If delimiter is not found: * the prefix is not found in the string *
151 * the new object will be the copy of this Mstring
153 Mstring getValueWithoutPrefix(const char delimiter) const;
156 * Remove all whitespace characters (' ', '\n', '\t', '\r')
157 * from the begining or the end of the Mstring content
159 void removeWSfromBegin();
160 void removeWSfromEnd();
163 * Get character in string
164 * Returns a reference the character at position pos in the string.
166 char & operator[](size_t pos);
167 const char & operator[](size_t pos) const;
171 * Sets a copy of the argument as the new content for the string object.
172 * The previous content is dropped.
174 Mstring & operator=(const Mstring & str);
175 Mstring & operator=(const char * s);
176 Mstring & operator=(char c);
178 const Mstring * operator*() const {
184 * Appends a copy of the argument to the Mstring content.
185 * The new Mstring content is the content existing in the string object before the call
186 * followed by the content of the argument.
188 Mstring & operator+=(const Mstring & str);
189 Mstring & operator+=(const char * s);
190 Mstring & operator+=(char c);
193 * String comparison operators
194 * These overloaded global operator functions perform the appropriate comparison operation between lhs and rhs.
197 friend bool operator==(const Mstring & lhs, const Mstring & rhs);
198 friend bool operator==(const char * lhs, const Mstring & rhs);
199 friend bool operator==(const Mstring & lhs, const char * rhs);
201 friend bool operator!=(const Mstring & lhs, const Mstring & rhs);
202 friend bool operator!=(const char * lhs, const Mstring & rhs);
203 friend bool operator!=(const Mstring & lhs, const char * rhs);
205 friend bool operator<(const Mstring & lhs, const Mstring & rhs);
206 friend bool operator<(const char * lhs, const Mstring & rhs);
207 friend bool operator<(const Mstring & lhs, const char * rhs);
209 friend bool operator>(const Mstring & lhs, const Mstring & rhs);
210 friend bool operator>(const char * lhs, const Mstring & rhs);
211 friend bool operator>(const Mstring & lhs, const char * rhs);
213 friend bool operator<=(const Mstring & lhs, const Mstring & rhs);
214 friend bool operator<=(const char * lhs, const Mstring & rhs);
215 friend bool operator<=(const Mstring & lhs, const char * rhs);
217 friend bool operator>=(const Mstring & lhs, const Mstring & rhs);
218 friend bool operator>=(const char * lhs, const Mstring & rhs);
219 friend bool operator>=(const Mstring & lhs, const char * rhs);
224 * Returns an Mstring object whose contents are the combination of the content of lhs followed by those of rhs.
226 const Mstring operator+(const Mstring & lhs, const Mstring & rhs);
227 const Mstring operator+(const char * lhs, const Mstring & rhs);
228 const Mstring operator+(char lhs, const Mstring & rhs);
229 const Mstring operator+(const Mstring & lhs, const char * rhs);
230 const Mstring operator+(const Mstring & lhs, char rhs);
232 bool operator==(const Mstring & lhs, const Mstring & rhs);
233 bool operator==(const char * lhs, const Mstring & rhs);
234 bool operator==(const Mstring & lhs, const char * rhs);
236 bool operator!=(const Mstring & lhs, const Mstring & rhs);
237 bool operator!=(const char * lhs, const Mstring & rhs);
238 bool operator!=(const Mstring & lhs, const char * rhs);
240 bool operator<(const Mstring & lhs, const Mstring & rhs);
241 bool operator<(const char * lhs, const Mstring & rhs);
242 bool operator<(const Mstring & lhs, const char * rhs);
244 bool operator>(const Mstring & lhs, const Mstring & rhs);
245 bool operator>(const char * lhs, const Mstring & rhs);
246 bool operator>(const Mstring & lhs, const char * rhs);
248 bool operator<=(const Mstring & lhs, const Mstring & rhs);
249 bool operator<=(const char * lhs, const Mstring & rhs);
250 bool operator<=(const Mstring & lhs, const char * rhs);
252 bool operator>=(const Mstring & lhs, const Mstring & rhs);
253 bool operator>=(const char * lhs, const Mstring & rhs);
254 bool operator>=(const Mstring & lhs, const char * rhs);
256 extern const Mstring empty_string;
258 #endif /* XSTRING_HH_ */