Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 994


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.

Location:
code/branches/core2/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r993 r994  
    4646
    4747    ConsoleCommandShortcutExtern(exec, AccessLevel::None);
     48    ConsoleCommandShortcutExtern(echo, AccessLevel::None);
     49
     50    ConsoleCommandShortcutExtern(read, AccessLevel::None);
     51    ConsoleCommandShortcutExtern(append, AccessLevel::None);
     52    ConsoleCommandShortcutExtern(write, AccessLevel::None);
    4853
    4954    void exec(const std::string& filename)
     
    7984
    8085        executingFiles.erase(filename);
     86        file.close();
     87    }
     88
     89    std::string echo(const std::string& text)
     90    {
     91        return text;
     92    }
     93
     94    void write(const std::string& filename, const std::string& text)
     95    {
     96        std::ofstream file;
     97        file.open(filename.c_str(), std::fstream::out);
     98
     99        if (!file.is_open())
     100        {
     101            COUT(1) << "Error: Couldn't write to file \"" << filename << "\"." << std::endl;
     102            return;
     103        }
     104
     105        file << text << std::endl;
     106        file.close();
     107    }
     108
     109    void append(const std::string& filename, const std::string& text)
     110    {
     111        std::ofstream file;
     112        file.open(filename.c_str(), std::fstream::app);
     113
     114        if (!file.is_open())
     115        {
     116            COUT(1) << "Error: Couldn't append to file \"" << filename << "\"." << std::endl;
     117            return;
     118        }
     119
     120        file << text << std::endl;
     121        file.close();
     122    }
     123
     124    std::string read(const std::string& filename)
     125    {
     126        std::ifstream file;
     127        file.open(filename.c_str(), std::fstream::in);
     128
     129        if (!file.is_open())
     130        {
     131            COUT(1) << "Error: Couldn't read from file \"" << filename << "\"." << std::endl;
     132            return "";
     133        }
     134
     135        std::string output = "";
     136        char line[1024];
     137        while (file.good() && !file.eof())
     138        {
     139            file.getline(line, 1024);
     140            output += line;
     141            output += "\n";
     142        }
     143
     144        file.close();
     145
     146        return output;
    81147    }
    82148
     
    200266    }
    201267
     268    MultiTypeMath CommandEvaluation::getReturnvalue() const
     269    {
     270        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     271        {
     272            if (this->shortcut_)
     273                return this->shortcut_->getReturnvalue();
     274        }
     275        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
     276        {
     277            if (this->function_)
     278                return this->function_->getReturnvalue();
     279        }
     280
     281        return MT_null;
     282    }
     283
    202284
    203285    /////////////////////
     
    252334    bool CommandExecutor::execute(const std::string& command)
    253335    {
    254         if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
    255             CommandExecutor::parse(command);
     336        std::string strippedCommand = getStrippedEnclosingQuotes(command);
     337
     338        SubString tokensIO(strippedCommand, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
     339        if (tokensIO.size() >= 2)
     340        {
     341            if (tokensIO[tokensIO.size() - 2] == ">")
     342            {
     343                bool success = CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join());
     344                write(tokensIO[tokensIO.size() - 1], CommandExecutor::getEvaluation().getReturnvalue());
     345                return success;
     346            }
     347            else if (tokensIO[tokensIO.size() - 2] == "<")
     348            {
     349                std::string input = read(tokensIO[tokensIO.size() - 1]);
     350                if (input == "" || input.size() == 0)
     351                    return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join());
     352                else
     353                    return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join() + " " + input);
     354            }
     355        }
     356
     357
     358        SubString tokensPipeline(strippedCommand, "|", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
     359        if (tokensPipeline.size() > 1)
     360        {
     361            bool success = true;
     362            std::string returnValue = "";
     363            for (int i = tokensPipeline.size() - 1; i >= 0; i--)
     364            {
     365                if (returnValue == "" || returnValue.size() == 0)
     366                {
     367                    //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i]);
     368                    if (!CommandExecutor::execute(tokensPipeline[i]))
     369                        success = false;
     370                }
     371                else
     372                {
     373                    //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i] + " " + returnValue);
     374                    if (!CommandExecutor::execute(tokensPipeline[i] + " " + returnValue))
     375                        success = false;
     376                }
     377
     378                //CommandExecutor::execute(evaluation);
     379                //returnValue = evaluation.getReturnvalue();
     380                returnValue = CommandExecutor::getEvaluation().getReturnvalue().toString();
     381            }
     382            return success;
     383        }
     384
     385        if ((CommandExecutor::getEvaluation().processedCommand_ != strippedCommand) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
     386            CommandExecutor::parse(strippedCommand);
    256387
    257388        return CommandExecutor::execute(CommandExecutor::getEvaluation());
     
    261392    bool CommandExecutor::execute(const CommandEvaluation& evaluation)
    262393    {
    263         SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     394        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    264395
    265396        if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_)
     
    353484    std::string CommandExecutor::complete(const CommandEvaluation& evaluation)
    354485    {
    355         SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     486        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    356487
    357488        std::list<std::pair<const std::string*, const std::string*> > temp;
     
    444575    std::string CommandExecutor::hint(const CommandEvaluation& evaluation)
    445576    {
    446         SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     577        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    447578
    448579        switch (evaluation.state_)
     
    516647    void CommandExecutor::parse(const std::string& command, bool bInitialize)
    517648    {
    518         CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     649        CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    519650        CommandExecutor::getEvaluation().processedCommand_ = command;
    520651
  • code/branches/core2/src/orxonox/core/CommandExecutor.h

    r993 r994  
    6262
    6363    void exec(const std::string& filename);
     64    std::string echo(const std::string& text);
     65
     66    void write(const std::string& filename, const std::string& text);
     67    void append(const std::string& filename, const std::string& text);
     68    std::string read(const std::string& filename);
    6469
    6570    enum KeybindMode {}; // temporary
     
    8792
    8893            void evaluateParams();
     94
     95            MultiTypeMath getReturnvalue() const;
    8996
    9097        private:
  • code/branches/core2/src/orxonox/core/Executor.cc

    r967 r994  
    9090        {
    9191            // more than one param
    92             SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     92            SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0');
    9393
    9494            // if there are not enough params given, check if there are default values
  • code/branches/core2/src/orxonox/core/Executor.h

    r967 r994  
    7676    else \
    7777    { \
    78         SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); \
    79     \
     78        SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \
     79        \
    8080        for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \
    8181        { \
     
    8686            } \
    8787        } \
    88     \
    89         MultiTypeMath param[paramCount]; \
     88        \
     89        MultiTypeMath param[MAX_FUNCTOR_ARGUMENTS]; \
    9090        COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \
    9191        for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \
     
    109109        } \
    110110        COUT(5) << ")." << std::endl; \
    111     \
     111        \
     112        if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \
     113            param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \
     114        \
    112115        switch(paramCount) \
    113116        { \
  • code/branches/core2/src/orxonox/core/InputBuffer.cc

    r972 r994  
    3636    {
    3737        this->bActivated_ = false;
    38         this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \"().:,;_-+*/=!?";
     38        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \"().:,;_-+*/=!?<>[|]";
    3939        this->keyboard_ = keyboard;
    4040        this->buffer_ = "";
  • code/branches/core2/src/orxonox/core/Namespace.cc

    r902 r994  
    7272        while ((pos = name.find('\t')) != std::string::npos)
    7373            name.replace(pos, 1, " ");
    74         SubString tokens(name, " ", "", false, '\\', '"', '\0', '\0', '\0');
     74        SubString tokens(name, " ", "", false, '\\', true, '"', true, '\0', '\0', true, '\0');
    7575        if (this->bRoot_)
    7676        {
  • code/branches/core2/src/orxonox/core/OutputHandler.h

    r955 r994  
    6060
    6161            /** @brief Puts some text on the outstream. @param text The text */
    62             static inline void log(const std::string& text)
    63                 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); }
     62            static inline std::string log(const std::string& text)
     63                { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; }
    6464
    6565            /** @brief Returns a reference to the logfile. @return The logfile */
  • code/branches/core2/src/orxonox/core/XMLPort.h

    r947 r994  
    3232#include "util/MultiTypeMath.h"
    3333#include "util/tinyxml/ticpp.h"
    34 #include "util/SubString.h"
    3534#include "Executor.h"
    3635#include "Debug.h"
  • code/branches/core2/src/util/Convert.h

    r961 r994  
    407407      if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    408408
    409       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
     409      SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    410410
    411411      if (tokens.size() >= 2)
     
    433433      if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    434434
    435       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
     435      SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    436436
    437437      if (tokens.size() >= 3)
     
    461461      if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    462462
    463       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
     463      SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    464464
    465465      if (tokens.size() >= 4)
     
    491491      if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    492492
    493       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
     493      SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    494494
    495495      if (tokens.size() >= 4)
     
    521521      if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
    522522
    523       SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', '"', '\0', '\0', '\0');
     523      SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
    524524
    525525      if (tokens.size() >= 4)
  • code/branches/core2/src/util/String.cc

    r957 r994  
    5252    std::string output = std::string(str);
    5353    strip(&output);
     54    return output;
     55}
     56
     57/**
     58    @brief Removes enclosing quotes if available.
     59    @brief str The string to strip
     60*/
     61void stripEnclosingQuotes(std::string* str)
     62{
     63    unsigned int start = std::string::npos;
     64    unsigned int end = 0;
     65
     66    for (unsigned int pos = 0; (pos < (*str).size()) && (pos < std::string::npos); pos++)
     67    {
     68        if ((*str)[pos] == '"')
     69        {
     70            start = pos;
     71            break;
     72        }
     73
     74        if (((*str)[pos] != ' ') && ((*str)[pos] != '\t') && ((*str)[pos] != '\n'))
     75            return;
     76    }
     77
     78    for (unsigned int pos = (*str).size() - 1; pos < std::string::npos; pos--)
     79    {
     80        if ((*str)[pos] == '"')
     81        {
     82            end = pos;
     83            break;
     84        }
     85
     86        if (((*str)[pos] != ' ') && ((*str)[pos] != '\t') && ((*str)[pos] != '\n'))
     87            return;
     88    }
     89
     90    if ((start != std::string::npos) && (end != 0))
     91        (*str) = (*str).substr(start + 1, end - start - 1);
     92}
     93
     94/**
     95    @brief Returns a copy of the string with removed enclosing quotes (if available).
     96    @brief str The string to strip
     97    @return The striped copy of the string
     98*/
     99std::string getStrippedEnclosingQuotes(const std::string& str)
     100{
     101    std::string output = std::string(str);
     102    stripEnclosingQuotes(&output);
    54103    return output;
    55104}
  • code/branches/core2/src/util/String.h

    r933 r994  
    3636_UtilExport void        strip(std::string* str);
    3737_UtilExport std::string getStripped(const std::string& str);
     38
     39_UtilExport void        stripEnclosingQuotes(std::string* str);
     40_UtilExport std::string getStrippedEnclosingQuotes(const std::string& str);
    3841
    3942_UtilExport bool        isEmpty(const std::string& str);
  • 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);
  • code/branches/core2/src/util/SubString.h

    r871 r994  
    8888  SubString(const std::string& string,
    8989            const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false,
    90             char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0');
     90            char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true,
     91            char openparenthesis_char = '(', char closeparenthesis_char = ')',  bool removeParenthesisChars = true, char comment_char = '\0');
    9192  SubString(unsigned int argc, const char** argv);
    9293  /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */
     
    111112  unsigned int split(const std::string& string,
    112113                     const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false,
    113                      char escapeChar ='\\', char safemode_char = '"', char openparenthesis_char = '(', char closeparenthesis_char = ')', char comment_char = '\0');
     114                     char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true,
     115                     char openparenthesis_char = '(', char closeparenthesis_char = ')',  bool removeParenthesisChars = true, char comment_char = '\0');
    114116  std::string join(const std::string& delimiter = " ") const;
    115117  ////////////////////////////////////////
     
    120122
    121123  // retrieve Information from within
    122   /** @returns true if the SubString is empty */
     124  /** @brief Returns true if the SubString is empty */
    123125  inline bool empty() const { return this->strings.empty(); };
    124   /** @returns the count of Strings stored in this substring */
     126  /** @brief Returns the count of Strings stored in this substring */
    125127  inline unsigned int size() const { return this->strings.size(); };
    126   /** @param i the i'th String @returns the i'th string from the subset of Strings */
     128  /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */
    127129  inline const std::string& operator[](unsigned int i) const { return this->strings[i]; };
    128   /** @param i the i'th String @returns the i'th string from the subset of Strings */
     130  /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */
    129131  inline const std::string& getString(unsigned int i) const { return (*this)[i]; };
    130   /** @returns the front of the StringList. */
     132  /** @brief Returns true if the token is in safemode. @param i the i'th token */
     133  inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; }
     134  /** @brief Returns the front of the StringList. */
    131135  inline const std::string& front() const { return this->strings.front(); };
    132   /** @returns the back of the StringList. */
     136  /** @brief Returns the back of the StringList. */
    133137  inline const std::string& back() const { return this->strings.back(); };
    134138  /** @brief removes the back of the strings list. */
    135   inline void pop_back() { this->strings.pop_back(); };
     139  inline void pop_back() { this->strings.pop_back(); this->bInSafemode.pop_back(); };
    136140
    137141  // the almighty algorithm.
    138142  static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,
     143                                    std::vector<bool>& bInSafemode,
    139144                                    const std::string& line,
    140145                                    const std::string& delimiters = SubString::WhiteSpaces,
     
    142147                                    bool emptyEntries = false,
    143148                                    char escape_char = '\\',
     149                                    bool removeExcapeChar = true,
    144150                                    char safemode_char = '"',
     151                                    bool removeSafemodeChar = true,
    145152                                    char openparenthesis_char = '(',
    146153                                    char closeparenthesis_char = ')',
     154                                    bool removeParenthesisChars = true,
    147155                                    char comment_char = '\0',
    148156                                    SPLIT_LINE_STATE start_state = SL_NORMAL);
     
    157165private:
    158166  std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
     167  std::vector<bool>         bInSafemode;
    159168};
    160169
Note: See TracChangeset for help on using the changeset viewer.