[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 | |
---|
[7352] | 40 | /** |
---|
| 41 | @file |
---|
| 42 | @brief Implementation of the SubString class. |
---|
| 43 | */ |
---|
| 44 | |
---|
[836] | 45 | #include "SubString.h" |
---|
[3196] | 46 | #include <cstdio> |
---|
[7327] | 47 | #include "Debug.h" |
---|
[836] | 48 | |
---|
[2171] | 49 | namespace orxonox |
---|
| 50 | { |
---|
[7327] | 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 | /** |
---|
[7327] | 56 | @brief Default constructor. |
---|
| 57 | */ |
---|
[2171] | 58 | SubString::SubString() |
---|
| 59 | { |
---|
| 60 | } |
---|
[836] | 61 | |
---|
[2171] | 62 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 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 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 95 | for (unsigned int i = begin; i < other.size(); ++i) |
---|
[2171] | 96 | { |
---|
[7327] | 97 | this->tokens_.push_back(other[i]); |
---|
| 98 | this->bTokenInSafemode_.push_back(other.isInSafemode(i)); |
---|
[2171] | 99 | } |
---|
| 100 | } |
---|
[836] | 101 | |
---|
[7327] | 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 | |
---|
[7327] | 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 | { |
---|
[7327] | 113 | for (unsigned int i = begin; i < std::min(other.size(), end); ++i) |
---|
[2171] | 114 | { |
---|
[7327] | 115 | this->tokens_.push_back(other[i]); |
---|
| 116 | this->bTokenInSafemode_.push_back(other.isInSafemode(i)); |
---|
[2171] | 117 | } |
---|
| 118 | } |
---|
[836] | 119 | |
---|
[2171] | 120 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 129 | this->tokens_.push_back(std::string(argv[i])); |
---|
| 130 | this->bTokenInSafemode_.push_back(false); |
---|
[2171] | 131 | } |
---|
| 132 | } |
---|
[836] | 133 | |
---|
[2171] | 134 | /** |
---|
[7327] | 135 | @brief Destructor |
---|
| 136 | */ |
---|
[2171] | 137 | SubString::~SubString() |
---|
| 138 | { } |
---|
[836] | 139 | |
---|
[2171] | 140 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 146 | this->tokens_ = other.tokens_; |
---|
| 147 | this->bTokenInSafemode_ = other.bTokenInSafemode_; |
---|
[2171] | 148 | return *this; |
---|
| 149 | } |
---|
[836] | 150 | |
---|
[2171] | 151 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 156 | return ((this->tokens_ == other.tokens_) && (this->bTokenInSafemode_ == other.bTokenInSafemode_)); |
---|
[2171] | 157 | } |
---|
[836] | 158 | |
---|
[2171] | 159 | /** |
---|
[7327] | 160 | @copydoc operator== |
---|
| 161 | */ |
---|
| 162 | bool SubString::compare(const SubString& other) const |
---|
[2171] | 163 | { |
---|
[7327] | 164 | return (*this == other); |
---|
[2171] | 165 | } |
---|
[836] | 166 | |
---|
[2171] | 167 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 174 | if (length > this->size() || length > other.size()) |
---|
[2171] | 175 | return false; |
---|
[836] | 176 | |
---|
[7327] | 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 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 189 | return SubString(*this) += other; |
---|
[2171] | 190 | } |
---|
[836] | 191 | |
---|
[2171] | 192 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 198 | for (unsigned int i = 0; i < other.size(); ++i) |
---|
[2171] | 199 | { |
---|
[7327] | 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 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 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 | /** |
---|
[7327] | 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 | { |
---|
[7327] | 227 | if (!this->tokens_.empty()) |
---|
[2171] | 228 | { |
---|
[7327] | 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 | |
---|
[7327] | 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 | |
---|
[7327] | 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 | { |
---|
[7327] | 251 | return SubString(*this, begin); |
---|
[2171] | 252 | } |
---|
[836] | 253 | |
---|
[7327] | 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 | |
---|
[7327] | 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 | { |
---|
[7327] | 268 | return SubString(*this, begin, end); |
---|
[2171] | 269 | } |
---|
[836] | 270 | |
---|
[7327] | 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 | |
---|
[7327] | 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 |
---|
[7327] | 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, |
---|
[7327] | 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 | |
---|
[7327] | 306 | if(start_state != SL_NORMAL && tokens.size() > 0) |
---|
[836] | 307 | { |
---|
[7327] | 308 | token = tokens[tokens.size()-1]; |
---|
| 309 | tokens.pop_back(); |
---|
[836] | 310 | } |
---|
[7327] | 311 | if(start_state != SL_NORMAL && bTokenInSafemode.size() > 0) |
---|
[836] | 312 | { |
---|
[7327] | 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: |
---|
[7327] | 322 | if(line[i] == escapeChar) |
---|
[2171] | 323 | { |
---|
| 324 | state = SL_ESCAPE; |
---|
[7327] | 325 | if (!bRemoveEscapeChar) |
---|
[2171] | 326 | token += line[i]; |
---|
[7332] | 327 | fallBackNeighbours = 0; |
---|
[2171] | 328 | } |
---|
[7327] | 329 | else if(line[i] == safemodeChar) |
---|
[2171] | 330 | { |
---|
| 331 | state = SL_SAFEMODE; |
---|
| 332 | inSafemode = true; |
---|
[7327] | 333 | if (!bRemoveSafemodeChar) |
---|
[2171] | 334 | token += line[i]; |
---|
[7332] | 335 | fallBackNeighbours = 0; |
---|
[2171] | 336 | } |
---|
[7327] | 337 | else if(line[i] == openparenthesisChar) |
---|
[2171] | 338 | { |
---|
| 339 | state = SL_PARENTHESES; |
---|
| 340 | inSafemode = true; |
---|
[7327] | 341 | if (!bRemoveParenthesisChars) |
---|
[2171] | 342 | token += line[i]; |
---|
[7332] | 343 | fallBackNeighbours = 0; |
---|
[2171] | 344 | } |
---|
[7327] | 345 | else if(line[i] == commentChar) |
---|
[2171] | 346 | { |
---|
| 347 | if (fallBackNeighbours > 0) |
---|
| 348 | token = token.substr(0, token.size() - fallBackNeighbours); |
---|
[7332] | 349 | fallBackNeighbours = 0; |
---|
[7327] | 350 | // FINISH |
---|
| 351 | if(bAllowEmptyEntries || token.size() > 0) |
---|
[2171] | 352 | { |
---|
[7327] | 353 | tokens.push_back(token); |
---|
[2171] | 354 | token.clear(); |
---|
[7327] | 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); |
---|
[7332] | 366 | fallBackNeighbours = 0; |
---|
[7327] | 367 | // FINISH |
---|
| 368 | if(bAllowEmptyEntries || token.size() > 0) |
---|
[2171] | 369 | { |
---|
[7327] | 370 | tokens.push_back(token); |
---|
[2171] | 371 | token.clear(); |
---|
[7327] | 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 | { |
---|
[7327] | 385 | ++i; |
---|
[2171] | 386 | continue; |
---|
| 387 | } |
---|
| 388 | } |
---|
| 389 | else |
---|
| 390 | fallBackNeighbours = 0; |
---|
| 391 | token += line[i]; // EAT |
---|
| 392 | } |
---|
| 393 | break; |
---|
| 394 | case SL_ESCAPE: |
---|
[7327] | 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: |
---|
[7327] | 412 | if(line[i] == safemodeChar) |
---|
[2171] | 413 | { |
---|
| 414 | state = SL_NORMAL; |
---|
[7327] | 415 | if (!bRemoveSafemodeChar) |
---|
[2171] | 416 | token += line[i]; |
---|
| 417 | } |
---|
[7327] | 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: |
---|
[7327] | 442 | if(line[i] == closeparenthesisChar) |
---|
[2171] | 443 | { |
---|
| 444 | state = SL_NORMAL; |
---|
[7327] | 445 | if (!bRemoveParenthesisChars) |
---|
[2171] | 446 | token += line[i]; |
---|
| 447 | } |
---|
[7327] | 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 | { |
---|
[7327] | 474 | // FINISH |
---|
[2171] | 475 | if(token.size() > 0) |
---|
| 476 | { |
---|
[7327] | 477 | tokens.push_back(token); |
---|
[2171] | 478 | token.clear(); |
---|
[7327] | 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 | } |
---|
[7327] | 494 | ++i; |
---|
[1505] | 495 | } |
---|
| 496 | |
---|
[7327] | 497 | // FINISH |
---|
[2171] | 498 | if (fallBackNeighbours > 0) |
---|
| 499 | token = token.substr(0, token.size() - fallBackNeighbours); |
---|
[7327] | 500 | if(bAllowEmptyEntries || token.size() > 0) |
---|
[836] | 501 | { |
---|
[7327] | 502 | tokens.push_back(token); |
---|
[836] | 503 | token.clear(); |
---|
[7327] | 504 | bTokenInSafemode.push_back(inSafemode); |
---|
[1505] | 505 | inSafemode = false; |
---|
[836] | 506 | } |
---|
[2171] | 507 | return(state); |
---|
[836] | 508 | } |
---|
| 509 | |
---|
[2171] | 510 | /** |
---|
[7327] | 511 | @brief Some nice debug information about this SubString. |
---|
| 512 | */ |
---|
[2171] | 513 | void SubString::debug() const |
---|
| 514 | { |
---|
[7327] | 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 | } |
---|