1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*******************************************************************************
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius*   Copyright (C) 1998-2012, International Business Machines
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*******************************************************************************
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File read.c
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History:
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Date        Name        Description
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   05/26/99    stephen     Creation.
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   5/10/01     Ram         removed ustdio dependency
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*******************************************************************************
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "read.h"
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "errmsg.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
2254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "unicode/utf16.h"
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define OPENBRACE    0x007B
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CLOSEBRACE   0x007D
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define COMMA        0x002C
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define QUOTE        0x0022
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define ESCAPE       0x005C
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define SLASH        0x002F
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define ASTERISK     0x002A
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define SPACE        0x0020
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define COLON        0x003A
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define BADBOM       0xFFFE
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CR           0x000D
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define LF           0x000A
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t lineCount;
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Protos */
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic enum ETokenType getStringToken(UCHARBUF *buf,
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      UChar32 initialChar,
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      struct UString *token,
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      UErrorCode *status);
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UChar32 getNextChar           (UCHARBUF *buf, UBool skipwhite, struct UString *token, UErrorCode *status);
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void    seekUntilNewline      (UCHARBUF *buf, struct UString *token, UErrorCode *status);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void    seekUntilEndOfComment (UCHARBUF *buf, struct UString *token, UErrorCode *status);
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool   isWhitespace          (UChar32 c);
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool   isNewline             (UChar32 c);
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
51103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusU_CFUNC void resetLineNumber() {
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    lineCount = 1;
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Read and return the next token from the stream.  If the token is of
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   type eString, fill in the token parameter with the token.  If the
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   token is eError, then the status parameter will contain the
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   specific error.  This will be eItemNotFound at the end of file,
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   indicating that all tokens have been returned.  This method will
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   never return eString twice in a row; instead, multiple adjacent
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   string tokens will be merged into one, with no intervening
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   space. */
63103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusU_CFUNC enum ETokenType
64103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusgetNextToken(UCHARBUF* buf,
65103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius             struct UString *token,
66103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius             uint32_t *linenumber, /* out: linenumber of token */
67103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius             struct UString *comment,
68103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius             UErrorCode *status) {
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    enum ETokenType result;
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32         c;
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_ERROR;
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Skip whitespace */
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    c = getNextChar(buf, TRUE, comment, status);
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_ERROR;
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    *linenumber = lineCount;
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch(c) {
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case BADBOM:
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_ERROR;
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case OPENBRACE:
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_OPEN_BRACE;
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case CLOSEBRACE:
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_CLOSE_BRACE;
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case COMMA:
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_COMMA;
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case U_EOF:
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_EOF;
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case COLON:
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_COLON;
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    default:
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        result = getStringToken(buf, c, token, status);
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    *linenumber = lineCount;
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return result;
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Copy a string token into the given UnicodeString.  Upon entry, we
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   have already read the first character of the string token, which is
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   not a whitespace character (but may be a QUOTE or ESCAPE). This
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   function reads all subsequent characters that belong with this
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   string, and copy them into the token parameter. The other
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   important, and slightly convoluted purpose of this function is to
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   merge adjacent strings.  It looks forward a bit, and if the next
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   non comment, non whitespace item is a string, it reads it in as
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   well.  If two adjacent strings are quoted, they are merged without
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   intervening space.  Otherwise a single SPACE character is
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   inserted. */
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic enum ETokenType getStringToken(UCHARBUF* buf,
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      UChar32 initialChar,
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      struct UString *token,
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      UErrorCode *status) {
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool    lastStringWasQuoted;
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32  c;
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar    target[3] = { '\0' };
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar    *pTarget   = target;
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int      len=0;
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool    isFollowingCharEscaped=FALSE;
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool    isNLUnescaped = FALSE;
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32  prevC=0;
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* We are guaranteed on entry that initialChar is not a whitespace
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       character. If we are at the EOF, or have some other problem, it
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       doesn't matter; we still want to validly return the initialChar
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       (if nothing else) as a string token. */
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_ERROR;
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* setup */
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    lastStringWasQuoted = FALSE;
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    c = initialChar;
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ustr_setlen(token, 0, status);
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TOK_ERROR;
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (;;) {
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (c == QUOTE) {
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (!lastStringWasQuoted && token->fLength > 0) {
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                ustr_ucat(token, SPACE, status);
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (U_FAILURE(*status)) {
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_ERROR;
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lastStringWasQuoted = TRUE;
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for (;;) {
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                c = ucbuf_getc(buf,status);
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* EOF reached */
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (c == U_EOF) {
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_EOF;
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* Unterminated quoted strings */
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (U_FAILURE(*status)) {
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_ERROR;
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (c == QUOTE && !isFollowingCharEscaped) {
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    break;
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (c == ESCAPE  && !isFollowingCharEscaped) {
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    pTarget = target;
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    c       = unescape(buf, status);
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if (c == U_ERR) {
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        return TOK_ERROR;
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if(c == CR || c == LF){
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        isNLUnescaped = TRUE;
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(c==ESCAPE && !isFollowingCharEscaped){
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    isFollowingCharEscaped = TRUE;
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }else{
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    U_APPEND_CHAR32(c, pTarget,len);
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    pTarget = target;
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    ustr_uscat(token, pTarget,len, status);
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    isFollowingCharEscaped = FALSE;
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    len=0;
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if(c == CR || c == LF){
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        if(isNLUnescaped == FALSE && prevC!=CR){
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                            lineCount++;
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        }
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        isNLUnescaped = FALSE;
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (U_FAILURE(*status)) {
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_ERROR;
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                prevC = c;
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (token->fLength > 0) {
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                ustr_ucat(token, SPACE, status);
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (U_FAILURE(*status)) {
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_ERROR;
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(lastStringWasQuoted){
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(getShowWarning()){
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    warning(lineCount, "Mixing quoted and unquoted strings");
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(isStrict()){
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_ERROR;
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lastStringWasQuoted = FALSE;
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* if we reach here we are mixing
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             * quoted and unquoted strings
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             * warn in normal mode and error in
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             * pedantic mode
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             */
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (c == ESCAPE) {
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                pTarget = target;
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                c       = unescape(buf, status);
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* EOF reached */
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (c == U_EOF) {
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_ERROR;
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            U_APPEND_CHAR32(c, pTarget,len);
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            pTarget = target;
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ustr_uscat(token, pTarget,len, status);
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            len=0;
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (U_FAILURE(*status)) {
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                return TOK_ERROR;
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for (;;) {
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* DON'T skip whitespace */
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                c = getNextChar(buf, FALSE, NULL, status);
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* EOF reached */
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (c == U_EOF) {
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    ucbuf_ungetc(c, buf);
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_STRING;
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (U_FAILURE(*status)) {
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_STRING;
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (c == QUOTE
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        || c == OPENBRACE
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        || c == CLOSEBRACE
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        || c == COMMA
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        || c == COLON) {
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    ucbuf_ungetc(c, buf);
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    break;
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (isWhitespace(c)) {
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    break;
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (c == ESCAPE) {
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    pTarget = target;
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    c       = unescape(buf, status);
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if (c == U_ERR) {
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        return TOK_ERROR;
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                U_APPEND_CHAR32(c, pTarget,len);
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                pTarget = target;
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                ustr_uscat(token, pTarget,len, status);
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                len=0;
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (U_FAILURE(*status)) {
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    return TOK_ERROR;
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* DO skip whitespace */
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        c = getNextChar(buf, TRUE, NULL, status);
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (U_FAILURE(*status)) {
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return TOK_STRING;
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (c == OPENBRACE || c == CLOSEBRACE || c == COMMA || c == COLON) {
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucbuf_ungetc(c, buf);
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return TOK_STRING;
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Retrieve the next character.  If skipwhite is
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   true, whitespace is skipped as well. */
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UChar32 getNextChar(UCHARBUF* buf,
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           UBool skipwhite,
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           struct UString *token,
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           UErrorCode *status) {
323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32 c, c2;
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return U_EOF;
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (;;) {
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        c = ucbuf_getc(buf,status);
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (c == U_EOF) {
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return U_EOF;
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (skipwhite && isWhitespace(c)) {
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* This also handles the get() failing case */
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (c != SLASH) {
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return c;
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
34585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        c = ucbuf_getc(buf,status); /* "/c" */
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (c == U_EOF) {
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return U_EOF;
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        switch (c) {
35285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        case SLASH:  /* "//" */
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            seekUntilNewline(buf, NULL, status);
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        case ASTERISK:  /* " / * " */
35785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            c2 = ucbuf_getc(buf, status); /* "/ * c" */
35885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if(c2 == ASTERISK){  /* "/ * *" */
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                /* parse multi-line comment and store it in token*/
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                seekUntilEndOfComment(buf, token, status);
36185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            } else {
36285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                ucbuf_ungetc(c2, buf); /* c2 is the non-asterisk following "/ *".  Include c2  back in buffer.  */
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                seekUntilEndOfComment(buf, NULL, status);
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        default:
36885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ucbuf_ungetc(c, buf); /* "/c" - put back the c */
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* If get() failed this is a NOP */
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return SLASH;
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void seekUntilNewline(UCHARBUF* buf,
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                             struct UString *token,
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                             UErrorCode *status) {
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32 c;
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    do {
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        c = ucbuf_getc(buf,status);
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* add the char to token */
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(token!=NULL){
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ustr_u32cat(token, c, status);
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } while (!isNewline(c) && c != U_EOF && *status == U_ZERO_ERROR);
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void seekUntilEndOfComment(UCHARBUF *buf,
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  struct UString *token,
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  UErrorCode *status) {
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32  c, d;
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t line;
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    line = lineCount;
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    do {
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        c = ucbuf_getc(buf, status);
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (c == ASTERISK) {
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            d = ucbuf_getc(buf, status);
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (d != SLASH) {
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                ucbuf_ungetc(d, buf);
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            } else {
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                break;
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* add the char to token */
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(token!=NULL){
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ustr_u32cat(token, c, status);
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* increment the lineCount */
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        isNewline(c);
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } while (c != U_EOF && *status == U_ZERO_ERROR);
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (c == U_EOF) {
428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        *status = U_INVALID_FORMAT_ERROR;
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        error(line, "unterminated comment detected");
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
433103e9ffba2cba345d0078eb8b8db33249f81840aCraig CorneliusU_CFUNC UChar32 unescape(UCHARBUF *buf, UErrorCode *status) {
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(*status)) {
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return U_EOF;
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* We expect to be called after the ESCAPE has been seen, but
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * u_fgetcx needs an ESCAPE to do its magic. */
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucbuf_ungetc(ESCAPE, buf);
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return ucbuf_getcx32(buf, status);
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool isWhitespace(UChar32 c) {
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch (c) {
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* ' ', '\t', '\n', '\r', 0x2029, 0xFEFF */
448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x000A:
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x2029:
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        lineCount++;
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x000D:
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x0020:
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x0009:
454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0xFEFF:
455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TRUE;
456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    default:
458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UBool isNewline(UChar32 c) {
463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch (c) {
464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* '\n', '\r', 0x2029 */
465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x000A:
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x2029:
467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        lineCount++;
468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    case 0x000D:
469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TRUE;
470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    default:
472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
475