- Timestamp:
- Apr 14, 2008, 12:48:25 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/ConfigFileManager.cc
r1030 r1049 66 66 // ConfigFileEntryValue // 67 67 ////////////////////////// 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 68 85 std::string ConfigFileEntryValue::getFileEntry() const 69 86 { … … 130 147 } 131 148 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) 133 150 { 134 151 for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) 152 { 135 153 if ((*it)->getName() == name) 154 { 155 (*it)->setString(bString); 136 156 return it; 157 } 158 } 137 159 138 160 this->bUpdated_ = true; 139 161 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) 144 166 { 145 167 for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) 168 { 146 169 if (((*it)->getName() == name) && ((*it)->getIndex() == index)) 170 { 171 (*it)->setString(bString); 147 172 return it; 173 } 174 } 148 175 149 176 this->bUpdated_ = true; 150 177 151 178 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))); 155 182 } 156 183 … … 233 260 unsigned int pos2 = line.find('['); 234 261 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)) 241 264 { 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)); 245 271 } 246 272 else 247 273 { 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)); 252 276 } 253 277 … … 259 283 { 260 284 // 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); 262 286 (*it)->setValue(value); 263 287 (*it)->setComment(comment); … … 267 291 268 292 // 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)); 270 294 continue; 271 295 }
Note: See TracChangeset
for help on using the changeset viewer.