Changeset 222
- Timestamp:
- 02/21/07 22:31:44 (1 year ago)
- Files:
-
- 06/libkombilo/sgfparser.cpp (modified) (9 diffs)
- 06/libkombilo/sgfparser.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/sgfparser.cpp
r210 r222 144 144 145 145 while (i < lSGFstring && s[i] != '[' && IDindex < 30) { 146 if (65 <= s[i] && s[i] <= 90) 146 if (65 <= s[i] && s[i] <= 90) { 147 147 ID[IDindex++] = s[i]; 148 else if (!(97 <= s[i] && s[i] <= 122) && !(s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t')) {148 } else if (!(97 <= s[i] && s[i] <= 122) && (!(s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t'))) { 149 149 throw SGFError(); 150 150 } … … 214 214 } 215 215 216 PropValue::PropValue(std::string IDC, std::vector<std::string>* PV) { 217 IDcomplete = IDC; 218 pv = PV; 219 } 220 221 PropValue::~PropValue() { 222 if (pv) delete pv; 223 } 224 225 216 226 Node::Node(Node* prev, char* SGFst, int lvl=0) throw(SGFError) { 217 227 next = NULL; … … 234 244 } 235 245 246 string remove_lowercase(string s) throw(SGFError) { 247 char ID[s.size()+1]; 248 int IDindex = 0; 249 for(unsigned int i=0; i<s.size(); i++) { 250 if (65 <= s[i] && s[i] <= 90) ID[IDindex++] = s[i]; 251 else if (!(97 <= s[i] && s[i] <= 122)) { 252 throw SGFError(); 253 } 254 } 255 ID[IDindex] = 0; 256 return string(ID); 257 } 258 236 259 vector<string> Node::gpv(const string& prop) { 237 260 vector<string>* result = get_property_value(prop); … … 244 267 parseNode(); 245 268 } 246 map<string, vector<string>* >::iterator result = data.find(prop);269 map<string, PropValue >::iterator result = data.find(remove_lowercase(prop)); 247 270 if (result == data.end()) return 0; 248 else return result->second ;271 else return result->second.pv; 249 272 } 250 273 … … 291 314 char ID[30]; 292 315 int IDindex = 0; 293 294 while (i < lSGFstring && s[i] != '[' && IDindex < 30) { 295 if (65 <= s[i] && s[i] <= 90) 316 char IDcomplete[100]; // store long property name here 317 int IDcompleteIndex = 0; 318 319 while (i < lSGFstring && s[i] != '[' && IDindex < 30 && IDcompleteIndex < 100) { 320 if (65 <= s[i] && s[i] <= 90) { 296 321 ID[IDindex++] = s[i]; 297 else if (!(97 <= s[i] && s[i] <= 122) && !(s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t')) { 322 IDcomplete[IDcompleteIndex++] = s[i]; 323 } else if (97 <= s[i] && s[i] <= 122) { 324 IDcomplete[IDcompleteIndex++] = s[i]; 325 } else if (!(s[i]==' ' || s[i]=='\n' || s[i]=='\r' || s[i]=='\t')) { 298 326 throw SGFError(); 299 327 } … … 302 330 i++; 303 331 304 if (i >= lSGFstring || IDindex >= 30 || !IDindex) throw SGFError(); 332 if (i >= lSGFstring || IDindex >= 30 || !IDindex || IDcompleteIndex >= 100) { 333 throw SGFError(); 334 } 305 335 ID[IDindex] = 0; 336 IDcomplete[IDcompleteIndex] = 0; 306 337 vector<string>* propValueList = new vector<string>; 307 338 … … 352 383 else i++; 353 384 } 354 data.insert(make_pair(string(ID), propValueList));385 data.insert(make_pair(string(ID), PropValue(string(IDcomplete), propValueList))); 355 386 } 356 387 parsed = 1; … … 358 389 } 359 390 360 void Node::set_property_value(string& ID, vector<string>* propValue) throw(SGFError) { 361 map<string, vector<string>* >::iterator it = data.find(ID); 362 if (it == data.end()) data.insert(make_pair(ID, propValue)); 363 else it->second->insert(it->second->end(), propValue->begin(), propValue->end()); 391 void Node::set_property_value(string& IDcomplete, vector<string>* propValue) throw(SGFError) { 392 string ID = remove_lowercase(IDcomplete); 393 map<string, PropValue >::iterator it = data.find(ID); 394 if (it == data.end()) data.insert(make_pair(ID, PropValue(IDcomplete, propValue))); 395 else it->second.pv->insert(it->second.pv->end(), propValue->begin(), propValue->end()); 364 396 SGFstring = nodeToString(data); 365 397 parsed = 1; … … 877 909 // } 878 910 879 string nodeToString(map<string, vector<string>*>& data) throw(SGFError) {911 string nodeToString(map<string, PropValue >& data) throw(SGFError) { 880 912 string result = ";"; 881 913 int l = 0; 882 for(map<string, vector<string>*>::iterator kv = data.begin(); kv != data.end(); kv++) {883 if (!kv->second || !kv->second->size()) continue;884 885 result += kv-> first;886 for(vector<string>::iterator it = kv->second ->begin(); it != kv->second->end(); it++) {914 for(map<string, PropValue >::iterator kv = data.begin(); kv != data.end(); kv++) { 915 if (!kv->second.pv || !kv->second.pv->size()) continue; 916 917 result += kv->second.IDcomplete; 918 for(vector<string>::iterator it = kv->second.pv->begin(); it != kv->second.pv->end(); it++) { 887 919 char* t = SGFescape(it->c_str()); 888 920 result += "["; 06/libkombilo/sgfparser.h
r195 r222 59 59 char* SGFescape(const char* s); 60 60 61 class PropValue { 62 public: 63 PropValue(std::string IDC, std::vector<std::string>* PV); 64 ~PropValue(); 65 std::string IDcomplete; 66 std::vector<std::string>* pv; 67 }; 68 61 69 class Node { 62 70 public: … … 71 79 std::vector<std::string> gpv(const std::string& prop); 72 80 std::vector<std::string>* get_property_value(const std::string& prop); 73 void set_property_value(std::string& ID , std::vector<std::string>* propValue) throw(SGFError);81 void set_property_value(std::string& IDcomplete, std::vector<std::string>* propValue) throw(SGFError); 74 82 75 83 int posyD; // used when displaying SGF structure graphically as a tree … … 81 89 static int sloppy; 82 90 private: 83 std::map<std::string, std::vector<std::string>*> data; // use get_property_value to access this91 std::map<std::string, PropValue> data; // use get_property_value to access this 84 92 }; 85 93 … … 120 128 }; 121 129 122 std::string nodeToString(std::map<std::string, std::vector<std::string>*>& data) throw(SGFError);130 std::string nodeToString(std::map<std::string, PropValue >& data) throw(SGFError); 123 131 // char* rootNodeToString(PyObject* data); 124 132
