[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 | *********************************************************************/
|
---|
| 25 |
|
---|
[155] | 26 | #include "htmlgen.h"
|
---|
| 27 | #include "unitool.h"
|
---|
[108] | 28 |
|
---|
[155] | 29 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 30 | # include <ospace\std\map>
|
---|
| 31 | #elif defined(GSDL_USE_STL_H)
|
---|
| 32 | # include <map.h>
|
---|
| 33 | #else
|
---|
| 34 | # include <map>
|
---|
| 35 | #endif
|
---|
[108] | 36 |
|
---|
| 37 |
|
---|
| 38 |
|
---|
[155] | 39 | // highlighttext highlights query terms in text string and
|
---|
| 40 | // outputs the resulting text string
|
---|
| 41 | void highlighttext (text_tarray &termvars, displayclass &disp, text_t &text,
|
---|
[158] | 42 | outconvertclass &outconvert, ostream &textout, ostream &/*logout*/) {
|
---|
[155] | 43 | map<text_t, int, lttext_t> terms;
|
---|
| 44 | map<text_t, int, lttext_t>::const_iterator it;
|
---|
| 45 | for (unsigned int i = 0; i < termvars.size(); i++) {
|
---|
| 46 | terms[termvars[i]] = 1;
|
---|
| 47 | }
|
---|
[108] | 48 |
|
---|
[155] | 49 | // get the text to start and end a hightlight
|
---|
| 50 | text_t starthighlight = "<b><u>";
|
---|
| 51 | text_t endhighlight = "</u></b>";
|
---|
| 52 | if (disp.isdefaultmacro("Global", "starthighlight"))
|
---|
| 53 | disp.expandstring("Global", "_starthighlight_", starthighlight);
|
---|
| 54 | if (disp.isdefaultmacro("Global", "endhighlight"))
|
---|
| 55 | disp.expandstring("Global", "_endhighlight_", endhighlight);
|
---|
[108] | 56 |
|
---|
[155] | 57 |
|
---|
| 58 | text_t::iterator here = text.begin();
|
---|
| 59 | text_t::iterator end = text.end();
|
---|
| 60 | text_t word, buffer;
|
---|
| 61 | while (here != end) {
|
---|
| 62 | if (is_unicode_letdig(*here)) {
|
---|
| 63 | // not word boundary
|
---|
| 64 | word.push_back(*here);
|
---|
| 65 | here++;
|
---|
| 66 |
|
---|
| 67 | } else {
|
---|
| 68 | // found word boundary
|
---|
| 69 | // add last word if there was one
|
---|
| 70 | if (!word.empty()) {
|
---|
| 71 | it = terms.find(word);
|
---|
| 72 | if (it != terms.end()) {
|
---|
| 73 | word = starthighlight + word + endhighlight;
|
---|
| 74 | }
|
---|
| 75 | buffer += word;
|
---|
| 76 | word.clear();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | if (*here == '<') {
|
---|
| 80 | // skip over rest of html tag
|
---|
| 81 | while ((here != end) && (*here != '>')) {
|
---|
| 82 | buffer.push_back(*here);
|
---|
| 83 | here++;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | buffer.push_back(*here);
|
---|
| 88 | here++;
|
---|
| 89 |
|
---|
| 90 | if (buffer.size() > 1024) {
|
---|
| 91 | textout << outconvert << buffer;
|
---|
| 92 | buffer.clear();
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | textout << outconvert << buffer;
|
---|
| 97 | }
|
---|