Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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/orxonox/core
Files:
5 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_ = "";
Note: See TracChangeset for help on using the changeset viewer.