Switch to unified view

a/src/qtgui/plaintorich.h b/src/qtgui/plaintorich.h
...
...
14
 *   Free Software Foundation, Inc.,
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
#ifndef _PLAINTORICH_H_INCLUDED_
17
#ifndef _PLAINTORICH_H_INCLUDED_
18
#define _PLAINTORICH_H_INCLUDED_
18
#define _PLAINTORICH_H_INCLUDED_
19
/* @(#$Id: plaintorich.h,v 1.16 2007-11-15 18:05:32 dockes Exp $  (C) 2004 J.F.Dockes */
19
/* @(#$Id: plaintorich.h,v 1.17 2008-07-01 08:27:58 dockes Exp $  (C) 2004 J.F.Dockes */
20
20
21
#include <string>
21
#include <string>
22
#include <list>
22
#include <list>
23
using std::list;
23
using std::list;
24
using std::string;
24
using std::string;
25
25
26
// A data struct to hold words and groups of words to be highlighted
26
/// Holder for plaintorich() input data: words and groups of words to
27
/// be highlighted
27
struct HiliteData {
28
struct HiliteData {
29
    // Single terms
28
    vector<string> terms;
30
    vector<string> terms;
31
    // NEAR and PHRASE elements
29
    vector<vector<string> > groups;
32
    vector<vector<string> > groups;
30
    vector<int> gslks; // group slacks (number of permitted non-matched words)
33
    // Group slacks (number of permitted non-matched words). 
34
    // Parallel vector to the above 'groups'
35
    vector<int> gslks; 
31
};
36
};
32
37
33
/**
38
/** 
34
 * Transform plain text into qt rich text for the preview window.
39
 * A class for highlighting search results. Overridable methods allow
35
 *
40
 * for different styles
36
 * We escape characters like < or &, and add qt rich text tags to 
37
 * colorize the query terms. The latter is a quite complicated matter because
38
 * of phrase/near searches. We treat all such searches as "near", not "phrase"
39
 * 
40
 * @param in          raw text out of internfile.
41
 * @param out         rich text output, divided in chunks (to help our caller
42
 *          avoid inserting half tags into textedit which doesnt like it)
43
 * @param hdata       terms and groups to be highlighted. These are
44
 *                     lowercase and unaccented.
45
 * @param noHeader    if true don't output header (<qt><title>...)
46
 * @param needBeacons Need to navigate highlighted terms, mark them,return last
47
 */
41
 */
42
class PlainToRich {
43
public:
44
    static const string snull;
45
    virtual ~PlainToRich() {}
46
    /**
47
     * Transform plain text for highlighting search terms, ie in the
48
     * preview window or result list entries.
49
     *
50
     * The actual tags used for highlighting and anchoring are
51
     * determined by deriving from this class which handles the searching for
52
     * terms and groups, but there is an assumption that the output will be
53
     * html-like: we escape characters like < or &
54
     * 
55
     * Finding the search terms is relatively complicated because of
56
     * phrase/near searches, which need group highlights. As a matter
57
     * of simplification, we handle "phrase" as "near", not filtering
58
     * on word order.
59
     *
60
     * @param in    raw text out of internfile.
61
     * @param out   rich text output, divided in chunks (to help our caller
62
     *   avoid inserting half tags into textedit which doesnt like it)
63
     * @param hdata terms and groups to be highlighted. These are
64
     *   lowercase and unaccented.
65
     * @param chunksize max size of chunks in output list
66
     */
48
extern bool plaintorich(const string &in, list<string> &out,
67
    virtual bool plaintorich(const string &in, list<string> &out,
49
            const HiliteData& hdata,
68
                 const HiliteData& hdata,
50
          bool noHeader,
51
          int  *needBeacons,
52
            int chunksize = 50000
69
                 int chunksize = 50000
53
          );
70
               );
54
71
55
extern string termAnchorName(int i);
72
    /* Methods to ouput headers, highlighting and marking tags */
73
    virtual string header() {return snull;}
74
    virtual string startMatch() {return snull;}
75
    virtual string endMatch() {return snull;}
76
    virtual string startAnchor(int) {return snull;}
77
    virtual string endAnchor() {return snull;}
78
};
56
79
57
#endif /* _PLAINTORICH_H_INCLUDED_ */
80
#endif /* _PLAINTORICH_H_INCLUDED_ */