yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #04333
[Branch ~yade-dev/yade/trunk] Rev 2212: 1. Fix O.tags with keys with spaces (historical relics)
------------------------------------------------------------
revno: 2212
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-05-10 13:06:45 +0200
message:
1. Fix O.tags with keys with spaces (historical relics)
modified:
py/yadeWrapper/yadeWrapper.cpp
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'py/yadeWrapper/yadeWrapper.cpp'
--- py/yadeWrapper/yadeWrapper.cpp 2010-05-03 13:58:09 +0000
+++ py/yadeWrapper/yadeWrapper.cpp 2010-05-10 11:06:45 +0000
@@ -139,23 +139,26 @@
pyTags(const shared_ptr<Scene> _mb): mb(_mb){}
const shared_ptr<Scene> mb;
bool hasKey(const string& key){ FOREACH(string val, mb->tags){ if(algorithm::starts_with(val,key+"=")){ return true;} } return false; }
- string getItem(string key){
+ string getItem(const string& key){
FOREACH(string& val, mb->tags){
- if(algorithm::starts_with(val,key+"=")){ string val1(val); algorithm::erase_head(val1,key.size()+1); algorithm::replace_all(val1,"~"," "); return val1;}
+ if(algorithm::starts_with(val,key+"=")){ string val1(val); algorithm::erase_head(val1,key.size()+1); return val1;}
}
PyErr_SetString(PyExc_KeyError, "Invalid key.");
python::throw_error_already_set(); /* make compiler happy; never reached */ return string();
}
- void setItem(string key,string newVal){
- string item=algorithm::replace_all_copy(key+"="+newVal," ","~");
+ void setItem(const string& key,const string& item){
+ if(key.find("=")!=string::npos) {
+ PyErr_SetString(PyExc_KeyError, "Key must not contain the '=' character (implementation limitation; sorry).");
+ python::throw_error_already_set();
+ }
FOREACH(string& val, mb->tags){if(algorithm::starts_with(val,key+"=")){ val=item; return; } }
- mb->tags.push_back(item);
+ mb->tags.push_back(key+"="+item);
}
python::list keys(){
python::list ret;
FOREACH(string val, mb->tags){
size_t i=val.find("=");
- if(i==string::npos) throw runtime_error("Tags must be in the key=value format");
+ if(i==string::npos) throw runtime_error("Tags must be in the key=value format (internal error?)");
algorithm::erase_tail(val,val.size()-i); ret.append(val);
}
return ret;
Follow ups