[108] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * htmlgen.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[533] | 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
[108] | 9 | *
|
---|
[533] | 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
[108] | 24 | * $Id: htmlgen.cpp 533 1999-09-07 04:57:01Z sjboddie $
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*
|
---|
| 29 | $Log$
|
---|
[533] | 30 | Revision 1.4 1999/09/07 04:56:55 sjboddie
|
---|
| 31 | added GPL notice
|
---|
| 32 |
|
---|
[158] | 33 | Revision 1.3 1999/02/11 01:24:04 rjmcnab
|
---|
| 34 |
|
---|
| 35 | Fixed a few compiler warnings.
|
---|
| 36 |
|
---|
[155] | 37 | Revision 1.2 1999/02/08 01:28:02 rjmcnab
|
---|
| 38 |
|
---|
| 39 | Got the receptionist producing something using the statusaction.
|
---|
| 40 |
|
---|
[108] | 41 | Revision 1.1 1999/01/08 08:40:56 rjmcnab
|
---|
| 42 |
|
---|
| 43 | Moved from lib directory.
|
---|
| 44 |
|
---|
| 45 | Revision 1.1 1999/01/08 03:57:46 rjmcnab
|
---|
| 46 |
|
---|
| 47 | Initial revision
|
---|
| 48 |
|
---|
| 49 | */
|
---|
| 50 |
|
---|
[155] | 51 | #include "htmlgen.h"
|
---|
| 52 | #include "unitool.h"
|
---|
[108] | 53 |
|
---|
[155] | 54 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 55 | # include <ospace\std\map>
|
---|
| 56 | #elif defined(GSDL_USE_STL_H)
|
---|
| 57 | # include <map.h>
|
---|
| 58 | #else
|
---|
| 59 | # include <map>
|
---|
| 60 | #endif
|
---|
[108] | 61 |
|
---|
| 62 |
|
---|
| 63 |
|
---|
[155] | 64 | // highlighttext highlights query terms in text string and
|
---|
| 65 | // outputs the resulting text string
|
---|
| 66 | void highlighttext (text_tarray &termvars, displayclass &disp, text_t &text,
|
---|
[158] | 67 | outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) {
|
---|
[155] | 68 | map<text_t, int, lttext_t> terms;
|
---|
| 69 | map<text_t, int, lttext_t>::const_iterator it;
|
---|
| 70 | for (unsigned int i = 0; i < termvars.size(); i++) {
|
---|
| 71 | terms[termvars[i]] = 1;
|
---|
| 72 | }
|
---|
[108] | 73 |
|
---|
[155] | 74 | // get the text to start and end a hightlight
|
---|
| 75 | text_t starthighlight = "<b><u>";
|
---|
| 76 | text_t endhighlight = "</u></b>";
|
---|
| 77 | if (disp.isdefaultmacro("Global", "starthighlight"))
|
---|
| 78 | disp.expandstring("Global", "_starthighlight_", starthighlight);
|
---|
| 79 | if (disp.isdefaultmacro("Global", "endhighlight"))
|
---|
| 80 | disp.expandstring("Global", "_endhighlight_", endhighlight);
|
---|
[108] | 81 |
|
---|
[155] | 82 |
|
---|
| 83 | text_t::iterator here = text.begin();
|
---|
| 84 | text_t::iterator end = text.end();
|
---|
| 85 | text_t word, buffer;
|
---|
| 86 | while (here != end) {
|
---|
| 87 | if (is_unicode_letdig(*here)) {
|
---|
| 88 | // not word boundary
|
---|
| 89 | word.push_back(*here);
|
---|
| 90 | here++;
|
---|
| 91 |
|
---|
| 92 | } else {
|
---|
| 93 | // found word boundary
|
---|
| 94 | // add last word if there was one
|
---|
| 95 | if (!word.empty()) {
|
---|
| 96 | it = terms.find(word);
|
---|
| 97 | if (it != terms.end()) {
|
---|
| 98 | word = starthighlight + word + endhighlight;
|
---|
| 99 | }
|
---|
| 100 | buffer += word;
|
---|
| 101 | word.clear();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | if (*here == '<') {
|
---|
| 105 | // skip over rest of html tag
|
---|
| 106 | while ((here != end) && (*here != '>')) {
|
---|
| 107 | buffer.push_back(*here);
|
---|
| 108 | here++;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | buffer.push_back(*here);
|
---|
| 113 | here++;
|
---|
| 114 |
|
---|
| 115 | if (buffer.size() > 1024) {
|
---|
| 116 | textout << outconvert << buffer;
|
---|
| 117 | buffer.clear();
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | textout << outconvert << buffer;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 |
|
---|