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