- Timestamp:
- May 17, 2007, 8:49:09 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Trac.cc
r309 r317 36 36 {} 37 37 38 std::string Trac::anchor_text(std::string::const_iterator first, 39 std::string::const_iterator last, 40 std::string::const_iterator last_trunc) 41 { 42 if (last>last_trunc) { // truncate 43 std::string str(first, last_trunc); 44 str+="..."; 45 return str; 46 } 47 return std::string(first, last); 48 } 49 50 38 51 bool Trac::changeset(std::string::const_iterator& first, 39 const std::string::const_iterator& last) 40 { 41 if (changeset1(first, last)) 42 return true; 43 if (changeset2(first, last)) 44 return true; 45 if (changeset3(first, last)) 52 const std::string::const_iterator& last, 53 const std::string::const_iterator& last_trunc) 54 { 55 if (changeset1(first, last, last_trunc)) 56 return true; 57 if (changeset2(first, last, last_trunc)) 58 return true; 59 if (changeset3(first, last, last_trunc)) 46 60 return true; 47 61 return false; … … 50 64 51 65 bool Trac::changeset1(std::string::const_iterator& first, 52 const std::string::const_iterator& last) 66 const std::string::const_iterator& last, 67 const std::string::const_iterator& last_trunc) 53 68 { 54 69 if (first==last) … … 64 79 } 65 80 std::string href(Configuration::instance().trac_root()+"changeset/"+rev); 66 hs_.stream() << anchor(href, std::string(first_orig,first));81 hs_.stream() << anchor(href, anchor_text(first_orig, first, last_trunc)); 67 82 return true; 68 83 } … … 70 85 71 86 bool Trac::changeset2(std::string::const_iterator& first, 72 const std::string::const_iterator& last) 87 const std::string::const_iterator& last, 88 const std::string::const_iterator& last_trunc) 73 89 { 74 90 if (first==last) … … 85 101 ++first; 86 102 std::string href(Configuration::instance().trac_root()+"changeset/"+rev); 87 hs_.stream() << anchor(href, std::string(first_orig,first));103 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 88 104 return true; 89 105 } … … 91 107 92 108 bool Trac::changeset3(std::string::const_iterator& first, 93 const std::string::const_iterator& last) 109 const std::string::const_iterator& last, 110 const std::string::const_iterator& last_trunc) 94 111 { 95 112 if (first==last) … … 106 123 } 107 124 std::string href(Configuration::instance().trac_root()+"changeset/"+rev); 108 hs_.stream() << anchor(href, std::string(first_orig,first));125 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 109 126 return true; 110 127 } … … 112 129 113 130 bool Trac::comment(std::string::const_iterator& first, 114 const std::string::const_iterator& last) 131 const std::string::const_iterator& last, 132 const std::string::const_iterator& last_trunc) 115 133 { 116 134 if (first==last) … … 136 154 std::string href(Configuration::instance().trac_root()+"ticket/"+ticket+ 137 155 "#comment:"+comment); 138 std::string str(first_orig, first); 139 hs_.stream() << anchor(href, str); 140 return true; 141 142 143 const Configuration& conf = Configuration::instance(); 144 hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket+ 145 "#comment:"+comment, 146 std::string(first_orig, first)); 147 return true; 148 156 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 157 return true; 149 158 } 150 159 151 160 152 161 bool Trac::diff(std::string::const_iterator& first, 153 const std::string::const_iterator& last) 154 { 155 if (diff3(first, last)) 156 return true; 157 if (diff1(first, last)) 158 return true; 159 if (diff2(first, last)) 162 const std::string::const_iterator& last, 163 const std::string::const_iterator& last_trunc) 164 { 165 if (diff3(first, last, last_trunc)) 166 return true; 167 if (diff1(first, last, last_trunc)) 168 return true; 169 if (diff2(first, last, last_trunc)) 160 170 return true; 161 171 return false; … … 164 174 165 175 bool Trac::diff1(std::string::const_iterator& first, 166 const std::string::const_iterator& last) 176 const std::string::const_iterator& last, 177 const std::string::const_iterator& last_trunc) 167 178 { 168 179 if (first==last) … … 199 210 "changeset?new="+new_rev+"&new_path="+node+"&old="+ 200 211 old_rev+"&old_path="+node); 201 hs_.stream() << anchor(href, std::string(first_orig, first));212 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 202 213 return true; 203 214 } … … 205 216 206 217 bool Trac::diff2(std::string::const_iterator& first, 207 const std::string::const_iterator& last) 218 const std::string::const_iterator& last, 219 const std::string::const_iterator& last_trunc) 208 220 { 209 221 if (first==last) … … 229 241 std::string href(Configuration::instance().trac_root()+ 230 242 "changeset?new_path="+new_path+"&old_path="+old_path); 231 hs_.stream() << anchor(href, std::string(first_orig, first));243 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 232 244 return true; 233 245 } … … 235 247 236 248 bool Trac::diff3(std::string::const_iterator& first, 237 const std::string::const_iterator& last) 249 const std::string::const_iterator& last, 250 const std::string::const_iterator& last_trunc) 238 251 { 239 252 if (first==last) … … 271 284 "changeset?new="+new_rev+"&new_path="+new_path+ 272 285 "&old="+old_rev+"&old_path="+old_path); 273 hs_.stream() << anchor(href, std::string(first_orig, first));286 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 274 287 return true; 275 288 } … … 277 290 278 291 bool Trac::log(std::string::const_iterator& first, 279 const std::string::const_iterator& last) 280 { 281 if (log1(first, last)) 282 return true; 283 if (log2(first, last)) 284 return true; 285 if (log3(first, last)) 292 const std::string::const_iterator& last, 293 const std::string::const_iterator& last_trunc) 294 { 295 if (log1(first, last, last_trunc)) 296 return true; 297 if (log2(first, last, last_trunc)) 298 return true; 299 if (log3(first, last, last_trunc)) 286 300 return true; 287 301 return false; … … 290 304 291 305 bool Trac::log1(std::string::const_iterator& first, 292 const std::string::const_iterator& last) 306 const std::string::const_iterator& last, 307 const std::string::const_iterator& last_trunc) 293 308 { 294 309 if (first==last) … … 313 328 std::string href(Configuration::instance().trac_root()+"log/?rev="+ 314 329 rev+"&stop_rev="+stop_rev); 315 hs_.stream() << anchor(href, std::string(first_orig, first));330 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 316 331 return true; 317 332 } … … 319 334 320 335 bool Trac::log2(std::string::const_iterator& first, 321 const std::string::const_iterator& last) 336 const std::string::const_iterator& last, 337 const std::string::const_iterator& last_trunc) 322 338 { 323 339 if (first==last) … … 343 359 std::string href(Configuration::instance().trac_root()+"log/?rev="+ 344 360 rev+"&stop_rev="+stop_rev); 345 hs_.stream() << anchor(href, std::string(first_orig, first));361 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 346 362 return true; 347 363 } … … 349 365 350 366 bool Trac::log3(std::string::const_iterator& first, 351 const std::string::const_iterator& last) 367 const std::string::const_iterator& last, 368 const std::string::const_iterator& last_trunc) 352 369 { 353 370 if (first==last) … … 383 400 "?rev="+rev+"&stop_rev="+stop_rev); 384 401 385 hs_.stream() << anchor(href, std::string(first_orig, first));402 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 386 403 return true; 387 404 } … … 389 406 390 407 bool Trac::milestone(std::string::const_iterator& first, 391 const std::string::const_iterator& last) 408 const std::string::const_iterator& last, 409 const std::string::const_iterator& last_trunc) 392 410 { 393 411 if (first==last) … … 415 433 416 434 const Configuration& conf = Configuration::instance(); 417 hs_.stream() << anchor(conf.trac_root()+"milestone/"+milestone,418 std::string(first_orig, first));419 return true; 420 } 421 422 423 void Trac::print(std::string str )435 std::string href(conf.trac_root()+"milestone/"+milestone); 436 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 437 return true; 438 } 439 440 441 void Trac::print(std::string str, size_t width) 424 442 { 425 443 std::string::const_iterator first(str.begin()); 426 while (first!=str.end()) { 427 if (log(first, str.end())) 428 continue; 429 if (comment(first, str.end())) 430 continue; 431 if (ticket(first, str.end())) 432 continue; 433 if (changeset(first, str.end())) 434 continue; 435 if (diff(first, str.end())) 436 continue; 437 if (milestone(first, str.end())) 438 continue; 439 if (source(first, str.end())) 444 std::string::const_iterator last_trunc(str.end()); 445 if (width<=str.size()) // truncate 446 last_trunc = first+width; 447 while (first<last_trunc) { 448 if (log(first, str.end(), last_trunc)) 449 continue; 450 if (comment(first, str.end(), last_trunc)) 451 continue; 452 if (ticket(first, str.end(), last_trunc)) 453 continue; 454 if (changeset(first, str.end(), last_trunc)) 455 continue; 456 if (diff(first, str.end(), last_trunc)) 457 continue; 458 if (milestone(first, str.end(), last_trunc)) 459 continue; 460 if (source(first, str.end(), last_trunc)) 440 461 continue; 441 462 hs_ << *first; 442 463 ++first; 443 464 } 465 if (last_trunc!=str.end()) 466 hs_ << "..."; 444 467 } 445 468 446 469 447 470 bool Trac::source(std::string::const_iterator& first, 448 const std::string::const_iterator& last) 471 const std::string::const_iterator& last, 472 const std::string::const_iterator& last_trunc) 449 473 { 450 474 if (first==last) … … 483 507 href += "#"+line; 484 508 } 485 hs_.stream() << anchor(href, std::string(first_orig, first));509 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 486 510 return true; 487 511 } … … 489 513 490 514 bool Trac::ticket(std::string::const_iterator& first, 491 const std::string::const_iterator& last) 492 { 493 if (ticket1(first, last)) 494 return true; 495 if (ticket2(first, last)) 515 const std::string::const_iterator& last, 516 const std::string::const_iterator& last_trunc) 517 { 518 if (ticket1(first, last, last_trunc)) 519 return true; 520 if (ticket2(first, last, last_trunc)) 496 521 return true; 497 522 return false; … … 500 525 501 526 bool Trac::ticket1(std::string::const_iterator& first, 502 const std::string::const_iterator& last) 527 const std::string::const_iterator& last, 528 const std::string::const_iterator& last_trunc) 503 529 { 504 530 if (first==last) … … 518 544 const Configuration& conf = Configuration::instance(); 519 545 hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket, 520 std::string(first_orig, first));546 anchor_text(first_orig,first, last_trunc)); 521 547 return true; 522 548 } … … 524 550 525 551 bool Trac::ticket2(std::string::const_iterator& first, 526 const std::string::const_iterator& last) 552 const std::string::const_iterator& last, 553 const std::string::const_iterator& last_trunc) 527 554 { 528 555 if (first==last) … … 538 565 539 566 const Configuration& conf = Configuration::instance(); 540 hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,541 std::string(first_orig, first));567 std::string href(conf.trac_root()+"ticket/"+ticket); 568 hs_.stream() << anchor(href, anchor_text(first_orig,first, last_trunc)); 542 569 return true; 543 570 } -
trunk/lib/Trac.h
r309 r317 47 47 /// 48 48 /// 49 void print(std::string str );49 void print(std::string str, size_t width); 50 50 51 51 private: 52 /** 53 */ 54 std::string anchor_text(std::string::const_iterator first, 55 std::string::const_iterator last, 56 std::string::const_iterator last_trunc); 52 57 /// 53 58 /// @see changeset1 changeset2 changeset3 … … 56 61 /// 57 62 bool changeset(std::string::const_iterator& first, 58 const std::string::const_iterator& last); 63 const std::string::const_iterator& last, 64 const std::string::const_iterator& last_trunc); 59 65 60 66 /// … … 69 75 /// 70 76 bool changeset1(std::string::const_iterator& first, 71 const std::string::const_iterator& last); 77 const std::string::const_iterator& last, 78 const std::string::const_iterator& last_trunc); 72 79 73 80 /// … … 82 89 /// 83 90 bool changeset2(std::string::const_iterator& first, 84 const std::string::const_iterator& last); 91 const std::string::const_iterator& last, 92 const std::string::const_iterator& last_trunc); 85 93 86 94 /// … … 95 103 /// 96 104 bool changeset3(std::string::const_iterator& first, 97 const std::string::const_iterator& last); 105 const std::string::const_iterator& last, 106 const std::string::const_iterator& last_trunc); 98 107 99 108 /// … … 108 117 /// 109 118 bool comment(std::string::const_iterator& first, 110 const std::string::const_iterator& last); 119 const std::string::const_iterator& last, 120 const std::string::const_iterator& last_trunc); 111 121 112 122 /// … … 116 126 /// 117 127 bool diff(std::string::const_iterator& first, 118 const std::string::const_iterator& last); 128 const std::string::const_iterator& last, 129 const std::string::const_iterator& last_trunc); 119 130 120 131 /// … … 133 144 /// 134 145 bool diff1(std::string::const_iterator& first, 135 const std::string::const_iterator& last); 146 const std::string::const_iterator& last, 147 const std::string::const_iterator& last_trunc); 136 148 137 149 /// … … 151 163 /// 152 164 bool diff2(std::string::const_iterator& first, 153 const std::string::const_iterator& last); 165 const std::string::const_iterator& last, 166 const std::string::const_iterator& last_trunc); 154 167 155 168 /// … … 167 180 /// 168 181 bool diff3(std::string::const_iterator& first, 169 const std::string::const_iterator& last); 182 const std::string::const_iterator& last, 183 const std::string::const_iterator& last_trunc); 170 184 171 185 … … 176 190 /// 177 191 bool log(std::string::const_iterator& first, 178 const std::string::const_iterator& last); 192 const std::string::const_iterator& last, 193 const std::string::const_iterator& last_trunc); 179 194 180 195 /// … … 191 206 /// 192 207 bool log1(std::string::const_iterator& first, 193 const std::string::const_iterator& last); 208 const std::string::const_iterator& last, 209 const std::string::const_iterator& last_trunc); 194 210 195 211 /// … … 206 222 /// 207 223 bool log2(std::string::const_iterator& first, 208 const std::string::const_iterator& last); 224 const std::string::const_iterator& last, 225 const std::string::const_iterator& last_trunc); 209 226 210 227 /// … … 221 238 /// 222 239 bool log3(std::string::const_iterator& first, 223 const std::string::const_iterator& last); 240 const std::string::const_iterator& last, 241 const std::string::const_iterator& last_trunc); 224 242 225 243 /// … … 236 254 /// 237 255 bool milestone(std::string::const_iterator& first, 238 const std::string::const_iterator& last); 256 const std::string::const_iterator& last, 257 const std::string::const_iterator& last_trunc); 239 258 240 259 /// … … 255 274 /// 256 275 bool source(std::string::const_iterator& first, 257 const std::string::const_iterator& last); 276 const std::string::const_iterator& last, 277 const std::string::const_iterator& last_trunc); 258 278 259 279 /// … … 263 283 /// 264 284 bool ticket(std::string::const_iterator& first, 265 const std::string::const_iterator& last); 285 const std::string::const_iterator& last, 286 const std::string::const_iterator& last_trunc); 266 287 267 288 /// … … 278 299 /// 279 300 bool ticket1(std::string::const_iterator& first, 280 const std::string::const_iterator& last); 301 const std::string::const_iterator& last, 302 const std::string::const_iterator& last_trunc); 281 303 282 304 /// … … 293 315 /// 294 316 bool ticket2(std::string::const_iterator& first, 295 const std::string::const_iterator& last); 317 const std::string::const_iterator& last, 318 const std::string::const_iterator& last_trunc); 296 319 297 320 -
trunk/lib/first_page.cc
r312 r317 182 182 std::replace(mess.begin(), mess.end(), '\n', ' '); 183 183 mess = htrim(mess); 184 // truncate message if too long 185 if ( mess.size()>maxlength)186 mess = mess.substr(0,maxlength-3) + "...";187 188 if (conf.trac_root().empty())184 185 if (conf.trac_root().empty()) { 186 // truncate message if too long 187 if (mess.size()>maxlength) 188 mess = mess.substr(0,maxlength-3) + "..."; 189 189 hs << mess; 190 } 190 191 else {// make anchors to trac 191 192 Trac trac(hs); 192 trac.print(mess );193 trac.print(mess, maxlength); 193 194 } 194 195 -
trunk/test/trac.cc
r309 r317 88 88 HtmlStream html(ss); 89 89 Trac trac(html); 90 trac.print(mess );90 trac.print(mess,80); 91 91 if (ss.str()==anchor(href, mess)) 92 92 return true;
Note: See TracChangeset
for help on using the changeset viewer.