1 //========================================================================
5 // Copyright 2002 Glyph & Cog, LLC
7 //========================================================================
10 #pragma implementation
15 #include "PSTokenizer.h"
17 //------------------------------------------------------------------------
19 // A '1' in this array means the character is white space. A '1' or
20 // '2' means the character ends a name or command.
21 static char specialChars[256] = {
22 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
24 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
25 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
26 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
40 //------------------------------------------------------------------------
42 PSTokenizer::PSTokenizer(int (*getCharFuncA)(void *), void *dataA) {
43 getCharFunc = getCharFuncA;
48 PSTokenizer::~PSTokenizer() {
51 GBool PSTokenizer::getToken(char *buf, int size, int *length) {
52 GBool comment, backslash;
56 // skip whitespace and comments
59 if ((c = getChar()) == EOF) {
65 if (c == '\x0a' || c == '\x0d') {
68 } else if (c == '%') {
70 } else if (specialChars[c] != 1) {
80 while ((c = lookChar()) != EOF) {
87 } else if (!backslash && c == ')') {
93 } else if (c == '<') {
94 while ((c = lookChar()) != EOF) {
103 } else if (c != '[' && c != ']') {
104 while ((c = lookChar()) != EOF && !specialChars[c]) {
117 int PSTokenizer::lookChar() {
119 charBuf = (*getCharFunc)(data);
124 int PSTokenizer::getChar() {
128 charBuf = (*getCharFunc)(data);