~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to filters/kword/rtf/import/KRTFTokenizer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: KRTFTokenizer.cpp,v 1.5 2001/04/07 17:36:53 mueller Exp $
3
 
 */
4
 
 
5
 
#include "KRTFTokenizer.h"
6
 
 
7
 
#include <qfile.h>
8
 
#include <ctype.h>
9
 
 
10
 
KRTFTokenizer::KRTFTokenizer( QFile* file )
11
 
{
12
 
    _file = file;
13
 
}
14
 
 
15
 
 
16
 
KRTFToken* KRTFTokenizer::nextToken()
17
 
{
18
 
    // first check whether there is anything on the pushback stack and
19
 
    // use that instead
20
 
    if( !_pushbackstack.isEmpty() ) {
21
 
        return _pushbackstack.pop();
22
 
    }
23
 
 
24
 
    QString text;
25
 
    QString param;
26
 
    KRTFToken* token = new KRTFToken( this );
27
 
    int ch = _file->getch();
28
 
 
29
 
    // skip leading whitespace
30
 
    while( isspace( ch ) && !_file->atEnd() )
31
 
        ch=_file->getch();
32
 
 
33
 
    if( _file->atEnd() ) {
34
 
        token->_type = TokenEOF;
35
 
        return token;
36
 
    }
37
 
 
38
 
 
39
 
    // first find out what this is
40
 
    if( ch == '\\' ) {
41
 
        // type is either control word or control symbol
42
 
        ch = _file->getch();
43
 
        if( !isalnum( ch ) ) {
44
 
            // control symbol
45
 
            token->_type = ControlSymbol;
46
 
            token->_text += (char)ch;
47
 
        } else {
48
 
            // control word
49
 
            token->_type = ControlWord;
50
 
            _file->ungetch( ch );
51
 
        }
52
 
    } else if( ch == '{' ) {
53
 
        token->_type = OpenGroup;
54
 
    } else if( ch == '}' ) {
55
 
        token->_type = CloseGroup;
56
 
    } else {
57
 
        token->_type = ::PlainText;
58
 
        _file->ungetch( ch );
59
 
    }
60
 
 
61
 
    // Lump together what might be needed additionally.
62
 
    switch( token->_type ) {
63
 
    case ControlWord:
64
 
        ch = _file->getch();
65
 
        while( isalpha( ch ) ) {
66
 
            text += (char)ch;
67
 
            ch = _file->getch();
68
 
        }
69
 
        // ch is not alpha, control word is over, let�s see what we do about it
70
 
        if( ch == ' ' ) {
71
 
            // space: part of the control word, which ends here
72
 
            text += ' ';
73
 
        } else if( isdigit( ch ) || ( ch == '-' ) ) {
74
 
            // digit or hyphen, build up numeric parameter
75
 
            param += (char)ch;
76
 
            ch = _file->getch();
77
 
            while( isalnum( ch ) ) {
78
 
                param += (char)ch;
79
 
                ch = _file->getch();
80
 
            }
81
 
        }
82
 
 
83
 
        token->_text = text;
84
 
        token->_param = param;
85
 
        break;
86
 
    case PlainText:
87
 
        // everything until next backslash, opener or closer
88
 
        ch = _file->getch();
89
 
        while( ch != '\\' && ch != '{'  && ch != '}' ) {
90
 
            text += (char)ch;
91
 
            ch = _file->getch();
92
 
        }
93
 
        token->_text = text;
94
 
        // give back last char
95
 
        _file->ungetch( ch );
96
 
    }
97
 
 
98
 
    return token;
99
 
}
100
 
 
101
 
 
102
 
void KRTFTokenizer::pushBack( KRTFToken* token )
103
 
{
104
 
    _pushbackstack.push( token );
105
 
}
106