source: psi/trunk/src/rtparse.cpp@ 58

Last change on this file since 58 was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 2.1 KB
Line 
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
25RTParse::RTParse(const QString &_in)
26{
27 in = _in;
28 v_atEnd = false;
29 v_at = 0;
30 //printf("rtparse:\n");
31}
32
33const QString &RTParse::output() const
34{
35 //printf("final: [%s]\n", out.latin1());
36 return out;
37}
38
39QString 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
76bool RTParse::atEnd() const
77{
78 return v_atEnd;
79}
80
81void 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
88void RTParse::putRich(const QString &s)
89{
90 out += s;
91 //printf("+ '%s'\n", s.latin1());
92}
93
Note: See TracBrowser for help on using the repository browser.