Fix [clear_variable];
it now clears key/value pairs, and if an explicit index is not specified, it will clear the whole array.
This commit is contained in:
parent
fba3df7e61
commit
7b39b62eae
1 changed files with 16 additions and 38 deletions
|
@ -768,39 +768,13 @@ void game_state::clear_variable(const std::string& varname)
|
|||
element = std::string(element.begin(),index_start);
|
||||
}
|
||||
|
||||
if(itor == key.end()) {
|
||||
std::string last_element(key);
|
||||
|
||||
size_t index = 0;
|
||||
const std::string::iterator index_start = std::find(last_element.begin(),last_element.end(),'[');
|
||||
const bool explicit_index = index_start != last_element.end();
|
||||
if(explicit_index) {
|
||||
const std::string::iterator index_end = std::find(index_start,last_element.end(),']');
|
||||
const std::string index_str(index_start+1,index_end);
|
||||
index = static_cast<size_t>(lexical_cast_default<int>(index_str));
|
||||
if(index > MaxLoop) {
|
||||
LOG_NG << "clear_variable: index greater than " << MaxLoop
|
||||
<< ", truncated\n";
|
||||
index = MaxLoop;
|
||||
}
|
||||
last_element = std::string(last_element.begin(),index_start);
|
||||
}
|
||||
if(vars->get_children(element).size() <= index) {
|
||||
return;
|
||||
}
|
||||
//std::cerr << "Removing " << last_element << "\n";
|
||||
vars->values.erase(last_element);
|
||||
vars->remove_child(last_element,index);
|
||||
if(vars->get_children(element).size() <= index) {
|
||||
return;
|
||||
}
|
||||
//std::cerr << "Entering " << element << "[" << index << "] of [" << vars->get_children(element).size() << "]\n";
|
||||
vars = vars->get_children(element)[index];
|
||||
if(!vars) {
|
||||
return;
|
||||
} else {
|
||||
if(vars->get_children(element).size() <= index) {
|
||||
return;
|
||||
}
|
||||
//std::cerr << "Entering " << element << "[" << index << "] of [" << vars->get_children(element).size() << "]\n";
|
||||
vars = vars->get_children(element)[index];
|
||||
if(!vars) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
itor = std::find(key.begin(),key.end(),'.');
|
||||
dot_index = key.find('.');
|
||||
|
@ -819,13 +793,17 @@ void game_state::clear_variable(const std::string& varname)
|
|||
}
|
||||
key = std::string(key.begin(),index_start);
|
||||
}
|
||||
|
||||
if(vars->get_children(key).size() <= index) {
|
||||
return;
|
||||
|
||||
if(explicit_index) {
|
||||
if(vars->get_children(key).size() <= index) {
|
||||
return;
|
||||
}
|
||||
//std::cerr << "Removing " << key << "\n";
|
||||
vars->remove_child(key,index);
|
||||
} else {
|
||||
vars->values.erase(key);
|
||||
vars->clear_children(key);
|
||||
}
|
||||
//std::cerr << "Removing " << key << "\n";
|
||||
vars->values.erase(key);
|
||||
vars->remove_child(key,index);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue