1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/io/sscanf.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +/* 1.5 +****************************************************************************** 1.6 +* 1.7 +* Copyright (C) 2000-2004, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +****************************************************************************** 1.11 +* 1.12 +* File sscanf.c 1.13 +* 1.14 +* Modification History: 1.15 +* 1.16 +* Date Name Description 1.17 +* 02/08/00 george Creation. Copied from uscanf.c 1.18 +****************************************************************************** 1.19 +*/ 1.20 + 1.21 +#include "unicode/utypes.h" 1.22 + 1.23 +#if !UCONFIG_NO_FORMATTING 1.24 + 1.25 +#include "unicode/putil.h" 1.26 +#include "unicode/ustdio.h" 1.27 +#include "unicode/ustring.h" 1.28 +#include "uscanf.h" 1.29 +#include "ufile.h" 1.30 +#include "ufmt_cmn.h" 1.31 + 1.32 +#include "cmemory.h" 1.33 +#include "cstring.h" 1.34 + 1.35 + 1.36 +U_CAPI int32_t U_EXPORT2 1.37 +u_sscanf(const UChar *buffer, 1.38 + const char *patternSpecification, 1.39 + ... ) 1.40 +{ 1.41 + va_list ap; 1.42 + int32_t converted; 1.43 + 1.44 + va_start(ap, patternSpecification); 1.45 + converted = u_vsscanf(buffer, patternSpecification, ap); 1.46 + va_end(ap); 1.47 + 1.48 + return converted; 1.49 +} 1.50 + 1.51 +U_CAPI int32_t U_EXPORT2 1.52 +u_sscanf_u(const UChar *buffer, 1.53 + const UChar *patternSpecification, 1.54 + ... ) 1.55 +{ 1.56 + va_list ap; 1.57 + int32_t converted; 1.58 + 1.59 + va_start(ap, patternSpecification); 1.60 + converted = u_vsscanf_u(buffer, patternSpecification, ap); 1.61 + va_end(ap); 1.62 + 1.63 + return converted; 1.64 +} 1.65 + 1.66 +U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ 1.67 +u_vsscanf(const UChar *buffer, 1.68 + const char *patternSpecification, 1.69 + va_list ap) 1.70 +{ 1.71 + int32_t converted; 1.72 + UChar *pattern; 1.73 + UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE]; 1.74 + int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1; 1.75 + 1.76 + /* convert from the default codepage to Unicode */ 1.77 + if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) { 1.78 + pattern = (UChar *)uprv_malloc(size * sizeof(UChar)); 1.79 + if(pattern == 0) { 1.80 + return 0; 1.81 + } 1.82 + } 1.83 + else { 1.84 + pattern = patBuffer; 1.85 + } 1.86 + u_charsToUChars(patternSpecification, pattern, size); 1.87 + 1.88 + /* do the work */ 1.89 + converted = u_vsscanf_u(buffer, pattern, ap); 1.90 + 1.91 + /* clean up */ 1.92 + if (pattern != patBuffer) { 1.93 + uprv_free(pattern); 1.94 + } 1.95 + 1.96 + return converted; 1.97 +} 1.98 + 1.99 +U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ 1.100 +u_vsscanf_u(const UChar *buffer, 1.101 + const UChar *patternSpecification, 1.102 + va_list ap) 1.103 +{ 1.104 + int32_t converted; 1.105 + UFILE inStr; 1.106 + 1.107 + inStr.fConverter = NULL; 1.108 + inStr.fFile = NULL; 1.109 + inStr.fOwnFile = FALSE; 1.110 +#if !UCONFIG_NO_TRANSLITERATION 1.111 + inStr.fTranslit = NULL; 1.112 +#endif 1.113 + inStr.fUCBuffer[0] = 0; 1.114 + inStr.str.fBuffer = (UChar *)buffer; 1.115 + inStr.str.fPos = (UChar *)buffer; 1.116 + inStr.str.fLimit = buffer + u_strlen(buffer); 1.117 + 1.118 + if(u_locbund_init(&inStr.str.fBundle, "en_US_POSIX") == 0) { 1.119 + return 0; 1.120 + } 1.121 + 1.122 + converted = u_scanf_parse(&inStr, patternSpecification, ap); 1.123 + 1.124 + u_locbund_close(&inStr.str.fBundle); 1.125 + 1.126 + /* return # of items converted */ 1.127 + return converted; 1.128 +} 1.129 + 1.130 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.131 +