]>
git.saurik.com Git - apple/icu.git/blob - icuSources/extra/ustdio/sscanf_p.c
2 ******************************************************************************
4 * Copyright (C) 2000-2001, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 02/08/00 george Creation. Copied from uscnnf_p.h
15 ******************************************************************************
18 #include "unicode/utypes.h"
20 #if !UCONFIG_NO_FORMATTING
25 /* flag characters for u_scanf */
26 #define FLAG_ASTERISK 0x002A
27 #define FLAG_PAREN 0x0028
29 #define ISFLAG(s) (s) == FLAG_ASTERISK || \
32 /* special characters for u_scanf */
33 #define SPEC_DOLLARSIGN 0x0024
36 #define DIGIT_ZERO 0x0030
37 #define DIGIT_ONE 0x0031
38 #define DIGIT_TWO 0x0032
39 #define DIGIT_THREE 0x0033
40 #define DIGIT_FOUR 0x0034
41 #define DIGIT_FIVE 0x0035
42 #define DIGIT_SIX 0x0036
43 #define DIGIT_SEVEN 0x0037
44 #define DIGIT_EIGHT 0x0038
45 #define DIGIT_NINE 0x0039
47 #define ISDIGIT(s) (s) == DIGIT_ZERO || \
50 (s) == DIGIT_THREE || \
51 (s) == DIGIT_FOUR || \
52 (s) == DIGIT_FIVE || \
54 (s) == DIGIT_SEVEN || \
55 (s) == DIGIT_EIGHT || \
58 /* u_scanf modifiers */
60 #define MOD_LOWERL 0x006C
63 #define ISMOD(s) (s) == MOD_H || \
64 (s) == MOD_LOWERL || \
67 /* We parse the argument list in Unicode */
69 u_sscanf_parse_spec (const UChar
*fmt
,
74 u_sscanf_spec_info
*info
= &(spec
->fInfo
);
76 /* initialize spec to default values */
78 spec
->fSkipArg
= FALSE
;
82 info
->fPadChar
= 0x0020;
83 info
->fIsLongDouble
= FALSE
;
84 info
->fIsShort
= FALSE
;
85 info
->fIsLong
= FALSE
;
86 info
->fIsLongLong
= FALSE
;
89 /* skip over the initial '%' */
92 /* Check for positional argument */
95 /* Save the current position */
98 /* handle positional parameters */
100 spec
->fArgPos
= (int) (*s
++ - DIGIT_ZERO
);
104 spec
->fArgPos
+= (int) (*s
++ - DIGIT_ZERO
);
108 /* if there is no '$', don't read anything */
109 if(*s
!= SPEC_DOLLARSIGN
) {
118 /* Get any format flags */
124 spec
->fSkipArg
= TRUE
;
127 /* pad character specified */
130 /* first four characters are hex values for pad char */
131 info
->fPadChar
= (UChar
)ufmt_digitvalue(*s
++);
132 info
->fPadChar
= (UChar
)((info
->fPadChar
* 16) + ufmt_digitvalue(*s
++));
133 info
->fPadChar
= (UChar
)((info
->fPadChar
* 16) + ufmt_digitvalue(*s
++));
134 info
->fPadChar
= (UChar
)((info
->fPadChar
* 16) + ufmt_digitvalue(*s
++));
136 /* final character is ignored */
145 info
->fWidth
= (int) (*s
++ - DIGIT_ZERO
);
149 info
->fWidth
+= (int) (*s
++ - DIGIT_ZERO
);
153 /* Get any modifiers */
159 info
->fIsShort
= TRUE
;
162 /* long or long long */
164 if(*s
== MOD_LOWERL
) {
165 info
->fIsLongLong
= TRUE
;
166 /* skip over the next 'l' */
170 info
->fIsLong
= TRUE
;
175 info
->fIsLongDouble
= TRUE
;
180 /* finally, get the specifier letter */
183 /* return # of characters in this specifier */
184 return (int32_t)(s
- fmt
);
187 #endif /* #if !UCONFIG_NO_FORMATTING */