~ubuntu-branches/ubuntu/hoary/psi/hoary

« back to all changes in this revision

Viewing changes to src/rtparse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** rtparse.cpp - class for manipulating richtext
 
3
** Copyright (C) 2001, 2002  Justin Karneges
 
4
**
 
5
** This program is free software; you can redistribute it and/or
 
6
** modify it under the terms of the GNU General Public License
 
7
** as published by the Free Software Foundation; either version 2
 
8
** of the License, or (at your option) any later version.
 
9
**
 
10
** This program is distributed in the hope that it will be useful,
 
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
** GNU General Public License for more details.
 
14
**
 
15
** You should have received a copy of the GNU General Public License
 
16
** along with this program; if not, write to the Free Software
 
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
#include"rtparse.h"
 
22
#include"common.h"
 
23
 
 
24
 
 
25
RTParse::RTParse(const QString &_in)
 
26
{
 
27
        in = _in;
 
28
        v_atEnd = false;
 
29
        v_at = 0;
 
30
        //printf("rtparse:\n");
 
31
}
 
32
 
 
33
const QString &RTParse::output() const
 
34
{
 
35
        //printf("final: [%s]\n", out.latin1());
 
36
        return out;
 
37
}
 
38
 
 
39
QString RTParse::next()
 
40
{
 
41
        if(v_atEnd)
 
42
                return "";
 
43
 
 
44
        // if we're at a tag, append it to the output
 
45
        if(in.at(v_at) == '<') {
 
46
                QString s;
 
47
                int n = in.find('>', v_at);
 
48
                if(n == -1) {
 
49
                        s = in.mid(v_at);
 
50
                }
 
51
                else {
 
52
                        ++n;
 
53
                        s = in.mid(v_at, n-v_at);
 
54
                }
 
55
                v_at += s.length();
 
56
                out += s;
 
57
        }
 
58
 
 
59
        // now find the next tag, and grab the text in between
 
60
        QString s;
 
61
        int x = in.find('<', v_at);
 
62
        if(x == -1) {
 
63
                s = in.mid(v_at);
 
64
                v_atEnd = true;
 
65
        }
 
66
        else {
 
67
                s = in.mid(v_at, x-v_at);
 
68
        }
 
69
        v_at += s.length();
 
70
        //printf("chunk = '%s'\n", s.latin1());
 
71
        s = resolveEntities(s);
 
72
        //printf("resolved = '%s'\n", s.latin1());
 
73
        return s;
 
74
}
 
75
 
 
76
bool RTParse::atEnd() const
 
77
{
 
78
        return v_atEnd;
 
79
}
 
80
 
 
81
void RTParse::putPlain(const QString &s)
 
82
{
 
83
        //printf("got this: [%s]\n", s.latin1());
 
84
        out += expandEntities(s);
 
85
        //printf("changed to this: [%s]\n", expandEntities(s).latin1());
 
86
}
 
87
 
 
88
void RTParse::putRich(const QString &s)
 
89
{
 
90
        out += s;
 
91
        //printf("+ '%s'\n", s.latin1());
 
92
}
 
93