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 207 by douglas, 2003-07-17T20:52:39-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.10 2003/07/18 03:52:39 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)));
177 <
178 <                string size = csize;
179 <
180 <                delete [] csize;
176 >                size.precision(1);
177 >                size << double(webpage.getSize()) / double(1024) << "k";
178  
179                  entities(address, '&', "&amp;");
180                  entities(address, '\"', "&quot;");
# Line 197 | Line 194 | void Outputer::body()
194                          tag(line, "<?title?>", title);
195                          tag(line, "<?sample?>", sample);
196                          tag(line, "<?description?>", description);
197 <                        tag(line, "<?size?>", size);
197 >                        tag(line, "<?size?>", size.str());
198  
199                          cout << line << (fin.good() ? "\n" : "");
200                  }
# Line 229 | Line 226 | void Outputer::footer(const string& quer
226                          platform());
227   #else
228                  tag(line, "<?version?>", programName + ' ' + programVersion + ' ' +
229 <                        platform() + ' ' + openssl(true));
229 >                        platform() + ' ' + openssl());
230   #endif
231                  tag(line, "<?query?>", query);
232                  tag(line, "<?range?>", range(page));
# Line 313 | Line 310 | string Outputer::pages(string query, uns
310                  conditional(line, fin, "<?ifnum?>", false);
311                  conditional(line, fin, "<?ifnext?>", false);
312  
313 <                char* cprevious = new char[1024];
317 <
318 <                sprintf(cprevious, "%u", page);
319 <
320 <                string previous = cprevious;
313 >                ostringstream previous;
314  
315 <                delete [] cprevious;
315 >                previous << page;
316  
317                  tag(line, "<?query?>", query);
318 <                tag(line, "<?previous?>", previous);
318 >                tag(line, "<?previous?>", previous.str());
319  
320                  lines += line + (fin.good() ? "\n" : "");
321          }
# Line 344 | Line 337 | string Outputer::pages(string query, uns
337                                  conditional(line, fin, "<?ifnum?>", false);
338                                  conditional(line, fin, "<?ifnext?>", false);
339  
340 <                                char* cpage = new char[1024];
340 >                                ostringstream current;
341  
342 <                                sprintf(cpage, "%u", (index + 1));
342 >                                current << index + 1;
343  
344 <                                string spage = cpage;
352 <
353 <                                delete [] cpage;
354 <
355 <                                tag(line, "<?page?>", spage);
344 >                                tag(line, "<?page?>", current.str());
345                          }
346                          else
347                          {
# Line 361 | Line 350 | string Outputer::pages(string query, uns
350                                  conditional(line, fin, "<?ifnum?>", true);
351                                  conditional(line, fin, "<?ifnext?>", false);
352  
353 <                                char* cnum = new char[1024];
365 <
366 <                                sprintf(cnum, "%u", (index + 1));
367 <
368 <                                string num = cnum;
353 >                                ostringstream num;
354  
355 <                                delete [] cnum;
355 >                                num << index + 1;
356  
357                                  tag(line, "<?query?>", query);
358 <                                tag(line, "<?num?>", num);
358 >                                tag(line, "<?num?>", num.str());
359                          }
360  
361                          lines += line + (fin.good() ? "\n" : "");
# Line 390 | Line 375 | string Outputer::pages(string query, uns
375                  conditional(line, fin, "<?ifnum?>", false);
376                  conditional(line, fin, "<?ifnext?>", page + 2 <= numPages);
377  
378 <                char* cnext = new char[1024];
378 >                ostringstream next;
379  
380 <                sprintf(cnext, "%u", (page + 2));
396 <
397 <                string next = cnext;
398 <
399 <                delete [] cnext;
380 >                next << page + 2;
381  
382                  tag(line, "<?query?>", query);
383 <                tag(line, "<?next?>", next);
383 >                tag(line, "<?next?>", next.str());
384  
385                  lines += line + (fin.good() ? "\n" : "");
386          }
# Line 413 | Line 394 | string Outputer::range(unsigned page)
394   {
395          unsigned bottom = page * 10 + 1;
396          unsigned top = numWebpages > page * 10 + 10 ? page * 10 + 10 : numWebpages;
397 +        ostringstream range;
398  
399 <        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;
399 >        range << bottom << " - " << top;
400  
401 <        delete [] cbottom;
426 <        delete [] ctop;
427 <
428 <        return range;
401 >        return range.str();
402   }
403  
404   string Outputer::total()
405   {
406 <        char* ctotal = new char[1024];
434 <
435 <        sprintf(ctotal, "%u", numWebpages);
406 >        ostringstream total;
407  
408 <        string total = ctotal;
408 >        total << numWebpages;
409  
410 <        delete [] ctotal;
440 <
441 <        return total;
410 >        return total.str();
411   }
412  
413   string Outputer::duration()
414   {
415 <        char* ctime = new char[1024];
447 <        sprintf(ctime, "%.2f", time);
448 <
449 <        string duration = ctime;
415 >        ostringstream duration;
416  
417 <        delete [] ctime;
417 >        duration.precision(2);
418 >        duration << time;
419  
420 <        return duration;
420 >        return duration.str();
421   }
422  
423   string Outputer::manycommon(vector<string> common)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines