source: trunk/gsdl/src/recpt/htmlgen.cpp@ 173

Last change on this file since 173 was 158, checked in by rjmcnab, 25 years ago

Fixed a few compiler warnings.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1/**********************************************************************
2 *
3 * htmlgen.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: htmlgen.cpp 158 1999-02-11 01:24:06Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.3 1999/02/11 01:24:04 rjmcnab
15
16 Fixed a few compiler warnings.
17
18 Revision 1.2 1999/02/08 01:28:02 rjmcnab
19
20 Got the receptionist producing something using the statusaction.
21
22 Revision 1.1 1999/01/08 08:40:56 rjmcnab
23
24 Moved from lib directory.
25
26 Revision 1.1 1999/01/08 03:57:46 rjmcnab
27
28 Initial revision
29
30 */
31
32#include "htmlgen.h"
33#include "unitool.h"
34
35#if defined(GSDL_USE_OBJECTSPACE)
36# include <ospace\std\map>
37#elif defined(GSDL_USE_STL_H)
38# include <map.h>
39#else
40# include <map>
41#endif
42
43
44
45// highlighttext highlights query terms in text string and
46// outputs the resulting text string
47void highlighttext (text_tarray &termvars, displayclass &disp, text_t &text,
48 outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) {
49 map<text_t, int, lttext_t> terms;
50 map<text_t, int, lttext_t>::const_iterator it;
51 for (unsigned int i = 0; i < termvars.size(); i++) {
52 terms[termvars[i]] = 1;
53 }
54
55 // get the text to start and end a hightlight
56 text_t starthighlight = "<b><u>";
57 text_t endhighlight = "</u></b>";
58 if (disp.isdefaultmacro("Global", "starthighlight"))
59 disp.expandstring("Global", "_starthighlight_", starthighlight);
60 if (disp.isdefaultmacro("Global", "endhighlight"))
61 disp.expandstring("Global", "_endhighlight_", endhighlight);
62
63
64 text_t::iterator here = text.begin();
65 text_t::iterator end = text.end();
66 text_t word, buffer;
67 while (here != end) {
68 if (is_unicode_letdig(*here)) {
69 // not word boundary
70 word.push_back(*here);
71 here++;
72
73 } else {
74 // found word boundary
75 // add last word if there was one
76 if (!word.empty()) {
77 it = terms.find(word);
78 if (it != terms.end()) {
79 word = starthighlight + word + endhighlight;
80 }
81 buffer += word;
82 word.clear();
83 }
84
85 if (*here == '<') {
86 // skip over rest of html tag
87 while ((here != end) && (*here != '>')) {
88 buffer.push_back(*here);
89 here++;
90 }
91 }
92
93 buffer.push_back(*here);
94 here++;
95
96 if (buffer.size() > 1024) {
97 textout << outconvert << buffer;
98 buffer.clear();
99 }
100 }
101 }
102 textout << outconvert << buffer;
103}
104
105
Note: See TracBrowser for help on using the repository browser.