ICU-3499 Improve the similarity between both scanf implementations.
X-SVN-Rev: 14988
This commit is contained in:
parent
c05f6b7cf7
commit
94b0e097ef
@ -96,7 +96,7 @@
|
||||
* @return The number of arguments converted and assigned, or -1 if an
|
||||
* error occurred.
|
||||
*/
|
||||
typedef int32_t (*u_scanf_handler) (u_localized_string *input,
|
||||
typedef int32_t (*u_scanf_handler) (UFILE *stream,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -114,37 +114,37 @@ typedef struct u_scanf_info {
|
||||
|
||||
|
||||
static int32_t
|
||||
u_scanf_skip_leading_ws(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(UFILE *input,
|
||||
UChar pad)
|
||||
{
|
||||
UChar c;
|
||||
UChar *origPos = input->fPos;
|
||||
UChar *origPos = input->str.fPos;
|
||||
|
||||
/* skip all leading ws in the input */
|
||||
while( ((c = *input->fPos) != 0) && (c == pad || u_isWhitespace(c)) )
|
||||
while( ((c = *input->str.fPos) != 0) && (c == pad || u_isWhitespace(c)) )
|
||||
{
|
||||
input->fPos++;
|
||||
input->str.fPos++;
|
||||
}
|
||||
|
||||
return input->fPos - origPos;
|
||||
return input->str.fPos - origPos;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_simple_percent_handler(u_localized_string *input,
|
||||
u_scanf_simple_percent_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
int32_t *consumed)
|
||||
{
|
||||
/* make sure the next character in the input is a percent */
|
||||
if(*(input->fPos++) != 0x0025) {
|
||||
if(*(input->str.fPos++) != 0x0025) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_string_handler(u_localized_string *input,
|
||||
u_scanf_string_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -171,7 +171,7 @@ u_scanf_string_handler(u_localized_string *input,
|
||||
if(U_FAILURE(status))
|
||||
return -1;
|
||||
|
||||
while( ((c = *(input->fPos++)) != 0)
|
||||
while( ((c = *(input->str.fPos++)) != 0)
|
||||
&& (c != info->fPadChar && !u_isWhitespace(c))
|
||||
&& (info->fWidth == -1 || count < info->fWidth) )
|
||||
{
|
||||
@ -197,7 +197,7 @@ u_scanf_string_handler(u_localized_string *input,
|
||||
|
||||
/* put the final character we read back on the input */
|
||||
if(c != 0)
|
||||
input->fPos--;
|
||||
input->str.fPos--;
|
||||
|
||||
/* add the terminator */
|
||||
*alias = 0x00;
|
||||
@ -210,7 +210,7 @@ u_scanf_string_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_ustring_handler(u_localized_string *input,
|
||||
u_scanf_ustring_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -227,7 +227,7 @@ u_scanf_ustring_handler(u_localized_string *input,
|
||||
/* get the string one character at a time, truncating to the width */
|
||||
count = 0;
|
||||
|
||||
while( ((c = *(input->fPos++)) != 0)
|
||||
while( ((c = *(input->str.fPos++)) != 0)
|
||||
&& (c != info->fPadChar && ! u_isWhitespace(c))
|
||||
&& (info->fWidth == -1 || count < info->fWidth) )
|
||||
{
|
||||
@ -241,7 +241,7 @@ u_scanf_ustring_handler(u_localized_string *input,
|
||||
|
||||
/* put the final character we read back on the input */
|
||||
if(c != 0)
|
||||
input->fPos--;
|
||||
input->str.fPos--;
|
||||
|
||||
/* add the terminator */
|
||||
*alias = 0x0000;
|
||||
@ -251,7 +251,7 @@ u_scanf_ustring_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_count_handler(u_localized_string *input,
|
||||
u_scanf_count_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -268,7 +268,7 @@ u_scanf_count_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_double_handler(u_localized_string *input,
|
||||
u_scanf_double_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -285,35 +285,35 @@ u_scanf_double_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* get the formatter */
|
||||
format = u_locbund_getNumberFormat(&input->fBundle, UNUM_DECIMAL);
|
||||
format = u_locbund_getNumberFormat(&input->str.fBundle, UNUM_DECIMAL);
|
||||
|
||||
/* handle error */
|
||||
if(format == 0)
|
||||
return 0;
|
||||
|
||||
/* parse the number */
|
||||
*num = unum_parseDouble(format, input->fPos, len, &parsePos, &status);
|
||||
*num = unum_parseDouble(format, input->str.fPos, len, &parsePos, &status);
|
||||
|
||||
/* mask off any necessary bits */
|
||||
/* if(! info->fIsLong_double)
|
||||
num &= DBL_MAX;*/
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += parsePos;
|
||||
input->str.fPos += parsePos;
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_scientific_handler(u_localized_string *input,
|
||||
u_scanf_scientific_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -330,35 +330,35 @@ u_scanf_scientific_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* get the formatter */
|
||||
format = u_locbund_getNumberFormat(&input->fBundle, UNUM_SCIENTIFIC);
|
||||
format = u_locbund_getNumberFormat(&input->str.fBundle, UNUM_SCIENTIFIC);
|
||||
|
||||
/* handle error */
|
||||
if(format == 0)
|
||||
return 0;
|
||||
|
||||
/* parse the number */
|
||||
*num = unum_parseDouble(format, input->fPos, len, &parsePos, &status);
|
||||
*num = unum_parseDouble(format, input->str.fPos, len, &parsePos, &status);
|
||||
|
||||
/* mask off any necessary bits */
|
||||
/* if(! info->fIsLong_double)
|
||||
num &= DBL_MAX;*/
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += parsePos;
|
||||
input->str.fPos += parsePos;
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_scidbl_handler(u_localized_string *input,
|
||||
u_scanf_scidbl_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -384,15 +384,15 @@ u_scanf_scidbl_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* get the formatters */
|
||||
scientificFormat = u_locbund_getNumberFormat(&input->fBundle, UNUM_SCIENTIFIC);
|
||||
genericFormat = u_locbund_getNumberFormat(&input->fBundle, UNUM_DECIMAL);
|
||||
scientificFormat = u_locbund_getNumberFormat(&input->str.fBundle, UNUM_SCIENTIFIC);
|
||||
genericFormat = u_locbund_getNumberFormat(&input->str.fBundle, UNUM_DECIMAL);
|
||||
|
||||
/* handle error */
|
||||
if(scientificFormat == 0 || genericFormat == 0)
|
||||
@ -400,10 +400,10 @@ u_scanf_scidbl_handler(u_localized_string *input,
|
||||
|
||||
/* parse the number using each format*/
|
||||
|
||||
scientificResult = unum_parseDouble(scientificFormat, input->fPos, len,
|
||||
scientificResult = unum_parseDouble(scientificFormat, input->str.fPos, len,
|
||||
&scientificParsePos, &scientificStatus);
|
||||
|
||||
genericResult = unum_parseDouble(genericFormat, input->fPos, len,
|
||||
genericResult = unum_parseDouble(genericFormat, input->str.fPos, len,
|
||||
&genericParsePos, &genericStatus);
|
||||
|
||||
/* determine which parse made it farther */
|
||||
@ -411,13 +411,13 @@ u_scanf_scidbl_handler(u_localized_string *input,
|
||||
/* stash the result in num */
|
||||
*num = scientificResult;
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += scientificParsePos;
|
||||
input->str.fPos += scientificParsePos;
|
||||
}
|
||||
else {
|
||||
/* stash the result in num */
|
||||
*num = genericResult;
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += genericParsePos;
|
||||
input->str.fPos += genericParsePos;
|
||||
}
|
||||
|
||||
/* mask off any necessary bits */
|
||||
@ -429,7 +429,7 @@ u_scanf_scidbl_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_integer_handler(u_localized_string *input,
|
||||
u_scanf_integer_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -447,21 +447,21 @@ u_scanf_integer_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* get the formatter */
|
||||
format = u_locbund_getNumberFormat(&input->fBundle, UNUM_DECIMAL);
|
||||
format = u_locbund_getNumberFormat(&input->str.fBundle, UNUM_DECIMAL);
|
||||
|
||||
/* handle error */
|
||||
if(format == 0)
|
||||
return 0;
|
||||
|
||||
/* parse the number */
|
||||
result = unum_parseInt64(format, input->fPos, len, &parsePos, &status);
|
||||
result = unum_parseInt64(format, input->str.fPos, len, &parsePos, &status);
|
||||
|
||||
/* mask off any necessary bits */
|
||||
if (info->fIsShort)
|
||||
@ -472,14 +472,14 @@ u_scanf_integer_handler(u_localized_string *input,
|
||||
*(int32_t*)num = (int32_t)(UINT32_MAX & result);
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += parsePos;
|
||||
input->str.fPos += parsePos;
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_uinteger_handler(u_localized_string *input,
|
||||
u_scanf_uinteger_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -499,7 +499,7 @@ u_scanf_uinteger_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_percent_handler(u_localized_string *input,
|
||||
u_scanf_percent_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -516,35 +516,35 @@ u_scanf_percent_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* get the formatter */
|
||||
format = u_locbund_getNumberFormat(&input->fBundle, UNUM_PERCENT);
|
||||
format = u_locbund_getNumberFormat(&input->str.fBundle, UNUM_PERCENT);
|
||||
|
||||
/* handle error */
|
||||
if(format == 0)
|
||||
return 0;
|
||||
|
||||
/* parse the number */
|
||||
*num = unum_parseDouble(format, input->fPos, len, &parsePos, &status);
|
||||
*num = unum_parseDouble(format, input->str.fPos, len, &parsePos, &status);
|
||||
|
||||
/* mask off any necessary bits */
|
||||
/* if(! info->fIsLong_double)
|
||||
num &= DBL_MAX;*/
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += parsePos;
|
||||
input->str.fPos += parsePos;
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_char_handler(u_localized_string *input,
|
||||
u_scanf_char_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -559,7 +559,7 @@ u_scanf_char_handler(u_localized_string *input,
|
||||
|
||||
/* get the character from the input, truncating to the width */
|
||||
if(info->fWidth == -1 || info->fWidth > 1)
|
||||
uc = *(input->fPos++);
|
||||
uc = *(input->str.fPos++);
|
||||
|
||||
/* handle EOF */
|
||||
if(uc == 0)
|
||||
@ -577,7 +577,7 @@ u_scanf_char_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_uchar_handler(u_localized_string *input,
|
||||
u_scanf_uchar_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -590,7 +590,7 @@ u_scanf_uchar_handler(u_localized_string *input,
|
||||
|
||||
/* get the character from the input, truncating to the width */
|
||||
if(info->fWidth == -1 || info->fWidth > 1)
|
||||
*c = *(input->fPos++);
|
||||
*c = *(input->str.fPos++);
|
||||
|
||||
/* handle EOF */
|
||||
if(*c == 0)
|
||||
@ -601,7 +601,7 @@ u_scanf_uchar_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_spellout_handler(u_localized_string *input,
|
||||
u_scanf_spellout_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -618,35 +618,35 @@ u_scanf_spellout_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* get the formatter */
|
||||
format = u_locbund_getNumberFormat(&input->fBundle, UNUM_SPELLOUT);
|
||||
format = u_locbund_getNumberFormat(&input->str.fBundle, UNUM_SPELLOUT);
|
||||
|
||||
/* handle error */
|
||||
if(format == 0)
|
||||
return 0;
|
||||
|
||||
/* parse the number */
|
||||
*num = unum_parseDouble(format, input->fPos, len, &parsePos, &status);
|
||||
*num = unum_parseDouble(format, input->str.fPos, len, &parsePos, &status);
|
||||
|
||||
/* mask off any necessary bits */
|
||||
/* if(! info->fIsLong_double)
|
||||
num &= DBL_MAX;*/
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += parsePos;
|
||||
input->str.fPos += parsePos;
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_hex_handler(u_localized_string *input,
|
||||
u_scanf_hex_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -661,26 +661,26 @@ u_scanf_hex_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* check for alternate form */
|
||||
if( *(input->fPos) == 0x0030 &&
|
||||
(*(input->fPos + 1) == 0x0078 || *(input->fPos + 1) == 0x0058) ) {
|
||||
if( *(input->str.fPos) == 0x0030 &&
|
||||
(*(input->str.fPos + 1) == 0x0078 || *(input->str.fPos + 1) == 0x0058) ) {
|
||||
|
||||
/* skip the '0' and 'x' or 'X' if present */
|
||||
input->fPos += 2;
|
||||
input->str.fPos += 2;
|
||||
len -= 2;
|
||||
}
|
||||
|
||||
/* parse the number */
|
||||
result = ufmt_uto64(input->fPos, &len, 16);
|
||||
result = ufmt_uto64(input->str.fPos, &len, 16);
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += len;
|
||||
input->str.fPos += len;
|
||||
|
||||
/* mask off any necessary bits */
|
||||
if (info->fIsShort)
|
||||
@ -695,7 +695,7 @@ u_scanf_hex_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_octal_handler(u_localized_string *input,
|
||||
u_scanf_octal_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -709,17 +709,17 @@ u_scanf_octal_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* parse the number */
|
||||
result = ufmt_uto64(input->fPos, &len, 8);
|
||||
result = ufmt_uto64(input->str.fPos, &len, 8);
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += len;
|
||||
input->str.fPos += len;
|
||||
|
||||
/* mask off any necessary bits */
|
||||
if (info->fIsShort)
|
||||
@ -734,7 +734,7 @@ u_scanf_octal_handler(u_localized_string *input,
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_pointer_handler(u_localized_string *input,
|
||||
u_scanf_pointer_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -748,24 +748,24 @@ u_scanf_pointer_handler(u_localized_string *input,
|
||||
u_scanf_skip_leading_ws(input, info->fPadChar);
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
len = ufmt_min(len, info->fWidth);
|
||||
|
||||
/* parse the pointer - cast to void** to assign to *p */
|
||||
*(void**)p = (void*) ufmt_uto64(input->fPos, &len, 16);
|
||||
*(void**)p = (void*) ufmt_uto64(input->str.fPos, &len, 16);
|
||||
|
||||
/* update the input's position to reflect consumed data */
|
||||
input->fPos += len;
|
||||
input->str.fPos += len;
|
||||
|
||||
/* we converted 1 arg */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
u_scanf_scanset_handler(u_localized_string *input,
|
||||
u_scanf_scanset_handler(UFILE *input,
|
||||
const u_scanf_spec_info *info,
|
||||
ufmt_args *args,
|
||||
const UChar *fmt,
|
||||
@ -785,7 +785,7 @@ u_scanf_scanset_handler(u_localized_string *input,
|
||||
fmt--;
|
||||
|
||||
/* determine the size of the input's buffer */
|
||||
len = input->fLimit - input->fPos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
|
||||
/* truncate to the width, if specified */
|
||||
if(info->fWidth != -1)
|
||||
@ -804,9 +804,9 @@ u_scanf_scanset_handler(u_localized_string *input,
|
||||
/* grab characters one at a time and make sure they are in the scanset */
|
||||
while(alias < limit) {
|
||||
int32_t pos = 0;
|
||||
len = input->fLimit - input->fPos;
|
||||
U16_NEXT(input->fPos, pos, len, c);
|
||||
input->fPos+=pos;
|
||||
len = input->str.fLimit - input->str.fPos;
|
||||
U16_NEXT(input->str.fPos, pos, len, c);
|
||||
input->str.fPos+=pos;
|
||||
if(c != 0 && uset_contains(scanset, c)) {
|
||||
int32_t idx = 0;
|
||||
UBool isError = FALSE;
|
||||
@ -826,7 +826,7 @@ u_scanf_scanset_handler(u_localized_string *input,
|
||||
|
||||
/* put the final character we read back on the input */
|
||||
if(c != 0) {
|
||||
input->fPos--;
|
||||
input->str.fPos--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -952,7 +952,7 @@ static const u_scanf_info g_u_scanf_infos[USCANF_NUM_FMT_HANDLERS] = {
|
||||
UFMT_EMPTY, UFMT_EMPTY, UFMT_EMPTY, UFMT_EMPTY,
|
||||
};
|
||||
|
||||
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
||||
u_vsscanf_u(const UChar *buffer,
|
||||
const char *locale,
|
||||
const UChar *patternSpecification,
|
||||
@ -963,7 +963,7 @@ u_vsscanf_u(const UChar *buffer,
|
||||
uint16_t handlerNum;
|
||||
|
||||
ufmt_args args;
|
||||
u_localized_string inStr;
|
||||
UFILE inStr;
|
||||
u_scanf_spec spec;
|
||||
ufmt_type_info info;
|
||||
u_scanf_handler handler;
|
||||
@ -971,14 +971,19 @@ u_vsscanf_u(const UChar *buffer,
|
||||
/* alias the pattern */
|
||||
alias = patternSpecification;
|
||||
|
||||
inStr.fBuffer = (UChar *)buffer;
|
||||
inStr.fPos = (UChar *)buffer;
|
||||
inStr.fLimit = buffer + u_strlen(buffer);
|
||||
inStr.fConverter = NULL;
|
||||
inStr.fFile = NULL;
|
||||
inStr.fOwnFile = FALSE;
|
||||
inStr.fTranslit = NULL;
|
||||
inStr.fUCBuffer[0] = 0;
|
||||
inStr.str.fBuffer = (UChar *)buffer;
|
||||
inStr.str.fPos = (UChar *)buffer;
|
||||
inStr.str.fLimit = buffer + u_strlen(buffer);
|
||||
|
||||
/* haven't converted anything yet */
|
||||
converted = 0;
|
||||
|
||||
if(u_locbund_init(&inStr.fBundle, locale) == 0) {
|
||||
if(u_locbund_init(&inStr.str.fBundle, locale) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -986,7 +991,7 @@ u_vsscanf_u(const UChar *buffer,
|
||||
for(;;) {
|
||||
|
||||
/* match any characters up to the next '%' */
|
||||
while(*alias != UP_PERCENT && *alias != 0x0000 && *(inStr.fPos++) == *alias) {
|
||||
while(*alias != UP_PERCENT && *alias != 0x0000 && *(inStr.str.fPos++) == *alias) {
|
||||
alias++;
|
||||
}
|
||||
|
||||
@ -1057,7 +1062,7 @@ u_vsscanf_u(const UChar *buffer,
|
||||
|
||||
/* just ignore unknown tags */
|
||||
}
|
||||
u_locbund_close(&inStr.fBundle);
|
||||
u_locbund_close(&inStr.str.fBundle);
|
||||
|
||||
/* return # of items converted */
|
||||
return converted;
|
||||
|
@ -45,9 +45,9 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
typedef struct u_localized_string {
|
||||
UChar *fBuffer; /* Place to write the string */
|
||||
UChar *fPos; /* current pos in fUCBuffer */
|
||||
const UChar *fLimit; /* data limit in fUCBuffer */
|
||||
UChar *fBuffer; /* Place to write the string */
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
ULocaleBundle fBundle; /* formatters */
|
||||
|
@ -29,8 +29,7 @@
|
||||
/**
|
||||
* Enum representing the possible argument types for uprintf/uscanf
|
||||
*/
|
||||
enum ufmt_type_info
|
||||
{
|
||||
typedef enum ufmt_type_info {
|
||||
ufmt_empty = 0,
|
||||
ufmt_simple_percent, /* %% do nothing */
|
||||
ufmt_count, /* special flag for count */
|
||||
@ -46,21 +45,19 @@ enum ufmt_type_info
|
||||
/*ufmt_wstring,*/ /* wchar_t* */
|
||||
/*ufmt_date,*/ /* Date */
|
||||
ufmt_last
|
||||
};
|
||||
typedef enum ufmt_type_info ufmt_type_info;
|
||||
} ufmt_type_info;
|
||||
|
||||
/**
|
||||
* Union representing a uprintf/uscanf argument
|
||||
*/
|
||||
union ufmt_args {
|
||||
int64_t int64Value; /* int, UChar */ /* TODO: Should int32_t be used instead of int? */
|
||||
float floatValue; /* float */
|
||||
double doubleValue; /* double */
|
||||
void *ptrValue; /* any pointer - void*, char*, wchar_t*, UChar* */
|
||||
/*wchar_t wcharValue;*/ /* wchar_t */ /* TODO: Should wchar_t be used? */
|
||||
/*UDate dateValue;*/ /* Date */
|
||||
};
|
||||
typedef union ufmt_args ufmt_args;
|
||||
typedef union ufmt_args {
|
||||
int64_t int64Value; /* int, UChar */
|
||||
float floatValue; /* float */
|
||||
double doubleValue; /* double */
|
||||
void *ptrValue; /* any pointer - void*, char*, wchar_t*, UChar* */
|
||||
/*wchar_t wcharValue;*/ /* wchar_t */ /* TODO: Should wchar_t be used? */
|
||||
/*UDate dateValue;*/ /* Date */
|
||||
} ufmt_args;
|
||||
|
||||
/**
|
||||
* Macro for determining the minimum of two numbers.
|
||||
@ -145,17 +142,6 @@ char*
|
||||
ufmt_unicodeToDefaultCP(const UChar *s,
|
||||
int32_t len);
|
||||
|
||||
/**
|
||||
* Get the number of fraction digits based on the requested precision.
|
||||
* This is a shortcoming of the formatting API, which doesn't
|
||||
* support precision
|
||||
* @param num The number to look at
|
||||
* @param precision The requested precision
|
||||
* @return The fraction digits size to use on the formatting API.
|
||||
*/
|
||||
int32_t
|
||||
ufmt_getFractionDigits(double num, int32_t precision);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1135,6 +1135,7 @@ u_printf_print_spec(const u_printf_stream_handler *streamHandler,
|
||||
/* pad character specified */
|
||||
case FLAG_PAREN:
|
||||
|
||||
/* TODO test that all four are numbers */
|
||||
/* first four characters are hex values for pad char */
|
||||
info->fPadChar = (UChar)ufmt_digitvalue(*s++);
|
||||
info->fPadChar = (UChar)((info->fPadChar * 16) + ufmt_digitvalue(*s++));
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include "unicode/udat.h"
|
||||
#include "unicode/uset.h"
|
||||
#include "uscanf.h"
|
||||
#include "uscanf_p.h"
|
||||
#include "ufile.h"
|
||||
#include "uscanf_p.h"
|
||||
#include "locbund.h"
|
||||
|
||||
#include "cmemory.h"
|
||||
@ -876,7 +876,7 @@ u_scanf_scanset_handler(UFILE *input,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
u_fscanf(UFILE *f,
|
||||
const char *patternSpecification,
|
||||
... )
|
||||
@ -891,7 +891,7 @@ u_fscanf(UFILE *f,
|
||||
return converted;
|
||||
}
|
||||
|
||||
int32_t
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
u_fscanf_u(UFILE *f,
|
||||
const UChar *patternSpecification,
|
||||
... )
|
||||
|
@ -390,6 +390,11 @@ ufile_fill_uchar_buffer(UFILE *f)
|
||||
char charBuffer[UFILE_CHARBUFFER_SIZE];
|
||||
u_localized_string *str;
|
||||
|
||||
if (f->fFile == NULL) {
|
||||
/* There is nothing to do. It's a string. */
|
||||
return;
|
||||
}
|
||||
|
||||
/* shift the buffer if it isn't empty */
|
||||
str = &f->str;
|
||||
dataSize = (int32_t)(str->fLimit - str->fPos);
|
||||
|
Loading…
Reference in New Issue
Block a user