Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 5, 2008, 5:54:24 PM (16 years ago)
Author:
landauf
Message:
  • added some symbols to the CommandExecutor: a) expression | expression: the pipe leads the output from the right expression into the left one b) expression > file: writes the output of the expression into a file c) expression < file: reads a file and uses it's content as input for the expression
  • added new console commands: a) echo text: returns the input b) read file: reads a file and returns the content c) write file text: writes text into a file d) append file text: appends text to a file
  • added stripEnclosingQuotes function to String.h, that removes enclosing quotes (if there are some). whitespaces outside the quotes are stripped, whitespaces inside the quotes stay. removes the quotes only if there is nothing else than whitespaces outside of them. what it changes: "expression" → expression what it let unchanged:
    • ex"press"ion
    • a"expression"b
    • a"expression"
    • "expression"b
    • express"ion
  • extended SubString: added some bools to determine the behaviour when dividing a string like the following up into pieces: mytext "this is a quoted area" blub (0, 1, 2)

this usually results in:
mytext / this is a quoted area / blub / 0, 1, 2

but now you can change it to:
mytext / "this is a quoted area" / blub / (0, 1, 2)

this is important if the string wents through several substring splitups and the quotes and brackets should stay.

File:
1 edited

Legend:

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

    r871 r994  
    6666SubString::SubString(const std::string& string,
    6767                     const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    68                      char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char)
    69 {
    70   SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char);
     68                     char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar,
     69                     char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
     70{
     71  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
    7172}
    7273
     
    7980{
    8081  for (unsigned int i = subSetBegin; i < subString.size(); i++)
     82  {
    8183    this->strings.push_back(subString[i]);
     84    this->bInSafemode.push_back(subString.isInSafemode(i));
     85  }
    8286}
    8387
     
    9195SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd)
    9296{
    93   for (unsigned int i = subSetBegin; i < subString.size() || i < subSetEnd; i++)
     97  for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++)
     98  {
    9499    this->strings.push_back(subString[i]);
     100    this->bInSafemode.push_back(subString.isInSafemode(i));
     101  }
    95102}
    96103
     
    103110{
    104111  for(unsigned int i = 0; i < argc; ++i)
     112  {
    105113    this->strings.push_back(std::string(argv[i]));
     114    this->bInSafemode.push_back(false);
     115  }
    106116}
    107117
     
    129139{
    130140  this->strings = subString.strings;
     141  this->bInSafemode = subString.bInSafemode;
    131142  return *this;
    132143}
     
    140151bool SubString::operator==(const SubString& subString) const
    141152{
    142   return (this->strings == subString.strings);
     153  return ((this->strings == subString.strings) && (this->bInSafemode == subString.bInSafemode));
    143154}
    144155
     
    165176
    166177  for (unsigned int i = 0; i < length; i++)
    167     if (this->strings[i] != subString.strings[i])
     178    if ((this->strings[i] != subString.strings[i]) || (this->bInSafemode[i] != subString.bInSafemode[i]))
    168179      return false;
    169180  return true;
     
    190201{
    191202  for (unsigned int i = 0; i < subString.size(); i++)
     203  {
    192204    this->strings.push_back(subString[i]);
     205    this->bInSafemode.push_back(subString.isInSafemode(i));
     206  }
    193207  return *this;
    194208}
     
    203217{
    204218  this->strings.clear();
     219  this->bInSafemode.clear();
    205220  char split[2];
    206221  split[0] = splitter;
    207222  split[1] = '\0';
    208   SubString::splitLine(this->strings, string, split);
     223  SubString::splitLine(this->strings, this->bInSafemode, string, split);
    209224  return strings.size();
    210225}
     
    223238unsigned int SubString::split(const std::string& string,
    224239                              const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries,
    225                               char escapeChar, char safemode_char, char openparenthesis_char, char closeparenthesis_char, char comment_char)
     240                              char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar,
     241                              char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char)
    226242{
    227243  this->strings.clear();
    228   SubString::splitLine(this->strings, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, safemode_char, openparenthesis_char, closeparenthesis_char, comment_char);
     244  this->bInSafemode.clear();
     245  SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char);
    229246  return this->strings.size();
    230247}
     
    292309 * @param escape_char: Escape carater (escapes splitters)
    293310 * @param safemode_char: the beginning of the safemode is marked with this
     311 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token
     312 * @param openparenthesis_char the beginning of a safemode is marked with this
     313 * @param closeparenthesis_char the ending of a safemode is marked with this
     314 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token
    294315 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line)
    295316 * @param start_state: the Initial state on how to parse the String.
    296  * @returns SPLIT_LINE_STATE the parser was in when returning
     317 * @return SPLIT_LINE_STATE the parser was in when returning
    297318 *
    298319 * This is the Actual Splitting Algorithm from Clemens Wacha
     
    302323SubString::SPLIT_LINE_STATE
    303324SubString::splitLine(std::vector<std::string>& ret,
     325                     std::vector<bool>& bInSafemode,
    304326                     const std::string& line,
    305327                     const std::string& delimiters,
     
    307329                     bool emptyEntries,
    308330                     char escape_char,
     331                     bool removeExcapeChar,
    309332                     char safemode_char,
     333                     bool removeSafemodeChar,
    310334                     char openparenthesis_char,
    311335                     char closeparenthesis_char,
     336                     bool removeParenthesisChars,
    312337                     char comment_char,
    313338                     SPLIT_LINE_STATE start_state)
     
    318343
    319344  std::string token;
     345  bool inSafemode = false;
    320346
    321347  if(start_state != SL_NORMAL && ret.size() > 0)
     
    323349    token = ret[ret.size()-1];
    324350    ret.pop_back();
     351  }
     352  if(start_state != SL_NORMAL && bInSafemode.size() > 0)
     353  {
     354    inSafemode = bInSafemode[bInSafemode.size()-1];
     355    bInSafemode.pop_back();
    325356  }
    326357
     
    333364        {
    334365          state = SL_ESCAPE;
     366          if (!removeExcapeChar)
     367            token += line[i];
    335368        }
    336369        else if(line[i] == safemode_char)
    337370        {
    338371          state = SL_SAFEMODE;
     372          inSafemode = true;
     373          if (!removeSafemodeChar)
     374            token += line[i];
    339375        }
    340376        else if(line[i] == openparenthesis_char)
    341377        {
    342378          state = SL_PARENTHESES;
     379          inSafemode = true;
     380          if (!removeParenthesisChars)
     381            token += line[i];
    343382        }
    344383        else if(line[i] == comment_char)
     
    351390            ret.push_back(token);
    352391            token.clear();
     392            bInSafemode.push_back(inSafemode);
     393            inSafemode = false;
    353394          }
    354395          token += line[i];       // EAT
     
    365406            ret.push_back(token);
    366407            token.clear();
     408            bInSafemode.push_back(inSafemode);
     409            inSafemode = false;
    367410          }
    368411          state = SL_NORMAL;
     
    386429        break;
    387430      case SL_ESCAPE:
    388         if(line[i] == 'n') token += '\n';
    389         else if(line[i] == 't') token += '\t';
    390         else if(line[i] == 'v') token += '\v';
    391         else if(line[i] == 'b') token += '\b';
    392         else if(line[i] == 'r') token += '\r';
    393         else if(line[i] == 'f') token += '\f';
    394         else if(line[i] == 'a') token += '\a';
    395         else if(line[i] == '?') token += '\?';
    396         else token += line[i];  // EAT
     431        if (!removeSafemodeChar)
     432          token += line[i];
     433        else
     434        {
     435          if(line[i] == 'n') token += '\n';
     436          else if(line[i] == 't') token += '\t';
     437          else if(line[i] == 'v') token += '\v';
     438          else if(line[i] == 'b') token += '\b';
     439          else if(line[i] == 'r') token += '\r';
     440          else if(line[i] == 'f') token += '\f';
     441          else if(line[i] == 'a') token += '\a';
     442          else if(line[i] == '?') token += '\?';
     443          else token += line[i];  // EAT
     444        }
    397445        state = SL_NORMAL;
    398446        break;
     
    401449        {
    402450          state = SL_NORMAL;
     451          if (!removeSafemodeChar)
     452            token += line[i];
    403453        }
    404454        else if(line[i] == escape_char)
     
    429479        {
    430480          state = SL_NORMAL;
     481          if (!removeParenthesisChars)
     482            token += line[i];
    431483        }
    432484        else if(line[i] == escape_char)
     
    461513            ret.push_back(token);
    462514            token.clear();
     515            bInSafemode.push_back(inSafemode);
     516            inSafemode = false;
    463517          }
    464518          state = SL_NORMAL;
     
    484538    ret.push_back(token);
    485539    token.clear();
     540    bInSafemode.push_back(inSafemode);
     541    inSafemode = false;
    486542  }
    487543  return(state);
Note: See TracChangeset for help on using the changeset viewer.