]>
git.saurik.com Git - apple/icu.git/blob - icuSources/io/sscanf.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 2000-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
13 * Modification History:
15 * Date Name Description
16 * 02/08/00 george Creation. Copied from uscanf.c
17 ******************************************************************************
20 #include "unicode/utypes.h"
22 #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_CONVERSION
24 #include "unicode/putil.h"
25 #include "unicode/ustdio.h"
26 #include "unicode/ustring.h"
35 U_CAPI
int32_t U_EXPORT2
36 u_sscanf(const UChar
*buffer
,
37 const char *patternSpecification
,
43 va_start(ap
, patternSpecification
);
44 converted
= u_vsscanf(buffer
, patternSpecification
, ap
);
50 U_CAPI
int32_t U_EXPORT2
51 u_sscanf_u(const UChar
*buffer
,
52 const UChar
*patternSpecification
,
58 va_start(ap
, patternSpecification
);
59 converted
= u_vsscanf_u(buffer
, patternSpecification
, ap
);
65 U_CAPI
int32_t U_EXPORT2
/* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
66 u_vsscanf(const UChar
*buffer
,
67 const char *patternSpecification
,
72 UChar patBuffer
[UFMT_DEFAULT_BUFFER_SIZE
];
73 int32_t size
= (int32_t)uprv_strlen(patternSpecification
) + 1;
75 /* convert from the default codepage to Unicode */
76 if (size
>= (int32_t)MAX_UCHAR_BUFFER_SIZE(patBuffer
)) {
77 pattern
= (UChar
*)uprv_malloc(size
* sizeof(UChar
));
85 u_charsToUChars(patternSpecification
, pattern
, size
);
88 converted
= u_vsscanf_u(buffer
, pattern
, ap
);
91 if (pattern
!= patBuffer
) {
98 U_CAPI
int32_t U_EXPORT2
/* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
99 u_vsscanf_u(const UChar
*buffer
,
100 const UChar
*patternSpecification
,
106 inStr
.fConverter
= NULL
;
108 inStr
.fOwnFile
= FALSE
;
109 #if !UCONFIG_NO_TRANSLITERATION
110 inStr
.fTranslit
= NULL
;
112 inStr
.fUCBuffer
[0] = 0;
113 inStr
.str
.fBuffer
= (UChar
*)buffer
;
114 inStr
.str
.fPos
= (UChar
*)buffer
;
115 inStr
.str
.fLimit
= buffer
+ u_strlen(buffer
);
117 if(u_locbund_init(&inStr
.str
.fBundle
, "en_US_POSIX") == 0) {
121 converted
= u_scanf_parse(&inStr
, patternSpecification
, ap
);
123 u_locbund_close(&inStr
.str
.fBundle
);
125 /* return # of items converted */
129 #endif /* #if !UCONFIG_NO_FORMATTING */