1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2009-04-15 01:57:02 +00:00
|
|
|
* Copyright (C) 1998-2009, International Business Machines
|
1999-12-13 22:28:37 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File read.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 05/26/99 stephen Creation.
|
2001-05-10 21:43:01 +00:00
|
|
|
* 5/10/01 Ram removed ustdio dependency
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "read.h"
|
2002-04-23 22:25:44 +00:00
|
|
|
#include "errmsg.h"
|
2000-05-15 18:39:17 +00:00
|
|
|
#include "unicode/ustring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
#define OPENBRACE 0x007B
|
|
|
|
#define CLOSEBRACE 0x007D
|
|
|
|
#define COMMA 0x002C
|
|
|
|
#define QUOTE 0x0022
|
|
|
|
#define ESCAPE 0x005C
|
|
|
|
#define SLASH 0x002F
|
|
|
|
#define ASTERISK 0x002A
|
|
|
|
#define SPACE 0x0020
|
2000-05-15 18:39:17 +00:00
|
|
|
#define COLON 0x003A
|
2000-05-18 21:25:51 +00:00
|
|
|
#define BADBOM 0xFFFE
|
2003-08-27 00:06:37 +00:00
|
|
|
#define CR 0x000D
|
|
|
|
#define LF 0x000A
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static int32_t lineCount;
|
2000-07-20 19:56:52 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Protos */
|
2001-07-11 20:31:32 +00:00
|
|
|
static enum ETokenType getStringToken(UCHARBUF *buf,
|
|
|
|
UChar32 initialChar,
|
|
|
|
struct UString *token,
|
|
|
|
UErrorCode *status);
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
static UChar32 getNextChar (UCHARBUF *buf, UBool skipwhite, struct UString *token, UErrorCode *status);
|
|
|
|
static void seekUntilNewline (UCHARBUF *buf, struct UString *token, UErrorCode *status);
|
|
|
|
static void seekUntilEndOfComment (UCHARBUF *buf, struct UString *token, UErrorCode *status);
|
2001-07-11 20:31:32 +00:00
|
|
|
static UBool isWhitespace (UChar32 c);
|
|
|
|
static UBool isNewline (UChar32 c);
|
|
|
|
|
|
|
|
void resetLineNumber() {
|
|
|
|
lineCount = 1;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Read and return the next token from the stream. If the token is of
|
|
|
|
type eString, fill in the token parameter with the token. If the
|
|
|
|
token is eError, then the status parameter will contain the
|
|
|
|
specific error. This will be eItemNotFound at the end of file,
|
|
|
|
indicating that all tokens have been returned. This method will
|
|
|
|
never return eString twice in a row; instead, multiple adjacent
|
|
|
|
string tokens will be merged into one, with no intervening
|
|
|
|
space. */
|
2001-05-10 16:54:09 +00:00
|
|
|
enum ETokenType getNextToken(UCHARBUF* buf,
|
2000-11-20 23:30:15 +00:00
|
|
|
struct UString *token,
|
2001-07-11 20:31:32 +00:00
|
|
|
uint32_t *linenumber, /* out: linenumber of token */
|
2003-08-26 02:36:57 +00:00
|
|
|
struct UString *comment,
|
2001-07-11 20:31:32 +00:00
|
|
|
UErrorCode *status) {
|
|
|
|
enum ETokenType result;
|
|
|
|
UChar32 c;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* Skip whitespace */
|
2003-08-26 02:36:57 +00:00
|
|
|
c = getNextChar(buf, TRUE, comment, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
*linenumber = lineCount;
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
case BADBOM:
|
|
|
|
return TOK_ERROR;
|
|
|
|
case OPENBRACE:
|
|
|
|
return TOK_OPEN_BRACE;
|
|
|
|
case CLOSEBRACE:
|
|
|
|
return TOK_CLOSE_BRACE;
|
|
|
|
case COMMA:
|
|
|
|
return TOK_COMMA;
|
|
|
|
case U_EOF:
|
|
|
|
return TOK_EOF;
|
|
|
|
case COLON:
|
|
|
|
return TOK_COLON;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = getStringToken(buf, c, token, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
*linenumber = lineCount;
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy a string token into the given UnicodeString. Upon entry, we
|
|
|
|
have already read the first character of the string token, which is
|
|
|
|
not a whitespace character (but may be a QUOTE or ESCAPE). This
|
|
|
|
function reads all subsequent characters that belong with this
|
|
|
|
string, and copy them into the token parameter. The other
|
|
|
|
important, and slightly convoluted purpose of this function is to
|
|
|
|
merge adjacent strings. It looks forward a bit, and if the next
|
|
|
|
non comment, non whitespace item is a string, it reads it in as
|
|
|
|
well. If two adjacent strings are quoted, they are merged without
|
|
|
|
intervening space. Otherwise a single SPACE character is
|
|
|
|
inserted. */
|
2001-05-10 16:54:09 +00:00
|
|
|
static enum ETokenType getStringToken(UCHARBUF* buf,
|
2001-05-26 01:20:21 +00:00
|
|
|
UChar32 initialChar,
|
2000-11-20 23:30:15 +00:00
|
|
|
struct UString *token,
|
2001-07-11 20:31:32 +00:00
|
|
|
UErrorCode *status) {
|
|
|
|
UBool lastStringWasQuoted;
|
|
|
|
UChar32 c;
|
|
|
|
UChar target[3] = { '\0' };
|
2001-07-27 17:33:28 +00:00
|
|
|
UChar *pTarget = target;
|
|
|
|
int len=0;
|
2001-08-28 01:25:35 +00:00
|
|
|
UBool isFollowingCharEscaped=FALSE;
|
2003-08-27 00:06:37 +00:00
|
|
|
UBool isNLUnescaped = FALSE;
|
2003-12-02 03:03:23 +00:00
|
|
|
UChar32 prevC=0;
|
2002-11-08 23:16:10 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* We are guaranteed on entry that initialChar is not a whitespace
|
|
|
|
character. If we are at the EOF, or have some other problem, it
|
|
|
|
doesn't matter; we still want to validly return the initialChar
|
|
|
|
(if nothing else) as a string token. */
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-11-20 23:30:15 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* setup */
|
|
|
|
lastStringWasQuoted = FALSE;
|
|
|
|
c = initialChar;
|
|
|
|
ustr_setlen(token, 0, status);
|
2000-11-20 23:30:15 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
2000-11-20 23:30:15 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
for (;;) {
|
|
|
|
if (c == QUOTE) {
|
|
|
|
if (!lastStringWasQuoted && token->fLength > 0) {
|
|
|
|
ustr_ucat(token, SPACE, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastStringWasQuoted = TRUE;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
c = ucbuf_getc(buf,status);
|
|
|
|
|
|
|
|
/* EOF reached */
|
|
|
|
if (c == U_EOF) {
|
|
|
|
return TOK_EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unterminated quoted strings */
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
|
2001-08-28 01:25:35 +00:00
|
|
|
if (c == QUOTE && !isFollowingCharEscaped) {
|
2001-07-11 20:31:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-28 21:27:44 +00:00
|
|
|
if (c == ESCAPE && !isFollowingCharEscaped) {
|
2001-07-11 20:31:32 +00:00
|
|
|
pTarget = target;
|
|
|
|
c = unescape(buf, status);
|
|
|
|
|
|
|
|
if (c == U_ERR) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
2003-08-27 00:06:37 +00:00
|
|
|
if(c == CR || c == LF){
|
|
|
|
isNLUnescaped = TRUE;
|
|
|
|
}
|
2001-11-07 03:23:55 +00:00
|
|
|
}
|
2001-11-07 04:59:47 +00:00
|
|
|
|
2001-08-28 01:25:35 +00:00
|
|
|
if(c==ESCAPE && !isFollowingCharEscaped){
|
|
|
|
isFollowingCharEscaped = TRUE;
|
2001-11-07 19:11:15 +00:00
|
|
|
}else{
|
|
|
|
U_APPEND_CHAR32(c, pTarget,len);
|
|
|
|
pTarget = target;
|
|
|
|
ustr_uscat(token, pTarget,len, status);
|
|
|
|
isFollowingCharEscaped = FALSE;
|
|
|
|
len=0;
|
2003-08-27 00:06:37 +00:00
|
|
|
if(c == CR || c == LF){
|
|
|
|
if(isNLUnescaped == FALSE && prevC!=CR){
|
|
|
|
lineCount++;
|
|
|
|
}
|
|
|
|
isNLUnescaped = FALSE;
|
|
|
|
}
|
2001-08-28 01:25:35 +00:00
|
|
|
}
|
2001-11-07 04:59:47 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
2003-08-27 00:06:37 +00:00
|
|
|
prevC = c;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (token->fLength > 0) {
|
|
|
|
ustr_ucat(token, SPACE, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2002-11-08 23:16:10 +00:00
|
|
|
|
|
|
|
if(lastStringWasQuoted){
|
|
|
|
if(getShowWarning()){
|
|
|
|
warning(lineCount, "Mixing quoted and unquoted strings");
|
|
|
|
}
|
|
|
|
if(isStrict()){
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
lastStringWasQuoted = FALSE;
|
2002-11-08 23:16:10 +00:00
|
|
|
|
|
|
|
/* if we reach here we are mixing
|
|
|
|
* quoted and unquoted strings
|
|
|
|
* warn in normal mode and error in
|
|
|
|
* pedantic mode
|
|
|
|
*/
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
if (c == ESCAPE) {
|
|
|
|
pTarget = target;
|
|
|
|
c = unescape(buf, status);
|
|
|
|
|
|
|
|
/* EOF reached */
|
|
|
|
if (c == U_EOF) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-27 17:33:28 +00:00
|
|
|
U_APPEND_CHAR32(c, pTarget,len);
|
2001-07-11 20:31:32 +00:00
|
|
|
pTarget = target;
|
2001-07-27 17:33:28 +00:00
|
|
|
ustr_uscat(token, pTarget,len, status);
|
|
|
|
len=0;
|
2003-08-27 00:06:37 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* DON'T skip whitespace */
|
2003-08-26 02:36:57 +00:00
|
|
|
c = getNextChar(buf, FALSE, NULL, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
/* EOF reached */
|
|
|
|
if (c == U_EOF) {
|
|
|
|
ucbuf_ungetc(c, buf);
|
|
|
|
return TOK_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == QUOTE
|
|
|
|
|| c == OPENBRACE
|
|
|
|
|| c == CLOSEBRACE
|
|
|
|
|| c == COMMA
|
|
|
|
|| c == COLON) {
|
|
|
|
ucbuf_ungetc(c, buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isWhitespace(c)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == ESCAPE) {
|
|
|
|
pTarget = target;
|
|
|
|
c = unescape(buf, status);
|
|
|
|
|
|
|
|
if (c == U_ERR) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-27 17:33:28 +00:00
|
|
|
U_APPEND_CHAR32(c, pTarget,len);
|
2001-07-11 20:31:32 +00:00
|
|
|
pTarget = target;
|
2001-07-27 17:33:28 +00:00
|
|
|
ustr_uscat(token, pTarget,len, status);
|
|
|
|
len=0;
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2001-05-25 00:16:28 +00:00
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* DO skip whitespace */
|
2003-08-26 02:36:57 +00:00
|
|
|
c = getNextChar(buf, TRUE, NULL, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return TOK_STRING;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (c == OPENBRACE || c == CLOSEBRACE || c == COMMA || c == COLON) {
|
|
|
|
ucbuf_ungetc(c, buf);
|
|
|
|
return TOK_STRING;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
/* Retrieve the next character. If skipwhite is
|
1999-08-16 21:50:52 +00:00
|
|
|
true, whitespace is skipped as well. */
|
2001-05-26 01:20:21 +00:00
|
|
|
static UChar32 getNextChar(UCHARBUF* buf,
|
2001-07-11 20:31:32 +00:00
|
|
|
UBool skipwhite,
|
2003-08-26 02:36:57 +00:00
|
|
|
struct UString *token,
|
2001-07-11 20:31:32 +00:00
|
|
|
UErrorCode *status) {
|
2003-08-26 02:36:57 +00:00
|
|
|
UChar32 c, c2;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return U_EOF;
|
|
|
|
}
|
2000-11-20 23:30:15 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
for (;;) {
|
|
|
|
c = ucbuf_getc(buf,status);
|
2000-11-20 23:30:15 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (c == U_EOF) {
|
|
|
|
return U_EOF;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (skipwhite && isWhitespace(c)) {
|
|
|
|
continue;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* This also handles the get() failing case */
|
|
|
|
if (c != SLASH) {
|
|
|
|
return c;
|
|
|
|
}
|
2000-11-20 23:30:15 +00:00
|
|
|
|
2008-05-28 20:51:38 +00:00
|
|
|
c = ucbuf_getc(buf,status); /* "/c" */
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (c == U_EOF) {
|
|
|
|
return U_EOF;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
switch (c) {
|
2008-05-28 20:51:38 +00:00
|
|
|
case SLASH: /* "//" */
|
2003-08-26 02:36:57 +00:00
|
|
|
seekUntilNewline(buf, NULL, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
break;
|
|
|
|
|
2009-04-15 01:57:02 +00:00
|
|
|
case ASTERISK: /* " / * " */
|
|
|
|
c2 = ucbuf_getc(buf, status); /* "/ * c" */
|
|
|
|
if(c2 == ASTERISK){ /* "/ * *" */
|
2003-08-26 02:36:57 +00:00
|
|
|
/* parse multi-line comment and store it in token*/
|
|
|
|
seekUntilEndOfComment(buf, token, status);
|
2008-05-28 20:51:38 +00:00
|
|
|
} else {
|
2009-04-15 01:57:02 +00:00
|
|
|
ucbuf_ungetc(c2, buf); /* c2 is the non-asterisk following "/ *". Include c2 back in buffer. */
|
2003-08-26 02:36:57 +00:00
|
|
|
seekUntilEndOfComment(buf, NULL, status);
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-05-28 20:51:38 +00:00
|
|
|
ucbuf_ungetc(c, buf); /* "/c" - put back the c */
|
2001-07-11 20:31:32 +00:00
|
|
|
/* If get() failed this is a NOP */
|
|
|
|
return SLASH;
|
|
|
|
}
|
2003-08-26 02:36:57 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-10 16:54:09 +00:00
|
|
|
static void seekUntilNewline(UCHARBUF* buf,
|
2003-08-26 02:36:57 +00:00
|
|
|
struct UString *token,
|
2001-07-11 20:31:32 +00:00
|
|
|
UErrorCode *status) {
|
|
|
|
UChar32 c;
|
2000-11-20 23:30:15 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
do {
|
|
|
|
c = ucbuf_getc(buf,status);
|
2003-08-26 02:36:57 +00:00
|
|
|
/* add the char to token */
|
|
|
|
if(token!=NULL){
|
|
|
|
ustr_u32cat(token, c, status);
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
} while (!isNewline(c) && c != U_EOF && *status == U_ZERO_ERROR);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static void seekUntilEndOfComment(UCHARBUF *buf,
|
2003-08-26 02:36:57 +00:00
|
|
|
struct UString *token,
|
2001-07-11 20:31:32 +00:00
|
|
|
UErrorCode *status) {
|
|
|
|
UChar32 c, d;
|
|
|
|
uint32_t line;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
line = lineCount;
|
|
|
|
|
|
|
|
do {
|
|
|
|
c = ucbuf_getc(buf, status);
|
|
|
|
|
|
|
|
if (c == ASTERISK) {
|
|
|
|
d = ucbuf_getc(buf, status);
|
|
|
|
|
|
|
|
if (d != SLASH) {
|
|
|
|
ucbuf_ungetc(d, buf);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-08-26 02:36:57 +00:00
|
|
|
/* add the char to token */
|
|
|
|
if(token!=NULL){
|
|
|
|
ustr_u32cat(token, c, status);
|
|
|
|
}
|
2003-11-14 22:47:47 +00:00
|
|
|
/* increment the lineCount */
|
|
|
|
isNewline(c);
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
} while (c != U_EOF && *status == U_ZERO_ERROR);
|
|
|
|
|
|
|
|
if (c == U_EOF) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(line, "unterminated comment detected");
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
UChar32 unescape(UCHARBUF *buf,
|
|
|
|
UErrorCode *status) {
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return U_EOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We expect to be called after the ESCAPE has been seen, but
|
|
|
|
* u_fgetcx needs an ESCAPE to do its magic. */
|
|
|
|
ucbuf_ungetc(ESCAPE, buf);
|
|
|
|
|
2002-10-10 01:05:51 +00:00
|
|
|
return ucbuf_getcx32(buf, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static UBool isWhitespace(UChar32 c) {
|
|
|
|
switch (c) {
|
|
|
|
/* ' ', '\t', '\n', '\r', 0x2029, 0xFEFF */
|
|
|
|
case 0x000A:
|
|
|
|
case 0x2029:
|
|
|
|
lineCount++;
|
|
|
|
case 0x000D:
|
|
|
|
case 0x0020:
|
|
|
|
case 0x0009:
|
|
|
|
case 0xFEFF:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static UBool isNewline(UChar32 c) {
|
|
|
|
switch (c) {
|
|
|
|
/* '\n', '\r', 0x2029 */
|
|
|
|
case 0x000A:
|
|
|
|
case 0x2029:
|
|
|
|
lineCount++;
|
|
|
|
case 0x000D:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|