Merge pull request #17 from BotondBaranyi/master
[deliverable/titan.core.git] / xsdconvert / Mstring.hh
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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#ifndef XSTRING_HH_
9#define XSTRING_HH_
10
11#include "../common/memory.h"
12
3abe9331 13class Mstring {
970ed795
EL
14 expstring_t text;
15
16public:
17 /**
18 * Construct Mstring object
19 */
20
21 /**
22 * Content is initialized to an empty (non-NULL) Mstring via memptystr()
23 */
24 Mstring();
25
26 /**
27 * Content is initialized to a copy of the Mstring object str.
28 */
29 Mstring(const Mstring & str);
30
31 /**
32 * Content is initialized to a copy of the string
33 * formed by the null-terminated character sequence (C string) pointed by s.
34 * The length of the character sequence is determined by the first occurrence of a null character.
35 * If s is NULL, content is initialized to an empty Mstring
36 */
37 explicit Mstring(const char * s);
38
39 /**
40 * Content is initialized to a single character c.
41 */
42 explicit Mstring(char c);
43
44 /** Construct from \a len characters at \a s (may not be null-terminated) */
45 Mstring(size_t len, const char *s);
46
47 /**
48 * Destruct Mstring object
49 */
50 ~Mstring();
51
52 /**
53 * Test if Mstring is empty
54 * true if the Mstring size is 0
55 * false otherwise
56 */
57 bool empty() const;
58
59 /**
60 * Return length of Mstring
61 */
62 size_t size() const;
63
64 /**
65 * The Mstring content is set to an empty Mstring,
66 * erasing any previous content and thus leaving its size at 0 characters.
67 */
68 void clear();
69
70 /**
71 * Generates a null-terminated sequence of characters (c-string)
72 * with the same content as the Mstring object and
73 * returns it as a pointer to an array of characters.
74 */
75 const char * c_str() const;
76
77 /**
78 * The function deletes one character at position pos from the Mstring content
79 * Size is reduced by one
80 */
81 void eraseChar(size_t pos);
82
83 /**
84 * The function inserts one character before position into the Mstring content
85 * Size is increments by one
86 */
87 void insertChar(size_t pos, char c);
88
89 /**
90 * Look for s Mstring content
91 * true if s is found
92 * false otherwise
93 */
94 bool isFound(const Mstring & s);
95
96 /**
97 * Look for s c-string content
98 * true if s is found
99 * false otherwise
100 */
101 bool isFound(const char * s);
102
103 /**
104 * Look for c character content
105 * true if s is found
106 * false otherwise
107 */
108 bool isFound(char c);
109
3abe9331 110 /**
111 * Look for c-string content
112 * and returns a pointer to the first
113 * character where the matching found,
114 * returns null otherwise
115 */
116 char * foundAt(const char * c);
117
970ed795
EL
118 /**
119 * The first character of the Mstring is set to uppercase
120 */
121 void setCapitalized();
122
123 /**
124 * The first character of the Mstring is set to lowercase
125 */
126 void setUncapitalized();
127
128 /**
129 * Creates a new Mstring object
130 * Looks for the first occurence of the give character (delimiter)
131 * If delimiter is found: * the prefix is found in the string *
132 * the content of the new object will be the part before the found char
133 * If delimiter is not found: * the prefix is not found in the string *
134 * the new object will be an empty Mstring
135 */
136 Mstring getPrefix(const char delimiter) const;
137
138 /**
139 * Creates a new Mstring object
140 * Looks for the last occurence of the give character (delimiter)
141 * If delimiter is found: * the prefix is found in the string *
142 * the content of the new object will be the part after the found char
143 * If delimiter is not found: * the prefix is not found in the string *
144 * the new object will be the copy of this Mstring
145 */
146 Mstring getValueWithoutPrefix(const char delimiter) const;
147
148 /**
149 * Remove all whitespace characters (' ', '\n', '\t', '\r')
150 * from the begining or the end of the Mstring content
151 */
152 void removeWSfromBegin();
153 void removeWSfromEnd();
154
155 /**
156 * Get character in string
157 * Returns a reference the character at position pos in the string.
158 */
3abe9331 159 char & operator[](size_t pos);
160 const char & operator[](size_t pos) const;
970ed795
EL
161
162 /**
163 * Mstring assignment
164 * Sets a copy of the argument as the new content for the string object.
165 * The previous content is dropped.
166 */
3abe9331 167 Mstring & operator=(const Mstring & str);
168 Mstring & operator=(const char * s);
169 Mstring & operator=(char c);
170
171 const Mstring * operator*() const {
172 return this;
173 }
970ed795
EL
174
175 /**
176 * Append to Mstring
177 * Appends a copy of the argument to the Mstring content.
178 * The new Mstring content is the content existing in the string object before the call
179 * followed by the content of the argument.
180 */
3abe9331 181 Mstring & operator+=(const Mstring & str);
182 Mstring & operator+=(const char * s);
183 Mstring & operator+=(char c);
970ed795
EL
184
185 /**
186 * String comparison operators
187 * These overloaded global operator functions perform the appropriate comparison operation between lhs and rhs.
188 *
189 */
3abe9331 190 friend bool operator==(const Mstring & lhs, const Mstring & rhs);
191 friend bool operator==(const char * lhs, const Mstring & rhs);
192 friend bool operator==(const Mstring & lhs, const char * rhs);
970ed795 193
3abe9331 194 friend bool operator!=(const Mstring & lhs, const Mstring & rhs);
195 friend bool operator!=(const char * lhs, const Mstring & rhs);
196 friend bool operator!=(const Mstring & lhs, const char * rhs);
970ed795 197
3abe9331 198 friend bool operator<(const Mstring & lhs, const Mstring & rhs);
199 friend bool operator<(const char * lhs, const Mstring & rhs);
200 friend bool operator<(const Mstring & lhs, const char * rhs);
970ed795 201
3abe9331 202 friend bool operator>(const Mstring & lhs, const Mstring & rhs);
203 friend bool operator>(const char * lhs, const Mstring & rhs);
204 friend bool operator>(const Mstring & lhs, const char * rhs);
970ed795 205
3abe9331 206 friend bool operator<=(const Mstring & lhs, const Mstring & rhs);
207 friend bool operator<=(const char * lhs, const Mstring & rhs);
208 friend bool operator<=(const Mstring & lhs, const char * rhs);
970ed795 209
3abe9331 210 friend bool operator>=(const Mstring & lhs, const Mstring & rhs);
211 friend bool operator>=(const char * lhs, const Mstring & rhs);
212 friend bool operator>=(const Mstring & lhs, const char * rhs);
970ed795
EL
213};
214
215/*
216 * Add strings
217 * Returns an Mstring object whose contents are the combination of the content of lhs followed by those of rhs.
218 */
3abe9331 219const Mstring operator+(const Mstring & lhs, const Mstring & rhs);
220const Mstring operator+(const char * lhs, const Mstring & rhs);
221const Mstring operator+(char lhs, const Mstring & rhs);
222const Mstring operator+(const Mstring & lhs, const char * rhs);
223const Mstring operator+(const Mstring & lhs, char rhs);
224
225bool operator==(const Mstring & lhs, const Mstring & rhs);
226bool operator==(const char * lhs, const Mstring & rhs);
227bool operator==(const Mstring & lhs, const char * rhs);
228
229bool operator!=(const Mstring & lhs, const Mstring & rhs);
230bool operator!=(const char * lhs, const Mstring & rhs);
231bool operator!=(const Mstring & lhs, const char * rhs);
232
233bool operator<(const Mstring & lhs, const Mstring & rhs);
234bool operator<(const char * lhs, const Mstring & rhs);
235bool operator<(const Mstring & lhs, const char * rhs);
236
237bool operator>(const Mstring & lhs, const Mstring & rhs);
238bool operator>(const char * lhs, const Mstring & rhs);
239bool operator>(const Mstring & lhs, const char * rhs);
240
241bool operator<=(const Mstring & lhs, const Mstring & rhs);
242bool operator<=(const char * lhs, const Mstring & rhs);
243bool operator<=(const Mstring & lhs, const char * rhs);
244
245bool operator>=(const Mstring & lhs, const Mstring & rhs);
246bool operator>=(const char * lhs, const Mstring & rhs);
247bool operator>=(const Mstring & lhs, const char * rhs);
970ed795
EL
248
249extern const Mstring empty_string;
250
251#endif /* XSTRING_HH_ */
This page took 0.033899 seconds and 5 git commands to generate.