1 //========================================================================
5 // Copyright 2002-2003 Glyph & Cog, LLC
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2006 Scott Turner <scotty1024@mac.com>
17 // Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
19 // To see a description of the changes please see the Changelog file that
20 // came with your tarball or type make ChangeLog if you are building from git
22 //========================================================================
26 #ifdef USE_GCC_PRAGMAS
27 #pragma implementation
32 #include "PSTokenizer.h"
34 //------------------------------------------------------------------------
36 // A '1' in this array means the character is white space. A '1' or
37 // '2' means the character ends a name or command.
38 static const char specialChars
[256] = {
39 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
41 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
57 //------------------------------------------------------------------------
59 PSTokenizer::PSTokenizer(int (*getCharFuncA
)(void *), void *dataA
) {
60 getCharFunc
= getCharFuncA
;
65 PSTokenizer::~PSTokenizer() {
68 GBool
PSTokenizer::getToken(char *buf
, int size
, int *length
) {
69 GBool comment
, backslash
;
73 // skip leading whitespace and comments
76 if ((c
= getChar()) == EOF
) {
82 if (c
== '\x0a' || c
== '\x0d') {
85 } else if (c
== '%') {
87 } else if (specialChars
[c
] != 1) {
92 // Reserve room for terminating '\0'
100 while ((c
= lookChar()) != EOF
) {
107 } else if (!backslash
&& c
== ')') {
113 } else if (c
== '<') {
114 while ((c
= lookChar()) != EOF
) {
116 if (i
< size
&& specialChars
[c
] != 1) {
123 } else if (c
!= '[' && c
!= ']') {
124 while ((c
= lookChar()) != EOF
&& !specialChars
[c
]) {
131 // Zero terminate token string
133 // Return length of token
139 int PSTokenizer::lookChar() {
141 charBuf
= (*getCharFunc
)(data
);
146 void PSTokenizer::consumeChar() {
150 int PSTokenizer::getChar() {
154 c
= (*getCharFunc
)(data
);