ICU-3499 Get ready for scanf merge
X-SVN-Rev: 15089
This commit is contained in:
parent
07d2c00053
commit
1f653cef10
@ -118,15 +118,20 @@ u_scanf_skip_leading_ws(UFILE *input,
|
||||
UChar pad)
|
||||
{
|
||||
UChar c;
|
||||
UChar *origPos = input->str.fPos;
|
||||
int32_t count = 0;
|
||||
UBool isNotEOF;
|
||||
|
||||
/* skip all leading ws in the input */
|
||||
while( ((c = *input->str.fPos) != 0) && (c == pad || u_isWhitespace(c)) )
|
||||
while( (isNotEOF = ufile_getch(input, &c)) && (c == pad || u_isWhitespace(c)) )
|
||||
{
|
||||
input->str.fPos++;
|
||||
count++;
|
||||
}
|
||||
|
||||
return input->str.fPos - origPos;
|
||||
/* put the final character back on the input */
|
||||
if(isNotEOF)
|
||||
u_fungetc(c, input);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
@ -137,7 +142,7 @@ u_scanf_simple_percent_handler(UFILE *input,
|
||||
int32_t *consumed)
|
||||
{
|
||||
/* make sure the next character in the input is a percent */
|
||||
if(*(input->str.fPos++) != 0x0025) {
|
||||
if(u_fgetc(input) != 0x0025) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@ -151,6 +156,7 @@ u_scanf_string_handler(UFILE *input,
|
||||
int32_t *consumed)
|
||||
{
|
||||
UChar c;
|
||||
UBool isNotEOF;
|
||||
int32_t count;
|
||||
const UChar *source;
|
||||
UConverter *conv;
|
||||
@ -171,7 +177,7 @@ u_scanf_string_handler(UFILE *input,
|
||||
if(U_FAILURE(status))
|
||||
return -1;
|
||||
|
||||
while( ((c = *(input->str.fPos++)) != 0)
|
||||
while( (isNotEOF = ufile_getch(input, &c))
|
||||
&& (c != info->fPadChar && !u_isWhitespace(c))
|
||||
&& (info->fWidth == -1 || count < info->fWidth) )
|
||||
{
|
||||
@ -196,8 +202,8 @@ u_scanf_string_handler(UFILE *input,
|
||||
}
|
||||
|
||||
/* put the final character we read back on the input */
|
||||
if(c != 0)
|
||||
input->str.fPos--;
|
||||
if(isNotEOF)
|
||||
u_fungetc(c, input);
|
||||
|
||||
/* add the terminator */
|
||||
*alias = 0x00;
|
||||
@ -217,6 +223,7 @@ u_scanf_ustring_handler(UFILE *input,
|
||||
int32_t *consumed)
|
||||
{
|
||||
UChar c;
|
||||
UBool isNotEOF;
|
||||
int32_t count;
|
||||
UChar *arg = (UChar*)(args[0].ptrValue);
|
||||
UChar *alias = arg;
|
||||
@ -227,7 +234,7 @@ u_scanf_ustring_handler(UFILE *input,
|
||||
/* get the string one character at a time, truncating to the width */
|
||||
count = 0;
|
||||
|
||||
while( ((c = *(input->str.fPos++)) != 0)
|
||||
while( (isNotEOF = ufile_getch(input, &c))
|
||||
&& (c != info->fPadChar && ! u_isWhitespace(c))
|
||||
&& (info->fWidth == -1 || count < info->fWidth) )
|
||||
{
|
||||
@ -240,8 +247,8 @@ u_scanf_ustring_handler(UFILE *input,
|
||||
}
|
||||
|
||||
/* put the final character we read back on the input */
|
||||
if(c != 0)
|
||||
input->str.fPos--;
|
||||
if(isNotEOF)
|
||||
u_fungetc(c, input);
|
||||
|
||||
/* add the terminator */
|
||||
*alias = 0x0000;
|
||||
@ -574,11 +581,8 @@ u_scanf_char_handler(UFILE *input,
|
||||
|
||||
/* get the character from the input, truncating to the width */
|
||||
if(info->fWidth == -1 || info->fWidth > 1)
|
||||
uc = *(input->str.fPos++);
|
||||
|
||||
/* handle EOF */
|
||||
if(uc == 0)
|
||||
return -1;
|
||||
if (!ufile_getch(input, &uc))
|
||||
return -1; /* no character */
|
||||
|
||||
/* convert the character to the default codepage */
|
||||
result = ufmt_unicodeToDefaultCP(&uc, 1);
|
||||
@ -605,11 +609,8 @@ u_scanf_uchar_handler(UFILE *input,
|
||||
|
||||
/* get the character from the input, truncating to the width */
|
||||
if(info->fWidth == -1 || info->fWidth > 1)
|
||||
*c = *(input->str.fPos++);
|
||||
|
||||
/* handle EOF */
|
||||
if(*c == 0)
|
||||
return -1;
|
||||
if (!ufile_getch(input, c))
|
||||
return -1; /* no character */
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
|
@ -86,6 +86,15 @@ u_file_write_flush( const UChar *chars,
|
||||
void
|
||||
ufile_fill_uchar_buffer(UFILE *f);
|
||||
|
||||
/**
|
||||
* Get one character and detect whether the end of file has been reached.
|
||||
* @param f The UFILE containing the characters.
|
||||
* @param ch The read in character
|
||||
* @return TRUE if the character is valid, or FALSE when EOF has been detected
|
||||
*/
|
||||
U_CFUNC UBool U_EXPORT2
|
||||
ufile_getch(UFILE *f, UChar *ch);
|
||||
|
||||
/**
|
||||
* Close out the transliterator and flush any data therein.
|
||||
* @param f flu
|
||||
|
@ -118,17 +118,18 @@ static int32_t
|
||||
u_scanf_skip_leading_ws(UFILE *input,
|
||||
UChar pad)
|
||||
{
|
||||
UChar c;
|
||||
int32_t count = 0;
|
||||
UChar c;
|
||||
int32_t count = 0;
|
||||
UBool isNotEOF;
|
||||
|
||||
/* skip all leading ws in the input */
|
||||
while( ((c = u_fgetc(input)) != U_EOF) && (c == pad || u_isWhitespace(c)) )
|
||||
while( (isNotEOF = ufile_getch(input, &c)) && (c == pad || u_isWhitespace(c)) )
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
/* put the final character back on the input */
|
||||
if(c != U_EOF)
|
||||
if(isNotEOF)
|
||||
u_fungetc(c, input);
|
||||
|
||||
return count;
|
||||
@ -156,6 +157,7 @@ u_scanf_string_handler(UFILE *input,
|
||||
int32_t *consumed)
|
||||
{
|
||||
UChar c;
|
||||
UBool isNotEOF;
|
||||
int32_t count;
|
||||
const UChar *source;
|
||||
UConverter *conv;
|
||||
@ -176,7 +178,7 @@ u_scanf_string_handler(UFILE *input,
|
||||
if(U_FAILURE(status))
|
||||
return -1;
|
||||
|
||||
while( ((c = u_fgetc(input)) != U_EOF)
|
||||
while( (isNotEOF = ufile_getch(input, &c))
|
||||
&& (c != info->fPadChar && !u_isWhitespace(c))
|
||||
&& (info->fWidth == -1 || count < info->fWidth) )
|
||||
{
|
||||
@ -201,7 +203,7 @@ u_scanf_string_handler(UFILE *input,
|
||||
}
|
||||
|
||||
/* put the final character we read back on the input */
|
||||
if(c != U_EOF)
|
||||
if(isNotEOF)
|
||||
u_fungetc(c, input);
|
||||
|
||||
/* add the terminator */
|
||||
@ -222,6 +224,7 @@ u_scanf_ustring_handler(UFILE *input,
|
||||
int32_t *consumed)
|
||||
{
|
||||
UChar c;
|
||||
UBool isNotEOF;
|
||||
int32_t count;
|
||||
UChar *arg = (UChar*)(args[0].ptrValue);
|
||||
UChar *alias = arg;
|
||||
@ -232,7 +235,7 @@ u_scanf_ustring_handler(UFILE *input,
|
||||
/* get the string one character at a time, truncating to the width */
|
||||
count = 0;
|
||||
|
||||
while( ((c = u_fgetc(input)) != U_EOF)
|
||||
while( (isNotEOF = ufile_getch(input, &c))
|
||||
&& (c != info->fPadChar && ! u_isWhitespace(c))
|
||||
&& (info->fWidth == -1 || count < info->fWidth) )
|
||||
{
|
||||
@ -245,7 +248,7 @@ u_scanf_ustring_handler(UFILE *input,
|
||||
}
|
||||
|
||||
/* put the final character we read back on the input */
|
||||
if(c != U_EOF)
|
||||
if(isNotEOF)
|
||||
u_fungetc(c, input);
|
||||
|
||||
/* add the terminator */
|
||||
@ -579,11 +582,8 @@ u_scanf_char_handler(UFILE *input,
|
||||
|
||||
/* get the character from the input, truncating to the width */
|
||||
if(info->fWidth == -1 || info->fWidth > 1)
|
||||
uc = u_fgetc(input);
|
||||
|
||||
/* handle EOF */
|
||||
if(uc == U_EOF)
|
||||
return -1;
|
||||
if (!ufile_getch(input, &uc))
|
||||
return -1; /* no character */
|
||||
|
||||
/* convert the character to the default codepage */
|
||||
result = ufmt_unicodeToDefaultCP(&uc, 1);
|
||||
@ -610,11 +610,8 @@ u_scanf_uchar_handler(UFILE *input,
|
||||
|
||||
/* get the character from the input, truncating to the width */
|
||||
if(info->fWidth == -1 || info->fWidth > 1)
|
||||
*c = u_fgetc(input);
|
||||
|
||||
/* handle EOF */
|
||||
if(*c == U_EOF)
|
||||
return -1;
|
||||
if (!ufile_getch(input, c))
|
||||
return -1; /* no character */
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
|
@ -541,22 +541,34 @@ u_fgets(UChar *s,
|
||||
return s;
|
||||
}
|
||||
|
||||
U_CFUNC UBool U_EXPORT2
|
||||
ufile_getch(UFILE *f, UChar *ch)
|
||||
{
|
||||
UBool isValidChar = FALSE;
|
||||
|
||||
*ch = U_EOF;
|
||||
/* if we have an available character in the buffer, return it */
|
||||
if(f->str.fPos < f->str.fLimit){
|
||||
*ch = *(f->str.fPos)++;
|
||||
isValidChar = TRUE;
|
||||
}
|
||||
else if (f) {
|
||||
/* otherwise, fill the buffer and return the next character */
|
||||
ufile_fill_uchar_buffer(f);
|
||||
if(f->str.fPos < f->str.fLimit) {
|
||||
*ch = *(f->str.fPos)++;
|
||||
isValidChar = TRUE;
|
||||
}
|
||||
}
|
||||
return isValidChar;
|
||||
}
|
||||
|
||||
U_CAPI UChar U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_fgetc(UFILE *f)
|
||||
{
|
||||
/* if we have an available character in the buffer, return it */
|
||||
if(f->str.fPos < f->str.fLimit)
|
||||
return *(f->str.fPos)++;
|
||||
/* otherwise, fill the buffer and return the next character */
|
||||
else {
|
||||
ufile_fill_uchar_buffer(f);
|
||||
if(f->str.fPos < f->str.fLimit) {
|
||||
return *(f->str.fPos)++;
|
||||
}
|
||||
else {
|
||||
return U_EOF;
|
||||
}
|
||||
}
|
||||
UChar ch;
|
||||
ufile_getch(f, &ch);
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* Read a UChar from a UFILE and process escape sequences */
|
||||
|
Loading…
Reference in New Issue
Block a user