Changeset 354 for trunk/gsdl/src/recpt/formattools.cpp
- Timestamp:
- 1999-07-09T08:48:33+12:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/formattools.cpp
r347 r354 12 12 /* 13 13 $Log$ 14 Revision 1.2 1999/07/08 20:48:33 rjmcnab 15 Added ability to print the result number 16 14 17 Revision 1.1 1999/07/07 05:49:34 sjboddie 15 18 had another crack at the format string code - created a new formattools … … 21 24 22 25 #include "formattools.h" 26 27 28 29 30 31 // a few function prototypes 32 static text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr); 33 34 static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 35 format_t *formatlistptr, text_tarray &metadata, bool &getParents, 36 text_tmap &metamap, int &metacount); 37 23 38 24 39 … … 48 63 49 64 50 bool parse_string (const text_t &formatstring, format_t *formatlistptr, 51 text_tarray &metadata, bool &getParents, 52 text_tmap &metamap, int &metacount) { 65 66 67 static void get_parent_options (text_t &instring, metadata_t &metaoption) { 68 69 metaoption.clear(); 70 text_t meta, com, op; 71 bool inbraces = false; 72 bool inquotes = false; 73 bool foundcolon = false; 74 text_t::const_iterator here = instring.begin()+6; 75 text_t::const_iterator end = instring.end(); 76 while (here != end) { 77 if (*here == '(') inbraces = true; 78 else if (*here == ')') inbraces = false; 79 else if (*here == '\'' && !inquotes) inquotes = true; 80 else if (*here == '\'' && inquotes) inquotes = false; 81 else if (*here == ':' && !inbraces) foundcolon = true; 82 else if (foundcolon) meta.push_back (*here); 83 else if (inquotes) op.push_back (*here); 84 else com.push_back (*here); 85 here ++; 86 } 87 instring = meta; 88 if (com.empty()) 89 metaoption.parentcommand = pImmediate; 90 else if (com == "Top") 91 metaoption.parentcommand = pTop; 92 else if (is_number(com)) { 93 metaoption.parentcommand = pIndex; 94 metaoption.metaindex = com.getint(); 95 } else if (com == "All") { 96 metaoption.parentcommand = pAll; 97 metaoption.parentoptions = op; 98 } 99 } 100 101 static bool parse_meta (text_t &meta, int &count, decision_t &decision, 102 text_tarray &metadata, bool &getParents, text_tmap &metamap) { 103 104 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 105 getParents = true; 106 metadata_t metaoption; 107 get_parent_options (meta, metaoption); 108 decision.meta = metaoption; 109 } 110 text_tmap::const_iterator it; 111 if ((it = metamap.find(meta)) != metamap.end()) { 112 decision.meta.metaindex = (*it).second.getint(); 113 } else { 114 metamap[meta] = count; 115 metadata.push_back (meta); 116 decision.meta.metaindex = count; 117 count ++; 118 } 119 return true; 120 } 121 122 static bool parse_meta (text_t &meta, int &count, format_t *formatlistptr, 123 text_tarray &metadata, bool &getParents, text_tmap &metamap) { 124 125 if (meta == "link") 126 formatlistptr->command = comLink; 127 else if (meta == "/link") 128 formatlistptr->command = comEndLink; 129 130 else if (meta == "num") 131 formatlistptr->command = comNum; 132 133 else { 134 formatlistptr->command = comMeta; 135 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 136 getParents = true; 137 metadata_t metaoption; 138 get_parent_options (meta, metaoption); 139 formatlistptr->meta = metaoption; 140 } 141 text_tmap::const_iterator it; 142 if ((it = metamap.find(meta)) != metamap.end()) { 143 (formatlistptr->meta).metaindex = (*it).second.getint(); 144 } else { 145 metamap[meta] = count; 146 metadata.push_back (meta); 147 (formatlistptr->meta).metaindex = count; 148 count ++; 149 } 150 } 151 return true; 152 } 153 154 static bool parse_string (const text_t &formatstring, format_t *formatlistptr, 155 text_tarray &metadata, bool &getParents, 156 text_tmap &metamap, int &metacount) { 53 157 54 158 text_t text; … … 112 216 } 113 217 114 bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 115 format_t *formatlistptr, text_tarray &metadata, bool &getParents, 116 text_tmap &metamap, int &metacount) { 218 219 static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 220 format_t *formatlistptr, text_tarray &metadata, bool &getParents, 221 text_tmap &metamap, int &metacount) { 117 222 118 223 text_t::const_iterator it = findchar (here, end, '}'); … … 215 320 } 216 321 322 217 323 bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr, 218 324 text_tarray &metadata, bool &getParents) { … … 228 334 } 229 335 230 bool parse_meta (text_t &meta, int &count, decision_t &decision, 231 text_tarray &metadata, bool &getParents, text_tmap &metamap) { 232 233 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 234 getParents = true; 235 metadata_t metaoption; 236 get_parent_options (meta, metaoption); 237 decision.meta = metaoption; 238 } 239 text_tmap::const_iterator it; 240 if ((it = metamap.find(meta)) != metamap.end()) { 241 decision.meta.metaindex = (*it).second.getint(); 242 } else { 243 metamap[meta] = count; 244 metadata.push_back (meta); 245 decision.meta.metaindex = count; 246 count ++; 247 } 248 return true; 249 } 250 251 bool parse_meta (text_t &meta, int &count, format_t *formatlistptr, 252 text_tarray &metadata, bool &getParents, text_tmap &metamap) { 253 254 if (meta == "link") 255 formatlistptr->command = comLink; 256 else if (meta == "/link") 257 formatlistptr->command = comEndLink; 258 259 else { 260 formatlistptr->command = comMeta; 261 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 262 getParents = true; 263 metadata_t metaoption; 264 get_parent_options (meta, metaoption); 265 formatlistptr->meta = metaoption; 266 } 267 text_tmap::const_iterator it; 268 if ((it = metamap.find(meta)) != metamap.end()) { 269 (formatlistptr->meta).metaindex = (*it).second.getint(); 270 } else { 271 metamap[meta] = count; 272 metadata.push_back (meta); 273 (formatlistptr->meta).metaindex = count; 274 count ++; 275 } 276 } 277 return true; 278 } 279 280 void get_parent_options (text_t &instring, metadata_t &metaoption) { 281 282 metaoption.clear(); 283 text_t meta, com, op; 284 bool inbraces = false; 285 bool inquotes = false; 286 bool foundcolon = false; 287 text_t::const_iterator here = instring.begin()+6; 288 text_t::const_iterator end = instring.end(); 289 while (here != end) { 290 if (*here == '(') inbraces = true; 291 else if (*here == ')') inbraces = false; 292 else if (*here == '\'' && !inquotes) inquotes = true; 293 else if (*here == '\'' && inquotes) inquotes = false; 294 else if (*here == ':' && !inbraces) foundcolon = true; 295 else if (foundcolon) meta.push_back (*here); 296 else if (inquotes) op.push_back (*here); 297 else com.push_back (*here); 298 here ++; 299 } 300 instring = meta; 301 if (com.empty()) 302 metaoption.parentcommand = pImmediate; 303 else if (com == "Top") 304 metaoption.parentcommand = pTop; 305 else if (is_number(com)) { 306 metaoption.parentcommand = pIndex; 307 metaoption.metaindex = com.getint(); 308 } else if (com == "All") { 309 metaoption.parentcommand = pAll; 310 metaoption.parentoptions = op; 311 } 312 } 313 314 text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta) { 336 337 338 static text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta) { 315 339 int metasize = docinfo.metadata.size(); 316 340 int mindex = meta.metaindex; … … 353 377 } 354 378 355 356 text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) { 357 358 text_t ft; 359 while (formatlistptr != NULL) { 360 ft += format_string (docinfo, formatlistptr); 361 formatlistptr = formatlistptr->nextptr; 362 } 363 return ft; 364 } 365 366 text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) { 379 static text_t get_or (const ResultDocInfo_t &docinfo, format_t *orptr) { 380 381 text_t tmp; 382 while (orptr != NULL) { 383 384 tmp = format_string (docinfo, orptr); 385 if (!tmp.empty()) return tmp; 386 387 orptr = orptr->nextptr; 388 } 389 return ""; 390 } 391 392 static text_t get_if (const ResultDocInfo_t &docinfo, const decision_t &decision, 393 format_t *ifptr, format_t *elseptr) { 394 395 // not much of a choice yet ... 396 if (decision.command == dMeta) { 397 if (get_meta (docinfo, decision.meta) != "") { 398 if (ifptr != NULL) 399 return get_formatted_string (docinfo, ifptr); 400 } 401 else { 402 if (elseptr != NULL) 403 return get_formatted_string (docinfo, elseptr); 404 } 405 } 406 return ""; 407 } 408 409 static text_t format_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) { 367 410 368 411 if (formatlistptr == NULL) return ""; … … 375 418 case comEndLink: 376 419 return "</a>"; 420 case comNum: 421 return docinfo.result_num; 377 422 case comMeta: 378 423 return get_meta (docinfo, formatlistptr->meta); … … 386 431 387 432 388 text_t get_or (const ResultDocInfo_t &docinfo, format_t *orptr) { 389 390 text_t tmp; 391 while (orptr != NULL) { 392 393 tmp = format_string (docinfo, orptr); 394 if (!tmp.empty()) return tmp; 395 396 orptr = orptr->nextptr; 397 } 398 return ""; 399 } 400 401 text_t get_if (const ResultDocInfo_t &docinfo, const decision_t &decision, 402 format_t *ifptr, format_t *elseptr) { 403 404 // not much of a choice yet ... 405 if (decision.command == dMeta) { 406 if (get_meta (docinfo, decision.meta) != "") { 407 if (ifptr != NULL) 408 return get_formatted_string (docinfo, ifptr); 409 } 410 else { 411 if (elseptr != NULL) 412 return get_formatted_string (docinfo, elseptr); 413 } 414 } 415 return ""; 416 } 417 433 434 text_t get_formatted_string (const ResultDocInfo_t &docinfo, format_t *formatlistptr) { 435 436 text_t ft; 437 while (formatlistptr != NULL) { 438 ft += format_string (docinfo, formatlistptr); 439 formatlistptr = formatlistptr->nextptr; 440 } 441 return ft; 442 } 443 444 445 446
Note:
See TracChangeset
for help on using the changeset viewer.