[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Christian Meyer |
---|
| 24 | * Co-authors: |
---|
| 25 | * Benjamin Grauer |
---|
| 26 | * |
---|
[1791] | 27 | |
---|
[1505] | 28 | // |
---|
| 29 | // splitLine |
---|
| 30 | // STL string tokenizer |
---|
| 31 | // |
---|
| 32 | // Created by Clemens Wacha. |
---|
| 33 | // Version 1.0 |
---|
| 34 | // Copyright (c) 2005 Clemens Wacha. All rights reserved. |
---|
| 35 | // |
---|
[1791] | 36 | |
---|
| 37 | * Extended by Fabian 'x3n' Landau by the SL_PARENTHESES mode. |
---|
[1505] | 38 | */ |
---|
[836] | 39 | |
---|
| 40 | #include "SubString.h" |
---|
[3196] | 41 | #include <cstdio> |
---|
[7327] | 42 | #include "Debug.h" |
---|
[836] | 43 | |
---|
[2171] | 44 | namespace orxonox |
---|
| 45 | { |
---|
[7327] | 46 | const std::string SubString::WhiteSpaces = " \n\t"; |
---|
| 47 | const std::string SubString::WhiteSpacesWithComma = " \n\t,"; |
---|
| 48 | const SubString SubString::NullSubString = SubString(); |
---|
| 49 | |
---|
[2171] | 50 | /** |
---|
[7327] | 51 | @brief Default constructor. |
---|
| 52 | */ |
---|
[2171] | 53 | SubString::SubString() |
---|
| 54 | { |
---|
| 55 | } |
---|
[836] | 56 | |
---|
[2171] | 57 | /** |
---|
[7327] | 58 | @brief Splits a string into multiple tokens. |
---|
| 59 | @param line The line to split |
---|
| 60 | @param delimiters Multiple characters at which to split the line |
---|
| 61 | @param delimiterNeighbours Neighbours of the delimiters that will be erased as well (for example white-spaces) |
---|
| 62 | @param bAllowEmptyEntries If true, empty tokens are also added to the SubString (if there are two delimiters without a char in between) |
---|
| 63 | @param escapeChar The escape character that is used to escape safemode chars (for example if you want to use a quotation mark between two other quotation marks). |
---|
| 64 | @param bRemoveEscapeChar If true, the escape char is removed from the tokens |
---|
| 65 | @param safemodeChar Within these characters splitting won't happen (usually the quotation marks) |
---|
| 66 | @param bRemoveSafemodeChar Removes the safemodeChar from the beginning and the ending of a token |
---|
| 67 | @param openparenthesisChar The beginning of a safemode is marked with this (usually an opening brace) |
---|
| 68 | @param closeparenthesisChar The ending of a safemode is marked with this (usually a closing brace) |
---|
| 69 | @param bRemoveParenthesisChars Removes the parenthesis chars from the beginning and the ending of a token |
---|
| 70 | @param commentChar The comment character (used to ignore the part of the line after the comment char). |
---|
| 71 | */ |
---|
| 72 | SubString::SubString(const std::string& line, |
---|
| 73 | const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, |
---|
| 74 | char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, |
---|
| 75 | char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) |
---|
[2171] | 76 | { |
---|
[7327] | 77 | SubString::splitLine(this->tokens_, this->bTokenInSafemode_, line, delimiters, delimiterNeighbours, bAllowEmptyEntries, escapeChar, bRemoveEscapeChar, safemodeChar, bRemoveSafemodeChar, openparenthesisChar, closeparenthesisChar, bRemoveParenthesisChars, commentChar); |
---|
[2171] | 78 | } |
---|
[836] | 79 | |
---|
[2171] | 80 | /** |
---|
[7327] | 81 | @brief creates a new SubString based on a subset of an other SubString. |
---|
| 82 | @param other The other SubString |
---|
| 83 | @param begin The beginning of the subset |
---|
| 84 | |
---|
| 85 | The subset ranges from the token with index @a begin to the end of the tokens. |
---|
| 86 | If @a begin is greater than the greatest index, the new SubString will be empty. |
---|
| 87 | */ |
---|
| 88 | SubString::SubString(const SubString& other, unsigned int begin) |
---|
[2171] | 89 | { |
---|
[7327] | 90 | for (unsigned int i = begin; i < other.size(); ++i) |
---|
[2171] | 91 | { |
---|
[7327] | 92 | this->tokens_.push_back(other[i]); |
---|
| 93 | this->bTokenInSafemode_.push_back(other.isInSafemode(i)); |
---|
[2171] | 94 | } |
---|
| 95 | } |
---|
[836] | 96 | |
---|
[7327] | 97 | /** |
---|
| 98 | @brief creates a new SubString based on a subset of an other SubString. |
---|
| 99 | @param other The other SubString |
---|
| 100 | @param begin The beginning of the subset |
---|
| 101 | @param end The end of the subset |
---|
[836] | 102 | |
---|
[7327] | 103 | The subset ranges from the token with index @a begin until (but not including) the token with index @a end. |
---|
| 104 | If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. |
---|
| 105 | */ |
---|
| 106 | SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) |
---|
[2171] | 107 | { |
---|
[7327] | 108 | for (unsigned int i = begin; i < std::min(other.size(), end); ++i) |
---|
[2171] | 109 | { |
---|
[7327] | 110 | this->tokens_.push_back(other[i]); |
---|
| 111 | this->bTokenInSafemode_.push_back(other.isInSafemode(i)); |
---|
[2171] | 112 | } |
---|
| 113 | } |
---|
[836] | 114 | |
---|
[2171] | 115 | /** |
---|
[7327] | 116 | @brief Creates a SubString from a count and values set. |
---|
| 117 | @param argc The number of arguments |
---|
| 118 | @param argv An array of pointers to the arguments |
---|
| 119 | */ |
---|
[2171] | 120 | SubString::SubString(unsigned int argc, const char** argv) |
---|
| 121 | { |
---|
| 122 | for(unsigned int i = 0; i < argc; ++i) |
---|
| 123 | { |
---|
[7327] | 124 | this->tokens_.push_back(std::string(argv[i])); |
---|
| 125 | this->bTokenInSafemode_.push_back(false); |
---|
[2171] | 126 | } |
---|
| 127 | } |
---|
[836] | 128 | |
---|
[2171] | 129 | /** |
---|
[7327] | 130 | @brief Destructor |
---|
| 131 | */ |
---|
[2171] | 132 | SubString::~SubString() |
---|
| 133 | { } |
---|
[836] | 134 | |
---|
[2171] | 135 | /** |
---|
[7327] | 136 | @brief Stores the tokens of @a other in this SubString |
---|
| 137 | @return This SubString. |
---|
| 138 | */ |
---|
| 139 | SubString& SubString::operator=(const SubString& other) |
---|
[2171] | 140 | { |
---|
[7327] | 141 | this->tokens_ = other.tokens_; |
---|
| 142 | this->bTokenInSafemode_ = other.bTokenInSafemode_; |
---|
[2171] | 143 | return *this; |
---|
| 144 | } |
---|
[836] | 145 | |
---|
[2171] | 146 | /** |
---|
[7327] | 147 | @brief Compares this SubString to another SubString and returns true if they contain the same values. |
---|
| 148 | */ |
---|
| 149 | bool SubString::operator==(const SubString& other) const |
---|
[2171] | 150 | { |
---|
[7327] | 151 | return ((this->tokens_ == other.tokens_) && (this->bTokenInSafemode_ == other.bTokenInSafemode_)); |
---|
[2171] | 152 | } |
---|
[836] | 153 | |
---|
[2171] | 154 | /** |
---|
[7327] | 155 | @copydoc operator== |
---|
| 156 | */ |
---|
| 157 | bool SubString::compare(const SubString& other) const |
---|
[2171] | 158 | { |
---|
[7327] | 159 | return (*this == other); |
---|
[2171] | 160 | } |
---|
[836] | 161 | |
---|
[2171] | 162 | /** |
---|
[7327] | 163 | @brief Compares this SubString to another SubString and returns true if the first @a length values match. |
---|
| 164 | @param other The other SubString |
---|
| 165 | @param length How many tokens to compare |
---|
| 166 | */ |
---|
| 167 | bool SubString::compare(const SubString& other, unsigned int length) const |
---|
[2171] | 168 | { |
---|
[7327] | 169 | if (length > this->size() || length > other.size()) |
---|
[2171] | 170 | return false; |
---|
[836] | 171 | |
---|
[7327] | 172 | for (unsigned int i = 0; i < length; ++i) |
---|
| 173 | if ((this->tokens_[i] != other.tokens_[i]) || (this->bTokenInSafemode_[i] != other.bTokenInSafemode_[i])) |
---|
[2171] | 174 | return false; |
---|
| 175 | return true; |
---|
| 176 | } |
---|
[836] | 177 | |
---|
[2171] | 178 | /** |
---|
[7327] | 179 | @brief Concatenates the tokens of two SubStrings and returns the resulting new SubString |
---|
| 180 | @return A new SubString that contains the tokens of this and the other SubString |
---|
| 181 | */ |
---|
| 182 | SubString SubString::operator+(const SubString& other) const |
---|
[2171] | 183 | { |
---|
[7327] | 184 | return SubString(*this) += other; |
---|
[2171] | 185 | } |
---|
[836] | 186 | |
---|
[2171] | 187 | /** |
---|
[7327] | 188 | @brief Appends the tokens of @a other to this SubString |
---|
| 189 | @return This SubString |
---|
| 190 | */ |
---|
| 191 | SubString& SubString::operator+=(const SubString& other) |
---|
[2171] | 192 | { |
---|
[7327] | 193 | for (unsigned int i = 0; i < other.size(); ++i) |
---|
[2171] | 194 | { |
---|
[7327] | 195 | this->tokens_.push_back(other[i]); |
---|
| 196 | this->bTokenInSafemode_.push_back(other.isInSafemode(i)); |
---|
[2171] | 197 | } |
---|
| 198 | return *this; |
---|
| 199 | } |
---|
[836] | 200 | |
---|
[2171] | 201 | /** |
---|
[7327] | 202 | @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) |
---|
| 203 | */ |
---|
| 204 | unsigned int SubString::split(const std::string& line, |
---|
| 205 | const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, |
---|
| 206 | char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, |
---|
| 207 | char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) |
---|
[2171] | 208 | { |
---|
[7327] | 209 | this->tokens_.clear(); |
---|
| 210 | this->bTokenInSafemode_.clear(); |
---|
| 211 | SubString::splitLine(this->tokens_, this->bTokenInSafemode_, line, delimiters, delimiterNeighbours, bAllowEmptyEntries, escapeChar, bRemoveEscapeChar, safemodeChar, bRemoveSafemodeChar, openparenthesisChar, closeparenthesisChar, bRemoveParenthesisChars, commentChar); |
---|
| 212 | return this->tokens_.size(); |
---|
[2171] | 213 | } |
---|
[836] | 214 | |
---|
[2171] | 215 | /** |
---|
[7327] | 216 | @brief Joins the tokens of this SubString using the given delimiter and returns a string. |
---|
| 217 | @param delimiter This delimiter will be placed between each two tokens |
---|
| 218 | @return The joined string. |
---|
| 219 | */ |
---|
[2171] | 220 | std::string SubString::join(const std::string& delimiter) const |
---|
| 221 | { |
---|
[7327] | 222 | if (!this->tokens_.empty()) |
---|
[2171] | 223 | { |
---|
[7327] | 224 | std::string retVal = this->tokens_[0]; |
---|
| 225 | for (unsigned int i = 1; i < this->tokens_.size(); ++i) |
---|
| 226 | retVal += delimiter + this->tokens_[i]; |
---|
[2171] | 227 | return retVal; |
---|
| 228 | } |
---|
| 229 | else |
---|
[6417] | 230 | return ""; |
---|
[2171] | 231 | } |
---|
[836] | 232 | |
---|
[7327] | 233 | /** |
---|
| 234 | @brief Creates a subset of this SubString. |
---|
| 235 | @param begin The beginning of the subset |
---|
| 236 | @return A new SubString containing the defined subset. |
---|
[836] | 237 | |
---|
[7327] | 238 | The subset ranges from the token with index @a begin to the end of the tokens. |
---|
| 239 | If @a begin is greater than the greatest index, the new SubString will be empty. |
---|
| 240 | |
---|
| 241 | This function is added for your convenience, and does the same as |
---|
| 242 | SubString::SubString(const SubString& other, unsigned int begin) |
---|
| 243 | */ |
---|
| 244 | SubString SubString::subSet(unsigned int begin) const |
---|
[2171] | 245 | { |
---|
[7327] | 246 | return SubString(*this, begin); |
---|
[2171] | 247 | } |
---|
[836] | 248 | |
---|
[7327] | 249 | /** |
---|
| 250 | @brief Creates a subset of this SubString. |
---|
| 251 | @param begin The beginning of the subset |
---|
| 252 | @param end The ending of the subset |
---|
| 253 | @return A new SubString containing the defined subset. |
---|
[836] | 254 | |
---|
[7327] | 255 | The subset ranges from the token with index @a begin until (but not including) the token with index @a end. |
---|
| 256 | If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. |
---|
| 257 | |
---|
| 258 | This function is added for your convenience, and does the same as |
---|
| 259 | SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) |
---|
| 260 | */ |
---|
| 261 | SubString SubString::subSet(unsigned int begin, unsigned int end) const |
---|
[2171] | 262 | { |
---|
[7327] | 263 | return SubString(*this, begin, end); |
---|
[2171] | 264 | } |
---|
[836] | 265 | |
---|
[7327] | 266 | /** |
---|
| 267 | @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) |
---|
| 268 | @param tokens The array, where the splitted strings will be stored in |
---|
| 269 | @param bTokenInSafemode A vector wich stores for each character of the string if it is in safemode or not |
---|
| 270 | @param start_state The internal state of the parser |
---|
[836] | 271 | |
---|
[7327] | 272 | This is the actual splitting algorithm from Clemens Wacha. |
---|
| 273 | Supports delimiters, escape characters, ignores special characters between safemodeChar and between commentChar and line end "\n". |
---|
| 274 | |
---|
| 275 | Extended by Orxonox to support parenthesis as additional safe-mode. |
---|
| 276 | */ |
---|
[2171] | 277 | SubString::SPLIT_LINE_STATE |
---|
[7327] | 278 | SubString::splitLine(std::vector<std::string>& tokens, |
---|
| 279 | std::vector<bool>& bTokenInSafemode, |
---|
[2171] | 280 | const std::string& line, |
---|
| 281 | const std::string& delimiters, |
---|
| 282 | const std::string& delimiterNeighbours, |
---|
[7327] | 283 | bool bAllowEmptyEntries, |
---|
| 284 | char escapeChar, |
---|
| 285 | bool bRemoveEscapeChar, |
---|
| 286 | char safemodeChar, |
---|
| 287 | bool bRemoveSafemodeChar, |
---|
| 288 | char openparenthesisChar, |
---|
| 289 | char closeparenthesisChar, |
---|
| 290 | bool bRemoveParenthesisChars, |
---|
| 291 | char commentChar, |
---|
[2171] | 292 | SPLIT_LINE_STATE start_state) |
---|
| 293 | { |
---|
| 294 | SPLIT_LINE_STATE state = start_state; |
---|
| 295 | unsigned int i = 0; |
---|
| 296 | unsigned int fallBackNeighbours = 0; |
---|
[836] | 297 | |
---|
[2171] | 298 | std::string token; |
---|
| 299 | bool inSafemode = false; |
---|
[836] | 300 | |
---|
[7327] | 301 | if(start_state != SL_NORMAL && tokens.size() > 0) |
---|
[836] | 302 | { |
---|
[7327] | 303 | token = tokens[tokens.size()-1]; |
---|
| 304 | tokens.pop_back(); |
---|
[836] | 305 | } |
---|
[7327] | 306 | if(start_state != SL_NORMAL && bTokenInSafemode.size() > 0) |
---|
[836] | 307 | { |
---|
[7327] | 308 | inSafemode = bTokenInSafemode[bTokenInSafemode.size()-1]; |
---|
| 309 | bTokenInSafemode.pop_back(); |
---|
[836] | 310 | } |
---|
[2171] | 311 | |
---|
| 312 | while(i < line.size()) |
---|
[1505] | 313 | { |
---|
[2171] | 314 | switch(state) |
---|
[836] | 315 | { |
---|
[2171] | 316 | case SL_NORMAL: |
---|
[7327] | 317 | if(line[i] == escapeChar) |
---|
[2171] | 318 | { |
---|
| 319 | state = SL_ESCAPE; |
---|
[7327] | 320 | if (!bRemoveEscapeChar) |
---|
[2171] | 321 | token += line[i]; |
---|
| 322 | } |
---|
[7327] | 323 | else if(line[i] == safemodeChar) |
---|
[2171] | 324 | { |
---|
| 325 | state = SL_SAFEMODE; |
---|
| 326 | inSafemode = true; |
---|
[7327] | 327 | if (!bRemoveSafemodeChar) |
---|
[2171] | 328 | token += line[i]; |
---|
| 329 | } |
---|
[7327] | 330 | else if(line[i] == openparenthesisChar) |
---|
[2171] | 331 | { |
---|
| 332 | state = SL_PARENTHESES; |
---|
| 333 | inSafemode = true; |
---|
[7327] | 334 | if (!bRemoveParenthesisChars) |
---|
[2171] | 335 | token += line[i]; |
---|
| 336 | } |
---|
[7327] | 337 | else if(line[i] == commentChar) |
---|
[2171] | 338 | { |
---|
| 339 | if (fallBackNeighbours > 0) |
---|
| 340 | token = token.substr(0, token.size() - fallBackNeighbours); |
---|
[7327] | 341 | // FINISH |
---|
| 342 | if(bAllowEmptyEntries || token.size() > 0) |
---|
[2171] | 343 | { |
---|
[7327] | 344 | tokens.push_back(token); |
---|
[2171] | 345 | token.clear(); |
---|
[7327] | 346 | bTokenInSafemode.push_back(inSafemode); |
---|
[2171] | 347 | inSafemode = false; |
---|
| 348 | } |
---|
| 349 | token += line[i]; // EAT |
---|
| 350 | state = SL_COMMENT; |
---|
| 351 | } |
---|
| 352 | else if(delimiters.find(line[i]) != std::string::npos) |
---|
| 353 | { |
---|
| 354 | // line[i] is a delimiter |
---|
| 355 | if (fallBackNeighbours > 0) |
---|
| 356 | token = token.substr(0, token.size() - fallBackNeighbours); |
---|
[7327] | 357 | // FINISH |
---|
| 358 | if(bAllowEmptyEntries || token.size() > 0) |
---|
[2171] | 359 | { |
---|
[7327] | 360 | tokens.push_back(token); |
---|
[2171] | 361 | token.clear(); |
---|
[7327] | 362 | bTokenInSafemode.push_back(inSafemode); |
---|
[2171] | 363 | inSafemode = false; |
---|
| 364 | } |
---|
| 365 | state = SL_NORMAL; |
---|
| 366 | } |
---|
| 367 | else |
---|
| 368 | { |
---|
| 369 | if (delimiterNeighbours.find(line[i]) != std::string::npos) |
---|
| 370 | { |
---|
| 371 | if (token.size() > 0) |
---|
| 372 | ++fallBackNeighbours; |
---|
| 373 | else |
---|
| 374 | { |
---|
[7327] | 375 | ++i; |
---|
[2171] | 376 | continue; |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | else |
---|
| 380 | fallBackNeighbours = 0; |
---|
| 381 | token += line[i]; // EAT |
---|
| 382 | } |
---|
| 383 | break; |
---|
| 384 | case SL_ESCAPE: |
---|
[7327] | 385 | if (!bRemoveSafemodeChar) |
---|
[2171] | 386 | token += line[i]; |
---|
| 387 | else |
---|
| 388 | { |
---|
| 389 | if(line[i] == 'n') token += '\n'; |
---|
| 390 | else if(line[i] == 't') token += '\t'; |
---|
| 391 | else if(line[i] == 'v') token += '\v'; |
---|
| 392 | else if(line[i] == 'b') token += '\b'; |
---|
| 393 | else if(line[i] == 'r') token += '\r'; |
---|
| 394 | else if(line[i] == 'f') token += '\f'; |
---|
| 395 | else if(line[i] == 'a') token += '\a'; |
---|
| 396 | else if(line[i] == '?') token += '\?'; |
---|
| 397 | else token += line[i]; // EAT |
---|
| 398 | } |
---|
| 399 | state = SL_NORMAL; |
---|
| 400 | break; |
---|
| 401 | case SL_SAFEMODE: |
---|
[7327] | 402 | if(line[i] == safemodeChar) |
---|
[2171] | 403 | { |
---|
| 404 | state = SL_NORMAL; |
---|
[7327] | 405 | if (!bRemoveSafemodeChar) |
---|
[2171] | 406 | token += line[i]; |
---|
| 407 | } |
---|
[7327] | 408 | else if(line[i] == escapeChar) |
---|
[2171] | 409 | { |
---|
| 410 | state = SL_SAFEESCAPE; |
---|
| 411 | } |
---|
| 412 | else |
---|
| 413 | { |
---|
| 414 | token += line[i]; // EAT |
---|
| 415 | } |
---|
| 416 | break; |
---|
[1505] | 417 | |
---|
[2171] | 418 | case SL_SAFEESCAPE: |
---|
| 419 | if(line[i] == 'n') token += '\n'; |
---|
| 420 | else if(line[i] == 't') token += '\t'; |
---|
| 421 | else if(line[i] == 'v') token += '\v'; |
---|
| 422 | else if(line[i] == 'b') token += '\b'; |
---|
| 423 | else if(line[i] == 'r') token += '\r'; |
---|
| 424 | else if(line[i] == 'f') token += '\f'; |
---|
| 425 | else if(line[i] == 'a') token += '\a'; |
---|
| 426 | else if(line[i] == '?') token += '\?'; |
---|
| 427 | else token += line[i]; // EAT |
---|
| 428 | state = SL_SAFEMODE; |
---|
| 429 | break; |
---|
[836] | 430 | |
---|
[2171] | 431 | case SL_PARENTHESES: |
---|
[7327] | 432 | if(line[i] == closeparenthesisChar) |
---|
[2171] | 433 | { |
---|
| 434 | state = SL_NORMAL; |
---|
[7327] | 435 | if (!bRemoveParenthesisChars) |
---|
[2171] | 436 | token += line[i]; |
---|
| 437 | } |
---|
[7327] | 438 | else if(line[i] == escapeChar) |
---|
[2171] | 439 | { |
---|
| 440 | state = SL_PARENTHESESESCAPE; |
---|
| 441 | } |
---|
| 442 | else |
---|
| 443 | { |
---|
| 444 | token += line[i]; // EAT |
---|
| 445 | } |
---|
| 446 | break; |
---|
| 447 | |
---|
| 448 | case SL_PARENTHESESESCAPE: |
---|
| 449 | if(line[i] == 'n') token += '\n'; |
---|
| 450 | else if(line[i] == 't') token += '\t'; |
---|
| 451 | else if(line[i] == 'v') token += '\v'; |
---|
| 452 | else if(line[i] == 'b') token += '\b'; |
---|
| 453 | else if(line[i] == 'r') token += '\r'; |
---|
| 454 | else if(line[i] == 'f') token += '\f'; |
---|
| 455 | else if(line[i] == 'a') token += '\a'; |
---|
| 456 | else if(line[i] == '?') token += '\?'; |
---|
| 457 | else token += line[i]; // EAT |
---|
| 458 | state = SL_PARENTHESES; |
---|
| 459 | break; |
---|
| 460 | |
---|
| 461 | case SL_COMMENT: |
---|
| 462 | if(line[i] == '\n') |
---|
| 463 | { |
---|
[7327] | 464 | // FINISH |
---|
[2171] | 465 | if(token.size() > 0) |
---|
| 466 | { |
---|
[7327] | 467 | tokens.push_back(token); |
---|
[2171] | 468 | token.clear(); |
---|
[7327] | 469 | bTokenInSafemode.push_back(inSafemode); |
---|
[2171] | 470 | inSafemode = false; |
---|
| 471 | } |
---|
| 472 | state = SL_NORMAL; |
---|
| 473 | } |
---|
| 474 | else |
---|
| 475 | { |
---|
| 476 | token += line[i]; // EAT |
---|
| 477 | } |
---|
| 478 | break; |
---|
| 479 | |
---|
| 480 | default: |
---|
| 481 | // nothing |
---|
| 482 | break; |
---|
| 483 | } |
---|
[7327] | 484 | ++i; |
---|
[1505] | 485 | } |
---|
| 486 | |
---|
[7327] | 487 | // FINISH |
---|
[2171] | 488 | if (fallBackNeighbours > 0) |
---|
| 489 | token = token.substr(0, token.size() - fallBackNeighbours); |
---|
[7327] | 490 | if(bAllowEmptyEntries || token.size() > 0) |
---|
[836] | 491 | { |
---|
[7327] | 492 | tokens.push_back(token); |
---|
[836] | 493 | token.clear(); |
---|
[7327] | 494 | bTokenInSafemode.push_back(inSafemode); |
---|
[1505] | 495 | inSafemode = false; |
---|
[836] | 496 | } |
---|
[2171] | 497 | return(state); |
---|
[836] | 498 | } |
---|
| 499 | |
---|
[2171] | 500 | /** |
---|
[7327] | 501 | @brief Some nice debug information about this SubString. |
---|
| 502 | */ |
---|
[2171] | 503 | void SubString::debug() const |
---|
| 504 | { |
---|
[7327] | 505 | COUT(0) << "Substring-information::count=" << this->tokens_.size() << " ::"; |
---|
| 506 | for (unsigned int i = 0; i < this->tokens_.size(); ++i) |
---|
| 507 | COUT(0) << "s" << i << "='" << this->tokens_[i].c_str() << "'::"; |
---|
| 508 | COUT(0) << std::endl; |
---|
[2171] | 509 | } |
---|
[836] | 510 | } |
---|