Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1049 for code/branches


Ignore:
Timestamp:
Apr 14, 2008, 12:48:25 AM (17 years ago)
Author:
landauf
Message:

config-value accepts now strings with special chars like \n or \t and hopefully every other. strings are enclosed by "…", but the quotes are only visible in the config-file. if you want something like " ← whitespace" you must add quotes, otherwise this would be stripped to "← whitespace".

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

Legend:

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

    r1030 r1049  
    335335    bool CommandExecutor::execute(const std::string& command)
    336336    {
    337         std::string strippedCommand = getStrippedEnclosingQuotes(command);
     337        std::string strippedCommand = stripEnclosingQuotes(command);
    338338
    339339        SubString tokensIO(strippedCommand, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
  • code/branches/core2/src/orxonox/core/ConfigFileManager.cc

    r1030 r1049  
    6666    // ConfigFileEntryValue //
    6767    //////////////////////////
     68
     69    void ConfigFileEntryValue::setValue(const std::string& value)
     70    {
     71        if (!this->bString_)
     72            this->value_ = value;
     73        else
     74            this->value_ = "\"" + addSlashes(value) + "\"";
     75    }
     76
     77    std::string ConfigFileEntryValue::getValue() const
     78    {
     79        if (!this->bString_)
     80            return this->value_;
     81        else
     82            return removeSlashes(stripEnclosingQuotes(this->value_));
     83    }
     84
    6885    std::string ConfigFileEntryValue::getFileEntry() const
    6986    {
     
    130147    }
    131148
    132     std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback)
     149    std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback, bool bString)
    133150    {
    134151        for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
     152        {
    135153            if ((*it)->getName() == name)
     154            {
     155                (*it)->setString(bString);
    136156                return it;
     157            }
     158        }
    137159
    138160        this->bUpdated_ = true;
    139161
    140         return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryValue(name, fallback)));
    141     }
    142 
    143     std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback)
     162        return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryValue(name, fallback, bString)));
     163    }
     164
     165    std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
    144166    {
    145167        for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
     168        {
    146169            if (((*it)->getName() == name) && ((*it)->getIndex() == index))
     170            {
     171                (*it)->setString(bString);
    147172                return it;
     173            }
     174        }
    148175
    149176        this->bUpdated_ = true;
    150177
    151178        if (index == 0)
    152             return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback)));
    153         else
    154             return this->entries_.insert(++this->getEntryIterator(name, index - 1), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback)));
     179            return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
     180        else
     181            return this->entries_.insert(++this->getEntryIterator(name, index - 1, "", bString), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
    155182    }
    156183
     
    233260                        unsigned int pos2 = line.find('[');
    234261                        unsigned int pos3 = line.find(']');
    235 
    236                         std::string value = removeTrailingWhitespaces(line.substr(pos1 + 1));
    237                         std::string comment = "";
    238 
    239                         std::string betweenQuotes = getStringBetweenQuotes(value);
    240                         if (value.size() > 0 && value[0] == '"' && betweenQuotes != "" && betweenQuotes.size() > 0)
     262                        unsigned int commentposition = getNextCommentPosition(line, pos1 + 1);
     263                        while (isBetweenQuotes(line, commentposition))
    241264                        {
    242                             value = betweenQuotes;
    243                             if (line.size() > pos1 + 1 + betweenQuotes.size() + 2)
    244                                 comment = removeTrailingWhitespaces(getComment(line.substr(pos1 + 1 + betweenQuotes.size() + 2)));
     265                            commentposition = getNextCommentPosition(line, commentposition + 1);
     266                        }
     267                        std::string value = "", comment = "";
     268                        if (commentposition == std::string::npos)
     269                        {
     270                            value = removeTrailingWhitespaces(line.substr(pos1 + 1));
    245271                        }
    246272                        else
    247273                        {
    248                             unsigned int pos4 = getCommentPosition(line);
    249                             value = removeTrailingWhitespaces(line.substr(pos1 + 1, pos4 - pos1 - 1));
    250                             if (pos4 != std::string::npos)
    251                                 comment = removeTrailingWhitespaces(line.substr(pos4));
     274                            value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1));
     275                            comment = removeTrailingWhitespaces(line.substr(commentposition));
    252276                        }
    253277
     
    259283                            {
    260284                                // New array
    261                                 std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value);
     285                                std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false);
    262286                                (*it)->setValue(value);
    263287                                (*it)->setComment(comment);
     
    267291
    268292                        // New value
    269                         newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, comment));
     293                        newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment));
    270294                        continue;
    271295                    }
  • code/branches/core2/src/orxonox/core/ConfigFileManager.h

    r1030 r1049  
    6363        public:
    6464            virtual void setValue(const std::string& value) = 0;
    65             virtual const std::string& getValue() const = 0;
     65            virtual std::string getValue() const = 0;
    6666            virtual const std::string& getName() const = 0;
    6767            virtual void setComment(const std::string& comment) = 0;
    6868            virtual unsigned int getIndex() const { return 0; }
     69            virtual void setString(bool bString) = 0;
    6970            virtual std::string getFileEntry() const = 0;
    7071    };
     
    7778    {
    7879        public:
    79             inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", const std::string& additionalComment = "") : name_(name), value_(value), additionalComment_(additionalComment), bString_(false) {}
     80            inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") : name_(name), value_(value), bString_(bString), additionalComment_(additionalComment) {}
    8081            inline virtual ~ConfigFileEntryValue() {}
    8182
     
    8687                { this->additionalComment_ = comment; }
    8788
    88             inline virtual void setValue(const std::string& value)
    89                 { this->value_ = value; }
    90             inline virtual const std::string& getValue() const
    91                 { return this->value_; }
     89            virtual void setValue(const std::string& value);
     90            virtual std::string getValue() const;
    9291
    9392            inline bool isString() const
     
    101100            std::string name_;
    102101            std::string value_;
     102            bool bString_;
    103103            std::string additionalComment_;
    104             bool bString_;
    105104    };
    106105
     
    112111    {
    113112        public:
    114             inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, additionalComment), index_(index) {}
     113            inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") : ConfigFileEntryValue(name, value, bString, additionalComment), index_(index) {}
    115114            inline virtual ~ConfigFileEntryVectorValue() {}
    116115
     
    142141            inline virtual void setValue(const std::string& value)
    143142                {}
    144             inline virtual const std::string& getValue() const
     143            inline virtual std::string getValue() const
    145144                { return this->comment_; }
     145
     146            inline void setString(bool bString) {}
    146147
    147148            inline virtual std::string getFileEntry() const
     
    170171                { this->additionalComment_ = comment; }
    171172
    172             inline void setValue(const std::string& name, const std::string& value)
    173                 { this->getEntry(name, value)->setValue(value); }
    174             inline const std::string& getValue(const std::string& name, const std::string& fallback)
    175                 { return this->getEntry(name, fallback)->getValue(); }
    176 
    177             inline void setValue(const std::string& name, unsigned int index, const std::string& value)
    178                 { this->getEntry(name, index, value)->setValue(value); }
    179             inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback)
    180                 { return this->getEntry(name, index, fallback)->getValue(); }
     173            inline void setValue(const std::string& name, const std::string& value, bool bString)
     174                { this->getEntry(name, value, bString)->setValue(value); }
     175            inline std::string getValue(const std::string& name, const std::string& fallback, bool bString)
     176                { return this->getEntry(name, fallback, bString)->getValue(); }
     177
     178            inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString)
     179                { this->getEntry(name, index, value, bString)->setValue(value); }
     180            inline std::string getValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
     181                { return this->getEntry(name, index, fallback, bString)->getValue(); }
    181182
    182183            void deleteVectorEntries(const std::string& name, unsigned int startindex = 0);
     
    193194                { return this->entries_.end(); }
    194195
    195             std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, const std::string& fallback = "");
    196             std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback = "");
    197 
    198             inline ConfigFileEntry* getEntry(const std::string& name, const std::string& fallback)
    199                 { return (*this->getEntryIterator(name, fallback)); }
    200             inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index, const std::string& fallback)
    201                 { return (*this->getEntryIterator(name, index, fallback)); }
     196            std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, const std::string& fallback, bool bString);
     197            std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString);
     198
     199            inline ConfigFileEntry* getEntry(const std::string& name, const std::string& fallback, bool bString)
     200                { return (*this->getEntryIterator(name, fallback, bString)); }
     201            inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
     202                { return (*this->getEntryIterator(name, index, fallback, bString)); }
    202203
    203204            std::string name_;
     
    221222            void clean(bool bCleanComments = false);
    222223
    223             inline void setValue(const std::string& section, const std::string& name, const std::string& value)
    224                 { this->getSection(section)->setValue(name, value); this->save(); }
    225             inline const std::string& getValue(const std::string& section, const std::string& name, const std::string& fallback)
    226                 { const std::string& output = this->getSection(section)->getValue(name, fallback); this->saveIfUpdated(); return output; }
    227 
    228             inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value)
    229                 { this->getSection(section)->setValue(name, index, value); this->save(); }
    230             inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback)
    231                 { const std::string& output = this->getSection(section)->getValue(name, index, fallback); this->saveIfUpdated(); return output; }
     224            inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString)
     225                { this->getSection(section)->setValue(name, value, bString); this->save(); }
     226            inline std::string getValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString)
     227                { std::string output = this->getSection(section)->getValue(name, fallback, bString); this->saveIfUpdated(); return output; }
     228
     229            inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
     230                { this->getSection(section)->setValue(name, index, value, bString); this->save(); }
     231            inline std::string getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
     232                { std::string output = this->getSection(section)->getValue(name, index, fallback, bString); this->saveIfUpdated(); return output; }
    232233
    233234            inline void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0)
     
    264265            void clean(ConfigFileType type, bool bCleanComments = false);
    265266
    266             inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value)
    267                 { this->getFile(type)->setValue(section, name, value); }
    268             inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback)
    269                 { return this->getFile(type)->getValue(section, name, fallback); }
    270 
    271             inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value)
    272                 { this->getFile(type)->setValue(section, name, index, value); }
    273             inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback)
    274                 { return this->getFile(type)->getValue(section, name, index, fallback); }
     267            inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value, bool bString)
     268                { this->getFile(type)->setValue(section, name, value, bString); }
     269            inline std::string getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString)
     270                { return this->getFile(type)->getValue(section, name, fallback, bString); }
     271
     272            inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
     273                { this->getFile(type)->setValue(section, name, index, value, bString); }
     274            inline std::string getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
     275                { return this->getFile(type)->getValue(section, name, index, fallback, bString); }
    275276
    276277            inline void deleteVectorEntries(ConfigFileType type, const std::string& section, const std::string& name, unsigned int startindex = 0)
  • code/branches/core2/src/orxonox/core/ConfigValueContainer.cc

    r1036 r1049  
    8888
    8989        for (unsigned int i = 0; i < defvalue.size(); i++)
    90             ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString());
     90            ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string));
    9191
    9292        for (unsigned int i = 0; i < defvalue.size(); i++)
     
    123123                this->valueVector_.erase(this->valueVector_.begin() + index);
    124124                for (unsigned int i = index; i < this->valueVector_.size(); i++)
    125                     ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i]);
     125                    ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string));
    126126                ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
    127127
     
    171171
    172172        bool success = this->tset(input);
    173         ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input);
     173        ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isA(MT_string));
    174174        return success;
    175175    }
     
    186186        {
    187187            bool success = this->tset(index, input);
    188             ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input);
     188            ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isA(MT_string));
    189189            return success;
    190190        }
     
    251251    {
    252252        if (!this->bIsVector_)
    253             this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_));
     253            this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isA(MT_string)));
    254254        else
    255255        {
     
    257257            for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++)
    258258            {
    259                 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i]));
     259                this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string)));
    260260                this->valueVector_.push_back(this->value_);
    261261            }
     
    322322                {
    323323                    this->valueVector_.push_back(MultiTypeMath());
    324                     ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i]);
     324                    ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string));
    325325                }
    326326            }
  • code/branches/core2/src/orxonox/core/InputBuffer.cc

    r994 r1049  
    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/objects/test3.cc

    r1033 r1049  
    8484        std::cout << "vector<int>:     " << i << ": " << this->vector_int_[i] << std::endl;
    8585        for (unsigned int i = 0; i < this->vector_string_.size(); i++)
    86         std::cout << "vector<string>:  " << i << ": " << this->vector_string_[i] << std::endl;
     86        std::cout << "vector<string>:  " << i << ":>" << this->vector_string_[i] << "<" << std::endl;
    8787        for (unsigned int i = 0; i < this->vector_vector3_.size(); i++)
    8888        std::cout << "vector<vector3>: " << i << ": " << this->vector_vector3_[i] << std::endl;
  • code/branches/core2/src/util/String.cc

    r1020 r1049  
    2727
    2828#include <cctype>
    29 
     29#include <iostream>
    3030#include "String.h"
    3131
     
    9292
    9393    return quote;
     94}
     95
     96/**
     97    @brief Returns true if pos is between two quotes.
     98    @param str The string
     99    @param pos The position to check
     100    @return True if pos is between two quotes
     101*/
     102bool isBetweenQuotes(const std::string& str, unsigned int pos)
     103{
     104    if (pos == std::string::npos)
     105        return false;
     106
     107    unsigned int quotecount = 0;
     108    unsigned int quote = 0;
     109    while ((quote = getNextQuote(str, quote)) < pos)
     110    {
     111        quotecount++;
     112    }
     113
     114    if (quote == std::string::npos)
     115        return false;
     116
     117    return ((quotecount % 2) == 1);
    94118}
    95119
     
    124148    @brief Removes enclosing quotes if available.
    125149    @brief str The string to strip
    126 */
    127 void stripEnclosingQuotes(std::string* str)
     150    @return The string with removed quotes
     151*/
     152std::string stripEnclosingQuotes(const std::string& str)
    128153{
    129154    unsigned int start = std::string::npos;
    130155    unsigned int end = 0;
    131156
    132     for (unsigned int pos = 0; (pos < (*str).size()) && (pos < std::string::npos); pos++)
    133     {
    134         if ((*str)[pos] == '"')
     157    for (unsigned int pos = 0; (pos < str.size()) && (pos < std::string::npos); pos++)
     158    {
     159        if (str[pos] == '"')
    135160        {
    136161            start = pos;
     
    138163        }
    139164
    140         if (((*str)[pos] != ' ') && ((*str)[pos] != '\t') && ((*str)[pos] != '\n'))
    141             return;
    142     }
    143 
    144     for (unsigned int pos = (*str).size() - 1; pos < std::string::npos; pos--)
    145     {
    146         if ((*str)[pos] == '"')
     165        if ((str[pos] != ' ') && (str[pos] != '\t') && (str[pos] != '\n'))
     166            return str;
     167    }
     168
     169    for (unsigned int pos = str.size() - 1; pos < std::string::npos; pos--)
     170    {
     171        if (str[pos] == '"')
    147172        {
    148173            end = pos;
     
    150175        }
    151176
    152         if (((*str)[pos] != ' ') && ((*str)[pos] != '\t') && ((*str)[pos] != '\n'))
    153             return;
     177        if ((str[pos] != ' ') && (str[pos] != '\t') && (str[pos] != '\n'))
     178            return str;
    154179    }
    155180
    156181    if ((start != std::string::npos) && (end != 0))
    157         (*str) = (*str).substr(start + 1, end - start - 1);
    158 }
    159 
    160 /**
    161     @brief Returns a copy of the string with removed enclosing quotes (if available).
    162     @brief str The string to strip
    163     @return The striped copy of the string
    164 */
    165 std::string getStrippedEnclosingQuotes(const std::string& str)
    166 {
    167     std::string output = std::string(str);
    168     stripEnclosingQuotes(&output);
    169     return output;
     182        return str.substr(start + 1, end - start - 1);
     183    else
     184        return str;
    170185}
    171186
     
    235250}
    236251
     252std::string addSlashes(const std::string& str)
     253{
     254    std::string output = str;
     255
     256    for (unsigned int pos = 0; (pos = output.find('\\', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\\\"); }
     257    for (unsigned int pos = 0; (pos = output.find('\n', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\n"); }
     258    for (unsigned int pos = 0; (pos = output.find('\t', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\t"); }
     259    for (unsigned int pos = 0; (pos = output.find('\v', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\v"); }
     260    for (unsigned int pos = 0; (pos = output.find('\b', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\b"); }
     261    for (unsigned int pos = 0; (pos = output.find('\r', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\r"); }
     262    for (unsigned int pos = 0; (pos = output.find('\f', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\f"); }
     263    for (unsigned int pos = 0; (pos = output.find('\a', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\a"); }
     264    for (unsigned int pos = 0; (pos = output.find('"', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\\""); }
     265    for (unsigned int pos = 0; (pos = output.find('\0', pos)) < std::string::npos; pos += 2) { output.replace(pos, 2, "\\0"); }
     266
     267    return output;
     268}
     269
     270std::string removeSlashes(const std::string& str)
     271{
     272    if (str.size() == 0)
     273        return str;
     274
     275    std::string output = "";
     276    for (unsigned int pos = 0; pos < str.size() - 1; )
     277    {
     278        if (str[pos] == '\\')
     279        {
     280            if (str[pos + 1] == '\\') { output += '\\'; pos += 2; continue; }
     281            else if (str[pos + 1] == 'n') { output += '\n'; pos += 2; continue; }
     282            else if (str[pos + 1] == 't') { output += '\t'; pos += 2; continue; }
     283            else if (str[pos + 1] == 'v') { output += '\v'; pos += 2; continue; }
     284            else if (str[pos + 1] == 'b') { output += '\b'; pos += 2; continue; }
     285            else if (str[pos + 1] == 'r') { output += '\r'; pos += 2; continue; }
     286            else if (str[pos + 1] == 'f') { output += '\f'; pos += 2; continue; }
     287            else if (str[pos + 1] == 'a') { output += '\a'; pos += 2; continue; }
     288            else if (str[pos + 1] == '"') { output += '"'; pos += 2; continue; }
     289            else if (str[pos + 1] == '0') { output += '\0'; pos += 2; continue; }
     290        }
     291        output += str[pos];
     292        pos++;
     293    }
     294    output += str[str.size() - 1];
     295
     296    return output;
     297}
     298
    237299/**
    238300    @brief Replaces each char between A and Z with its lowercase equivalent.
     
    364426unsigned int getCommentPosition(const std::string& str)
    365427{
    366     for (unsigned int i = 0; i < str.size(); i++)
     428    return getNextCommentPosition(str, 0);
     429}
     430
     431/**
     432    @brief Returns the position of the next comment-symbol, starting with start.
     433    @param str The string
     434    @param start The startposition
     435    @return The position
     436*/
     437unsigned int getNextCommentPosition(const std::string& str, unsigned int start)
     438{
     439    for (unsigned int i = start; i < str.size(); i++)
    367440        if (isComment(str.substr(i)))
    368441            return i;
  • code/branches/core2/src/util/String.h

    r1020 r1049  
    4040
    4141_UtilExport unsigned int getNextQuote(const std::string& str, unsigned int start);
     42_UtilExport bool         isBetweenQuotes(const std::string& str, unsigned int pos);
    4243
    4344_UtilExport bool         hasStringBetweenQuotes(const std::string& str);
    4445_UtilExport std::string  getStringBetweenQuotes(const std::string& str);
    4546
    46 _UtilExport void         stripEnclosingQuotes(std::string* str);
    47 _UtilExport std::string  getStrippedEnclosingQuotes(const std::string& str);
     47_UtilExport std::string  stripEnclosingQuotes(const std::string& str);
    4848
    4949_UtilExport bool         isEmpty(const std::string& str);
    5050_UtilExport bool         isComment(const std::string& str);
    5151_UtilExport bool         isNumeric(const std::string& str);
     52
     53_UtilExport std::string  addSlashes(const std::string& str);
     54_UtilExport std::string  removeSlashes(const std::string& str);
    5255
    5356_UtilExport void         lowercase(std::string* str);
     
    6366_UtilExport std::string  getComment(const std::string& str);
    6467_UtilExport unsigned int getCommentPosition(const std::string& str);
     68_UtilExport unsigned int getNextCommentPosition(const std::string& str, unsigned int start = 0);
    6569
    6670//! The Convert class has some static member functions to convert strings to values and values to strings.
Note: See TracChangeset for help on using the changeset viewer.