Changeset 7235 in orxonox.OLD for branches/preferences/src/lib/parser
- Timestamp:
- Mar 21, 2006, 3:48:37 PM (19 years ago)
- Location:
- branches/preferences/src/lib/parser/ini_parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/preferences/src/lib/parser/ini_parser/ini_parser.cc
r7234 r7235 401 401 * @return true if everything is ok false on error 402 402 */ 403 bool IniParser::editVar(const char* entryName, const char* value, const char*sectionName)403 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName) 404 404 { 405 405 std::list<IniSection>::iterator section; 406 406 407 if ( sectionName != NULL)407 if (!sectionName.empty()) 408 408 { 409 409 for (section = this->sections.begin(); section != this->sections.end(); section++) 410 if ( !strcmp((*section).name, sectionName))410 if ((*section).name == sectionName) 411 411 break; 412 412 } … … 417 417 { 418 418 IniSection sec; 419 sec.comment = NULL; 420 sec.name = new char[strlen(sectionName)+1]; 421 strcpy(sec.name, sectionName); 419 sec.comment = ""; 420 sec.name = sectionName; 422 421 section = this->sections.insert(this->sections.end(), sec); 423 422 } … … 425 424 if (section == this->sections.end()) 426 425 { 427 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName , entryName);426 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str()); 428 427 return false; 429 428 } … … 433 432 std::list<IniEntry>::iterator entry; 434 433 for (entry = section->entries.begin(); entry!=section->entries.end(); entry++) 435 if ( !strcmp( entry->name, entryName ))434 if (entry->name == entryName ) 436 435 break; 437 436 … … 439 438 if ( entry != section->entries.end() ) 440 439 { 441 if ( entry->value != NULL ) 442 { 443 delete[] entry->value; 444 } 445 entry->value = new char[strlen(value)+1]; 446 strcpy(entry->value, value); 440 entry->value = value; 447 441 448 442 return true; … … 451 445 //not found -> create it 452 446 (*section).entries.push_back(IniEntry()); 453 (*section).entries.back().comment = NULL; 454 (*section).entries.back().name = new char[strlen(entryName)+1]; 455 strcpy((*section).entries.back().name, entryName); 456 (*section).entries.back().value = new char[strlen(value)+1]; 457 strcpy((*section).entries.back().value, value); 447 (*section).entries.back().comment = ""; 448 (*section).entries.back().name = entryName; 449 (*section).entries.back().value = value; 458 450 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 459 (*section).entries.back().name ,460 (*section).entries.back().value ,451 (*section).entries.back().name.c_str(), 452 (*section).entries.back().value.c_str(), 461 453 (*section).name); 462 454 this->currentEntry = --(*section).entries.end(); -
branches/preferences/src/lib/parser/ini_parser/ini_parser.h
r7221 r7235 69 69 bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" ); 70 70 const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const; 71 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName = ""); 71 72 void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName); 72 73 const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const;
Note: See TracChangeset
for help on using the changeset viewer.