1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1998-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File uscnnf_p.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 12/02/98 stephen Creation.
|
|
|
|
* 03/13/99 stephen Modified for new C API.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uscanf_p.h"
|
|
|
|
#include "ufmt_cmn.h"
|
|
|
|
|
|
|
|
/* flag characters for u_scanf */
|
|
|
|
#define FLAG_ASTERISK 0x002A
|
|
|
|
#define FLAG_PAREN 0x0028
|
|
|
|
|
|
|
|
#define ISFLAG(s) (s) == FLAG_ASTERISK || \
|
|
|
|
(s) == FLAG_PAREN
|
|
|
|
|
|
|
|
/* special characters for u_scanf */
|
|
|
|
#define SPEC_DOLLARSIGN 0x0024
|
|
|
|
|
|
|
|
/* unicode digits */
|
|
|
|
#define DIGIT_ZERO 0x0030
|
|
|
|
#define DIGIT_ONE 0x0031
|
|
|
|
#define DIGIT_TWO 0x0032
|
|
|
|
#define DIGIT_THREE 0x0033
|
|
|
|
#define DIGIT_FOUR 0x0034
|
|
|
|
#define DIGIT_FIVE 0x0035
|
|
|
|
#define DIGIT_SIX 0x0036
|
|
|
|
#define DIGIT_SEVEN 0x0037
|
|
|
|
#define DIGIT_EIGHT 0x0038
|
|
|
|
#define DIGIT_NINE 0x0039
|
|
|
|
|
|
|
|
#define ISDIGIT(s) (s) == DIGIT_ZERO || \
|
|
|
|
(s) == DIGIT_ONE || \
|
|
|
|
(s) == DIGIT_TWO || \
|
|
|
|
(s) == DIGIT_THREE || \
|
|
|
|
(s) == DIGIT_FOUR || \
|
|
|
|
(s) == DIGIT_FIVE || \
|
|
|
|
(s) == DIGIT_SIX || \
|
|
|
|
(s) == DIGIT_SEVEN || \
|
|
|
|
(s) == DIGIT_EIGHT || \
|
|
|
|
(s) == DIGIT_NINE
|
|
|
|
|
|
|
|
/* u_scanf modifiers */
|
|
|
|
#define MOD_H 0x0068
|
|
|
|
#define MOD_LOWERL 0x006C
|
|
|
|
#define MOD_L 0x004C
|
|
|
|
|
|
|
|
#define ISMOD(s) (s) == MOD_H || \
|
|
|
|
(s) == MOD_LOWERL || \
|
|
|
|
(s) == MOD_L
|
|
|
|
|
|
|
|
/* We parse the argument list in Unicode */
|
|
|
|
int32_t
|
|
|
|
u_scanf_parse_spec (const UChar *fmt,
|
|
|
|
u_scanf_spec *spec)
|
|
|
|
{
|
|
|
|
const UChar *s = fmt;
|
|
|
|
const UChar *backup;
|
2000-09-23 00:04:59 +00:00
|
|
|
u_scanf_spec_info *info = &(spec->fInfo);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* initialize spec to default values */
|
2000-09-23 00:04:59 +00:00
|
|
|
spec->fArgPos = -1;
|
|
|
|
spec->fSkipArg = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fSpec = 0x0000;
|
|
|
|
info->fWidth = -1;
|
|
|
|
info->fPadChar = 0x0020;
|
|
|
|
info->fIsLongDouble = FALSE;
|
|
|
|
info->fIsShort = FALSE;
|
|
|
|
info->fIsLong = FALSE;
|
|
|
|
info->fIsLongLong = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* skip over the initial '%' */
|
2000-09-23 00:21:17 +00:00
|
|
|
s++;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Check for positional argument */
|
|
|
|
if(ISDIGIT(*s)) {
|
|
|
|
|
|
|
|
/* Save the current position */
|
|
|
|
backup = s;
|
|
|
|
|
|
|
|
/* handle positional parameters */
|
|
|
|
if(ISDIGIT(*s)) {
|
|
|
|
spec->fArgPos = (int) (*s++ - DIGIT_ZERO);
|
|
|
|
|
|
|
|
while(ISDIGIT(*s)) {
|
2000-09-23 00:04:59 +00:00
|
|
|
spec->fArgPos *= 10;
|
|
|
|
spec->fArgPos += (int) (*s++ - DIGIT_ZERO);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there is no '$', don't read anything */
|
|
|
|
if(*s != SPEC_DOLLARSIGN) {
|
|
|
|
spec->fArgPos = -1;
|
|
|
|
s = backup;
|
|
|
|
}
|
|
|
|
/* munge the '$' */
|
|
|
|
else
|
2000-09-23 00:21:17 +00:00
|
|
|
s++;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get any format flags */
|
|
|
|
while(ISFLAG(*s)) {
|
|
|
|
switch(*s++) {
|
|
|
|
|
|
|
|
/* skip argument */
|
|
|
|
case FLAG_ASTERISK:
|
|
|
|
spec->fSkipArg = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* pad character specified */
|
|
|
|
case FLAG_PAREN:
|
|
|
|
|
|
|
|
/* first four characters are hex values for pad char */
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fPadChar = (UChar)ufmt_digitvalue(*s++);
|
|
|
|
info->fPadChar = (UChar)((info->fPadChar * 16) + ufmt_digitvalue(*s++));
|
|
|
|
info->fPadChar = (UChar)((info->fPadChar * 16) + ufmt_digitvalue(*s++));
|
|
|
|
info->fPadChar = (UChar)((info->fPadChar * 16) + ufmt_digitvalue(*s++));
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* final character is ignored */
|
2000-09-23 00:21:17 +00:00
|
|
|
s++;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the width */
|
|
|
|
if(ISDIGIT(*s)){
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fWidth = (int) (*s++ - DIGIT_ZERO);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
while(ISDIGIT(*s)) {
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fWidth *= 10;
|
|
|
|
info->fWidth += (int) (*s++ - DIGIT_ZERO);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get any modifiers */
|
|
|
|
if(ISMOD(*s)) {
|
|
|
|
switch(*s++) {
|
|
|
|
|
|
|
|
/* short */
|
|
|
|
case MOD_H:
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fIsShort = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* long or long long */
|
|
|
|
case MOD_LOWERL:
|
|
|
|
if(*s == MOD_LOWERL) {
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fIsLongLong = TRUE;
|
|
|
|
/* skip over the next 'l' */
|
2000-09-23 00:21:17 +00:00
|
|
|
s++;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
else
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fIsLong = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* long double */
|
|
|
|
case MOD_L:
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fIsLongDouble = TRUE;
|
1999-08-16 21:50:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* finally, get the specifier letter */
|
2000-09-23 00:04:59 +00:00
|
|
|
info->fSpec = *s++;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* return # of characters in this specifier */
|
|
|
|
return (s - fmt);
|
|
|
|
}
|