Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 1:10:46 AM (17 years ago)
Author:
rgrieder
Message:

SVN doesn't seem to like me. Reverted some really badly converted line endings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/util/SubString.cc

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Christian Meyer *   Co-authors: *      Benjamin Grauer *////  splitLine//  STL string tokenizer////  Created by Clemens Wacha.//  Version 1.0//  Copyright (c) 2005 Clemens Wacha. All rights reserved.// */
     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 *
     27//
     28//  splitLine
     29//  STL string tokenizer
     30//
     31//  Created by Clemens Wacha.
     32//  Version 1.0
     33//  Copyright (c) 2005 Clemens Wacha. All rights reserved.
     34//
     35 */
     36
    237#include "SubString.h"
    338
     
    3267SubString::SubString(const std::string& string,
    3368                     const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    34                      char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar,                     char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
     69                     char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar,
     70                     char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
    3571{
    3672  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeEscapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
     
    4480SubString::SubString(const SubString& subString, unsigned int subSetBegin)
    4581{
    46   for (unsigned int i = subSetBegin; i < subString.size(); i++)  {
    47     this->strings.push_back(subString[i]);    this->bInSafemode.push_back(subString.isInSafemode(i));  }
     82  for (unsigned int i = subSetBegin; i < subString.size(); i++)
     83  {
     84    this->strings.push_back(subString[i]);
     85    this->bInSafemode.push_back(subString.isInSafemode(i));
     86  }
    4887}
    4988
     
    5796SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd)
    5897{
    59   for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++)  {
    60     this->strings.push_back(subString[i]);    this->bInSafemode.push_back(subString.isInSafemode(i));  }
     98  for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++)
     99  {
     100    this->strings.push_back(subString[i]);
     101    this->bInSafemode.push_back(subString.isInSafemode(i));
     102  }
    61103}
    62104
     
    68110SubString::SubString(unsigned int argc, const char** argv)
    69111{
    70   for(unsigned int i = 0; i < argc; ++i)  {
    71     this->strings.push_back(std::string(argv[i]));    this->bInSafemode.push_back(false);  }
     112  for(unsigned int i = 0; i < argc; ++i)
     113  {
     114    this->strings.push_back(std::string(argv[i]));
     115    this->bInSafemode.push_back(false);
     116  }
    72117}
    73118
     
    94139SubString& SubString::operator=(const SubString& subString)
    95140{
    96   this->strings = subString.strings;  this->bInSafemode = subString.bInSafemode;
     141  this->strings = subString.strings;
     142  this->bInSafemode = subString.bInSafemode;
    97143  return *this;
    98144}
     
    155201SubString& SubString::operator+=(const SubString& subString)
    156202{
    157   for (unsigned int i = 0; i < subString.size(); i++)  {
    158     this->strings.push_back(subString[i]);    this->bInSafemode.push_back(subString.isInSafemode(i));  }
     203  for (unsigned int i = 0; i < subString.size(); i++)
     204  {
     205    this->strings.push_back(subString[i]);
     206    this->bInSafemode.push_back(subString.isInSafemode(i));
     207  }
    159208  return *this;
    160209}
     
    168217unsigned int SubString::split(const std::string& string, char splitter)
    169218{
    170   this->strings.clear();  this->bInSafemode.clear();
     219  this->strings.clear();
     220  this->bInSafemode.clear();
    171221  char split[2];
    172222  split[0] = splitter;
     
    189239unsigned int SubString::split(const std::string& string,
    190240                              const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    191                               char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar,                              char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
    192 {
    193   this->strings.clear();  this->bInSafemode.clear();
     241                              char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar,
     242                              char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
     243{
     244  this->strings.clear();
     245  this->bInSafemode.clear();
    194246  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
    195247  return this->strings.size();
     
    257309 * @param emptyEntries: if empty Strings are added to the List of Strings.
    258310 * @param escape_char: Escape carater (escapes splitters)
    259  * @param safemode_char: the beginning of the safemode is marked with this * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token * @param openparenthesis_char the beginning of a safemode is marked with this * @param closeparenthesis_char the ending of a safemode is marked with this * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token
     311 * @param safemode_char: the beginning of the safemode is marked with this
     312 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token
     313 * @param openparenthesis_char the beginning of a safemode is marked with this
     314 * @param closeparenthesis_char the ending of a safemode is marked with this
     315 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token
    260316 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line)
    261317 * @param start_state: the Initial state on how to parse the String.
     
    267323 */
    268324SubString::SPLIT_LINE_STATE
    269 SubString::splitLine(std::vector<std::string>& ret,                     std::vector<bool>& bInSafemode,
     325SubString::splitLine(std::vector<std::string>& ret,
     326                     std::vector<bool>& bInSafemode,
    270327                     const std::string& line,
    271328                     const std::string& delimiters,
    272329                     const std::string& delimiterNeighbours,
    273330                     bool emptyEntries,
    274                      char escape_char,                     bool removeExcapeChar,
    275                      char safemode_char,                     bool removeSafemodeChar,                     char openparenthesis_char,                     char closeparenthesis_char,                     bool removeParenthesisChars,
     331                     char escape_char,
     332                     bool removeExcapeChar,
     333                     char safemode_char,
     334                     bool removeSafemodeChar,
     335                     char openparenthesis_char,
     336                     char closeparenthesis_char,
     337                     bool removeParenthesisChars,
    276338                     char comment_char,
    277339                     SPLIT_LINE_STATE start_state)
     
    281343  unsigned int fallBackNeighbours = 0;
    282344
    283   std::string token;  bool inSafemode = false;
    284 
    285   if(start_state != SL_NORMAL && ret.size() > 0)  {    token = ret[ret.size()-1];
    286     ret.pop_back();  }  if(start_state != SL_NORMAL && bInSafemode.size() > 0)  {    inSafemode = bInSafemode[bInSafemode.size()-1];    bInSafemode.pop_back();  }
     345  std::string token;
     346  bool inSafemode = false;
     347
     348  if(start_state != SL_NORMAL && ret.size() > 0)
     349  {
     350    token = ret[ret.size()-1];
     351    ret.pop_back();
     352  }
     353  if(start_state != SL_NORMAL && bInSafemode.size() > 0)
     354  {
     355    inSafemode = bInSafemode[bInSafemode.size()-1];
     356    bInSafemode.pop_back();
     357  }
     358
    287359  while(i < line.size())
    288360  {
     
    292364        if(line[i] == escape_char)
    293365        {
    294           state = SL_ESCAPE;          if (!removeExcapeChar)            token += line[i];
     366          state = SL_ESCAPE;
     367          if (!removeExcapeChar)
     368            token += line[i];
    295369        }
    296370        else if(line[i] == safemode_char)
    297371        {
    298           state = SL_SAFEMODE;          inSafemode = true;          if (!removeSafemodeChar)            token += line[i];
    299         }        else if(line[i] == openparenthesis_char)        {          state = SL_PARENTHESES;          inSafemode = true;          if (!removeParenthesisChars)            token += line[i];        }
     372          state = SL_SAFEMODE;
     373          inSafemode = true;
     374          if (!removeSafemodeChar)
     375            token += line[i];
     376        }
     377        else if(line[i] == openparenthesis_char)
     378        {
     379          state = SL_PARENTHESES;
     380          inSafemode = true;
     381          if (!removeParenthesisChars)
     382            token += line[i];
     383        }
    300384        else if(line[i] == comment_char)
    301385        {
     
    305389          if(emptyEntries || token.size() > 0)
    306390          {
    307             ret.push_back(token);            token.clear();            bInSafemode.push_back(inSafemode);            inSafemode = false;          }
     391            ret.push_back(token);
     392            token.clear();
     393            bInSafemode.push_back(inSafemode);
     394            inSafemode = false;
     395          }
    308396          token += line[i];       // EAT
    309397          state = SL_COMMENT;
     
    319407            ret.push_back(token);
    320408            token.clear();
    321             bInSafemode.push_back(inSafemode);            inSafemode = false;          }
     409            bInSafemode.push_back(inSafemode);
     410            inSafemode = false;
     411          }
    322412          state = SL_NORMAL;
    323413        }
     
    339429        }
    340430        break;
    341       case SL_ESCAPE:        if (!removeSafemodeChar)          token += line[i];        else        {
     431      case SL_ESCAPE:
     432        if (!removeSafemodeChar)
     433          token += line[i];
     434        else
     435        {
    342436          if(line[i] == 'n') token += '\n';
    343437          else if(line[i] == 't') token += '\t';
     
    348442          else if(line[i] == 'a') token += '\a';
    349443          else if(line[i] == '?') token += '\?';
    350           else token += line[i];  // EAT        }
     444          else token += line[i];  // EAT
     445        }
    351446        state = SL_NORMAL;
    352447        break;
     
    355450        {
    356451          state = SL_NORMAL;
    357           if (!removeSafemodeChar)            token += line[i];        }
     452          if (!removeSafemodeChar)
     453            token += line[i];
     454        }
    358455        else if(line[i] == escape_char)
    359456        {
     
    364461          token += line[i];       // EAT
    365462        }
    366         break;      case SL_SAFEESCAPE:
     463        break;
     464
     465      case SL_SAFEESCAPE:
    367466        if(line[i] == 'n') token += '\n';
    368467        else if(line[i] == 't') token += '\t';
     
    376475        state = SL_SAFEMODE;
    377476        break;
    378       case SL_PARENTHESES:        if(line[i] == closeparenthesis_char)        {          state = SL_NORMAL;          if (!removeParenthesisChars)            token += line[i];        }        else if(line[i] == escape_char)        {          state = SL_PARENTHESESESCAPE;        }        else        {          token += line[i];       // EAT        }        break;      case SL_PARENTHESESESCAPE:        if(line[i] == 'n') token += '\n';        else if(line[i] == 't') token += '\t';        else if(line[i] == 'v') token += '\v';        else if(line[i] == 'b') token += '\b';        else if(line[i] == 'r') token += '\r';        else if(line[i] == 'f') token += '\f';        else if(line[i] == 'a') token += '\a';        else if(line[i] == '?') token += '\?';        else token += line[i];  // EAT        state = SL_PARENTHESES;        break;
     477
     478      case SL_PARENTHESES:
     479        if(line[i] == closeparenthesis_char)
     480        {
     481          state = SL_NORMAL;
     482          if (!removeParenthesisChars)
     483            token += line[i];
     484        }
     485        else if(line[i] == escape_char)
     486        {
     487          state = SL_PARENTHESESESCAPE;
     488        }
     489        else
     490        {
     491          token += line[i];       // EAT
     492        }
     493        break;
     494
     495      case SL_PARENTHESESESCAPE:
     496        if(line[i] == 'n') token += '\n';
     497        else if(line[i] == 't') token += '\t';
     498        else if(line[i] == 'v') token += '\v';
     499        else if(line[i] == 'b') token += '\b';
     500        else if(line[i] == 'r') token += '\r';
     501        else if(line[i] == 'f') token += '\f';
     502        else if(line[i] == 'a') token += '\a';
     503        else if(line[i] == '?') token += '\?';
     504        else token += line[i];  // EAT
     505        state = SL_PARENTHESES;
     506        break;
     507
    379508      case SL_COMMENT:
    380509        if(line[i] == '\n')
     
    385514            ret.push_back(token);
    386515            token.clear();
    387             bInSafemode.push_back(inSafemode);            inSafemode = false;          }
     516            bInSafemode.push_back(inSafemode);
     517            inSafemode = false;
     518          }
    388519          state = SL_NORMAL;
    389520        }
     
    408539    ret.push_back(token);
    409540    token.clear();
    410     bInSafemode.push_back(inSafemode);    inSafemode = false;  }
     541    bInSafemode.push_back(inSafemode);
     542    inSafemode = false;
     543  }
    411544  return(state);
    412545}
Note: See TracChangeset for help on using the changeset viewer.