ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Search/Outputer.cpp
(Generate patch)

Comparing trunk/Search/Outputer.cpp (file contents):
Revision 206 by douglas, 2003-07-17T00:13:45-07:00 vs.
Revision 211 by douglas, 2003-07-19T18:46:12-07:00

# Line 46 | Line 46
46   //
47   // Douglas Thrift
48   //
49 < // $Id: Outputer.cpp,v 1.9 2003/07/17 07:13:45 douglas Exp $
49 > // $Id: Outputer.cpp,v 1.11 2003/07/20 01:46:12 douglas Exp $
50  
51   #include "Outputer.h"
52  
# Line 137 | Line 137 | void Outputer::header(const string& quer
137                          platform());
138   #else
139                  tag(line, "<?version?>", programName + ' ' + programVersion + ' ' +
140 <                        platform() + ' ' + openssl(true));
140 >                        platform() + ' ' + openssl());
141   #endif
142                  tag(line, "<?query?>", query);
143                  tag(line, "<?range?>", range(page));
# Line 171 | Line 171 | void Outputer::body()
171                  string address = webpage.getURL();
172                  string sample = webpage.getSample();
173                  string description = webpage.getDescription();
174 +                ostringstream size;
175  
176 <                char* csize = new char[1024];
177 <                sprintf(csize, "%.0fk", (double(webpage.getSize()) / double(1024)));
178 <
178 <                string size = csize;
179 <
180 <                delete [] csize;
176 >                size.precision(0);
177 >                size.setf(ios_base::fixed, ios_base::floatfield);
178 >                size << double(webpage.getSize()) / double(1024) << "k";
179  
180                  entities(address, '&', "&amp;");
181                  entities(address, '\"', "&quot;");
# Line 197 | Line 195 | void Outputer::body()
195                          tag(line, "<?title?>", title);
196                          tag(line, "<?sample?>", sample);
197                          tag(line, "<?description?>", description);
198 <                        tag(line, "<?size?>", size);
198 >                        tag(line, "<?size?>", size.str());
199  
200                          cout << line << (fin.good() ? "\n" : "");
201                  }
# Line 229 | Line 227 | void Outputer::footer(const string& quer
227                          platform());
228   #else
229                  tag(line, "<?version?>", programName + ' ' + programVersion + ' ' +
230 <                        platform() + ' ' + openssl(true));
230 >                        platform() + ' ' + openssl());
231   #endif
232                  tag(line, "<?query?>", query);
233                  tag(line, "<?range?>", range(page));
# Line 313 | Line 311 | string Outputer::pages(string query, uns
311                  conditional(line, fin, "<?ifnum?>", false);
312                  conditional(line, fin, "<?ifnext?>", false);
313  
314 <                char* cprevious = new char[1024];
317 <
318 <                sprintf(cprevious, "%u", page);
319 <
320 <                string previous = cprevious;
314 >                ostringstream previous;
315  
316 <                delete [] cprevious;
316 >                previous << page;
317  
318                  tag(line, "<?query?>", query);
319 <                tag(line, "<?previous?>", previous);
319 >                tag(line, "<?previous?>", previous.str());
320  
321                  lines += line + (fin.good() ? "\n" : "");
322          }
# Line 344 | Line 338 | string Outputer::pages(string query, uns
338                                  conditional(line, fin, "<?ifnum?>", false);
339                                  conditional(line, fin, "<?ifnext?>", false);
340  
341 <                                char* cpage = new char[1024];
341 >                                ostringstream current;
342  
343 <                                sprintf(cpage, "%u", (index + 1));
343 >                                current << index + 1;
344  
345 <                                string spage = cpage;
352 <
353 <                                delete [] cpage;
354 <
355 <                                tag(line, "<?page?>", spage);
345 >                                tag(line, "<?page?>", current.str());
346                          }
347                          else
348                          {
# Line 361 | Line 351 | string Outputer::pages(string query, uns
351                                  conditional(line, fin, "<?ifnum?>", true);
352                                  conditional(line, fin, "<?ifnext?>", false);
353  
354 <                                char* cnum = new char[1024];
365 <
366 <                                sprintf(cnum, "%u", (index + 1));
367 <
368 <                                string num = cnum;
354 >                                ostringstream num;
355  
356 <                                delete [] cnum;
356 >                                num << index + 1;
357  
358                                  tag(line, "<?query?>", query);
359 <                                tag(line, "<?num?>", num);
359 >                                tag(line, "<?num?>", num.str());
360                          }
361  
362                          lines += line + (fin.good() ? "\n" : "");
# Line 390 | Line 376 | string Outputer::pages(string query, uns
376                  conditional(line, fin, "<?ifnum?>", false);
377                  conditional(line, fin, "<?ifnext?>", page + 2 <= numPages);
378  
379 <                char* cnext = new char[1024];
379 >                ostringstream next;
380  
381 <                sprintf(cnext, "%u", (page + 2));
396 <
397 <                string next = cnext;
398 <
399 <                delete [] cnext;
381 >                next << page + 2;
382  
383                  tag(line, "<?query?>", query);
384 <                tag(line, "<?next?>", next);
384 >                tag(line, "<?next?>", next.str());
385  
386                  lines += line + (fin.good() ? "\n" : "");
387          }
# Line 413 | Line 395 | string Outputer::range(unsigned page)
395   {
396          unsigned bottom = page * 10 + 1;
397          unsigned top = numWebpages > page * 10 + 10 ? page * 10 + 10 : numWebpages;
398 +        ostringstream range;
399  
400 <        char* cbottom = new char[1024];
418 <        char* ctop = new char[1024];
419 <
420 <        sprintf(cbottom, "%u", bottom);
421 <        sprintf(ctop, "%u", top);
422 <
423 <        string range = string(cbottom) + " - " + ctop;
400 >        range << bottom << " - " << top;
401  
402 <        delete [] cbottom;
426 <        delete [] ctop;
427 <
428 <        return range;
402 >        return range.str();
403   }
404  
405   string Outputer::total()
406   {
407 <        char* ctotal = new char[1024];
434 <
435 <        sprintf(ctotal, "%u", numWebpages);
407 >        ostringstream total;
408  
409 <        string total = ctotal;
409 >        total << numWebpages;
410  
411 <        delete [] ctotal;
440 <
441 <        return total;
411 >        return total.str();
412   }
413  
414   string Outputer::duration()
415   {
416 <        char* ctime = new char[1024];
447 <        sprintf(ctime, "%.2f", time);
448 <
449 <        string duration = ctime;
416 >        ostringstream duration;
417  
418 <        delete [] ctime;
418 >        duration.precision(2);
419 >        duration << time;
420  
421 <        return duration;
421 >        return duration.str();
422   }
423  
424   string Outputer::manycommon(vector<string> common)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines