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