michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 2000-2004, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * File sscanf.c michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 02/08/00 george Creation. Copied from uscanf.c michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/putil.h" michael@0: #include "unicode/ustdio.h" michael@0: #include "unicode/ustring.h" michael@0: #include "uscanf.h" michael@0: #include "ufile.h" michael@0: #include "ufmt_cmn.h" michael@0: michael@0: #include "cmemory.h" michael@0: #include "cstring.h" michael@0: michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_sscanf(const UChar *buffer, michael@0: const char *patternSpecification, michael@0: ... ) michael@0: { michael@0: va_list ap; michael@0: int32_t converted; michael@0: michael@0: va_start(ap, patternSpecification); michael@0: converted = u_vsscanf(buffer, patternSpecification, ap); michael@0: va_end(ap); michael@0: michael@0: return converted; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_sscanf_u(const UChar *buffer, michael@0: const UChar *patternSpecification, michael@0: ... ) michael@0: { michael@0: va_list ap; michael@0: int32_t converted; michael@0: michael@0: va_start(ap, patternSpecification); michael@0: converted = u_vsscanf_u(buffer, patternSpecification, ap); michael@0: va_end(ap); michael@0: michael@0: return converted; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ michael@0: u_vsscanf(const UChar *buffer, michael@0: const char *patternSpecification, michael@0: va_list ap) michael@0: { michael@0: int32_t converted; michael@0: UChar *pattern; michael@0: UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE]; michael@0: int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1; michael@0: michael@0: /* convert from the default codepage to Unicode */ michael@0: if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) { michael@0: pattern = (UChar *)uprv_malloc(size * sizeof(UChar)); michael@0: if(pattern == 0) { michael@0: return 0; michael@0: } michael@0: } michael@0: else { michael@0: pattern = patBuffer; michael@0: } michael@0: u_charsToUChars(patternSpecification, pattern, size); michael@0: michael@0: /* do the work */ michael@0: converted = u_vsscanf_u(buffer, pattern, ap); michael@0: michael@0: /* clean up */ michael@0: if (pattern != patBuffer) { michael@0: uprv_free(pattern); michael@0: } michael@0: michael@0: return converted; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ michael@0: u_vsscanf_u(const UChar *buffer, michael@0: const UChar *patternSpecification, michael@0: va_list ap) michael@0: { michael@0: int32_t converted; michael@0: UFILE inStr; michael@0: michael@0: inStr.fConverter = NULL; michael@0: inStr.fFile = NULL; michael@0: inStr.fOwnFile = FALSE; michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: inStr.fTranslit = NULL; michael@0: #endif michael@0: inStr.fUCBuffer[0] = 0; michael@0: inStr.str.fBuffer = (UChar *)buffer; michael@0: inStr.str.fPos = (UChar *)buffer; michael@0: inStr.str.fLimit = buffer + u_strlen(buffer); michael@0: michael@0: if(u_locbund_init(&inStr.str.fBundle, "en_US_POSIX") == 0) { michael@0: return 0; michael@0: } michael@0: michael@0: converted = u_scanf_parse(&inStr, patternSpecification, ap); michael@0: michael@0: u_locbund_close(&inStr.str.fBundle); michael@0: michael@0: /* return # of items converted */ michael@0: return converted; michael@0: } michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: