ICU-6236 remove broken 'unescape' functionality from ucbuf_ungetc. Fix error condition. Add comments to clarify code.

X-SVN-Rev: 24043
This commit is contained in:
Steven R. Loomis 2008-05-28 20:51:38 +00:00
parent 838f8d88bb
commit a4d77f9f7f
3 changed files with 15 additions and 22 deletions

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 1998-2003, International Business Machines
* Copyright (C) 1998-2008, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -340,30 +340,30 @@ static UChar32 getNextChar(UCHARBUF* buf,
return c;
}
c = ucbuf_getc(buf,status);
c = ucbuf_getc(buf,status); /* "/c" */
if (c == U_EOF) {
return U_EOF;
}
switch (c) {
case SLASH:
case SLASH: /* "//" */
seekUntilNewline(buf, NULL, status);
break;
case ASTERISK:
c2 = ucbuf_getc(buf, status);
if(c2== ASTERISK){
case ASTERISK: /* "/*" */
c2 = ucbuf_getc(buf, status); /* "/*c" */
if(c2 == ASTERISK){ /* "/**" */
/* parse multi-line comment and store it in token*/
seekUntilEndOfComment(buf, token, status);
}else{
ucbuf_ungetc(c, buf);
} else {
ucbuf_ungetc(c2, buf); /* c2 is the non-asterisk following "/*". Include c2 back in buffer. */
seekUntilEndOfComment(buf, NULL, status);
}
break;
default:
ucbuf_ungetc(c, buf);
ucbuf_ungetc(c, buf); /* "/c" - put back the c */
/* If get() failed this is a NOP */
return SLASH;
}

View file

@ -538,21 +538,14 @@ ucbuf_ungetc(int32_t c,UCHARBUF* buf){
/* decrement currentPos pointer
* if not at the begining of buffer
*/
UChar escaped[8] ={'\0'};
int32_t len =0;
if(c > 0xFFFF){
len = uprv_itou(escaped,8,c,16,8);
}else{
len=uprv_itou(escaped,8,c,16,4);
}
if(buf->currentPos!=buf->buffer){
if(*(buf->currentPos-1)==c){
buf->currentPos--;
}else if(u_strncmp(buf->currentPos-len,escaped,len) == 0){
while(--len>0){
buf->currentPos--;
}
} else {
/* ungetc failed - did not match. */
}
} else {
/* ungetc failed - beginning of buffer. */
}
}

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 1998-2005, International Business Machines
* Copyright (C) 1998-2008, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -138,7 +138,7 @@ U_CAPI void U_EXPORT2
ucbuf_close(UCHARBUF* buf);
/**
* Rewinds the buffer by one codepoint
* Rewinds the buffer by one codepoint. Does not rewind over escaped characters.
*/
U_CAPI void U_EXPORT2
ucbuf_ungetc(int32_t ungetChar,UCHARBUF* buf);