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