Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2008, 11:24:44 PM (16 years ago)
Author:
rgrieder
Message:
  • set the svn:eol-style property to all files so, that where ever you check out, you'll get the right line endings (had to change every file with mixed endings to windows in order to set the property)
File:
1 edited

Legend:

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

    • Property svn:eol-style set to native
    r1349 r1494  
    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 
     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.// */
    372#include "SubString.h"
    383
     
    6732SubString::SubString(const std::string& string,
    6833                     const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    69                      char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar,
    70                      char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
     34                     char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar,                     char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
    7135{
    7236  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeEscapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
     
    8044SubString::SubString(const SubString& subString, unsigned int subSetBegin)
    8145{
    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   }
     46  for (unsigned int i = subSetBegin; i < subString.size(); i++)  {
     47    this->strings.push_back(subString[i]);    this->bInSafemode.push_back(subString.isInSafemode(i));  }
    8748}
    8849
     
    9657SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd)
    9758{
    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   }
     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));  }
    10361}
    10462
     
    11068SubString::SubString(unsigned int argc, const char** argv)
    11169{
    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   }
     70  for(unsigned int i = 0; i < argc; ++i)  {
     71    this->strings.push_back(std::string(argv[i]));    this->bInSafemode.push_back(false);  }
    11772}
    11873
     
    13994SubString& SubString::operator=(const SubString& subString)
    14095{
    141   this->strings = subString.strings;
    142   this->bInSafemode = subString.bInSafemode;
     96  this->strings = subString.strings;  this->bInSafemode = subString.bInSafemode;
    14397  return *this;
    14498}
     
    201155SubString& SubString::operator+=(const SubString& subString)
    202156{
    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   }
     157  for (unsigned int i = 0; i < subString.size(); i++)  {
     158    this->strings.push_back(subString[i]);    this->bInSafemode.push_back(subString.isInSafemode(i));  }
    208159  return *this;
    209160}
     
    217168unsigned int SubString::split(const std::string& string, char splitter)
    218169{
    219   this->strings.clear();
    220   this->bInSafemode.clear();
     170  this->strings.clear();  this->bInSafemode.clear();
    221171  char split[2];
    222172  split[0] = splitter;
     
    239189unsigned int SubString::split(const std::string& string,
    240190                              const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    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();
     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();
    246194  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
    247195  return this->strings.size();
     
    309257 * @param emptyEntries: if empty Strings are added to the List of Strings.
    310258 * @param escape_char: Escape carater (escapes splitters)
    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
     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
    316260 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line)
    317261 * @param start_state: the Initial state on how to parse the String.
     
    323267 */
    324268SubString::SPLIT_LINE_STATE
    325 SubString::splitLine(std::vector<std::string>& ret,
    326                      std::vector<bool>& bInSafemode,
     269SubString::splitLine(std::vector<std::string>& ret,                     std::vector<bool>& bInSafemode,
    327270                     const std::string& line,
    328271                     const std::string& delimiters,
    329272                     const std::string& delimiterNeighbours,
    330273                     bool emptyEntries,
    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,
     274                     char escape_char,                     bool removeExcapeChar,
     275                     char safemode_char,                     bool removeSafemodeChar,                     char openparenthesis_char,                     char closeparenthesis_char,                     bool removeParenthesisChars,
    338276                     char comment_char,
    339277                     SPLIT_LINE_STATE start_state)
     
    343281  unsigned int fallBackNeighbours = 0;
    344282
    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 
     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();  }
    359287  while(i < line.size())
    360288  {
     
    364292        if(line[i] == escape_char)
    365293        {
    366           state = SL_ESCAPE;
    367           if (!removeExcapeChar)
    368             token += line[i];
     294          state = SL_ESCAPE;          if (!removeExcapeChar)            token += line[i];
    369295        }
    370296        else if(line[i] == safemode_char)
    371297        {
    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         }
     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];        }
    384300        else if(line[i] == comment_char)
    385301        {
     
    389305          if(emptyEntries || token.size() > 0)
    390306          {
    391             ret.push_back(token);
    392             token.clear();
    393             bInSafemode.push_back(inSafemode);
    394             inSafemode = false;
    395           }
     307            ret.push_back(token);            token.clear();            bInSafemode.push_back(inSafemode);            inSafemode = false;          }
    396308          token += line[i];       // EAT
    397309          state = SL_COMMENT;
     
    407319            ret.push_back(token);
    408320            token.clear();
    409             bInSafemode.push_back(inSafemode);
    410             inSafemode = false;
    411           }
     321            bInSafemode.push_back(inSafemode);            inSafemode = false;          }
    412322          state = SL_NORMAL;
    413323        }
     
    429339        }
    430340        break;
    431       case SL_ESCAPE:
    432         if (!removeSafemodeChar)
    433           token += line[i];
    434         else
    435         {
     341      case SL_ESCAPE:        if (!removeSafemodeChar)          token += line[i];        else        {
    436342          if(line[i] == 'n') token += '\n';
    437343          else if(line[i] == 't') token += '\t';
     
    442348          else if(line[i] == 'a') token += '\a';
    443349          else if(line[i] == '?') token += '\?';
    444           else token += line[i];  // EAT
    445         }
     350          else token += line[i];  // EAT        }
    446351        state = SL_NORMAL;
    447352        break;
     
    450355        {
    451356          state = SL_NORMAL;
    452           if (!removeSafemodeChar)
    453             token += line[i];
    454         }
     357          if (!removeSafemodeChar)            token += line[i];        }
    455358        else if(line[i] == escape_char)
    456359        {
     
    461364          token += line[i];       // EAT
    462365        }
    463         break;
    464 
    465       case SL_SAFEESCAPE:
     366        break;      case SL_SAFEESCAPE:
    466367        if(line[i] == 'n') token += '\n';
    467368        else if(line[i] == 't') token += '\t';
     
    475376        state = SL_SAFEMODE;
    476377        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 
     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;
    508379      case SL_COMMENT:
    509380        if(line[i] == '\n')
     
    514385            ret.push_back(token);
    515386            token.clear();
    516             bInSafemode.push_back(inSafemode);
    517             inSafemode = false;
    518           }
     387            bInSafemode.push_back(inSafemode);            inSafemode = false;          }
    519388          state = SL_NORMAL;
    520389        }
     
    539408    ret.push_back(token);
    540409    token.clear();
    541     bInSafemode.push_back(inSafemode);
    542     inSafemode = false;
    543   }
     410    bInSafemode.push_back(inSafemode);    inSafemode = false;  }
    544411  return(state);
    545412}
Note: See TracChangeset for help on using the changeset viewer.