Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ****************************************************************************** |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2000-2004, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ****************************************************************************** |
michael@0 | 8 | * |
michael@0 | 9 | * File sscanf.c |
michael@0 | 10 | * |
michael@0 | 11 | * Modification History: |
michael@0 | 12 | * |
michael@0 | 13 | * Date Name Description |
michael@0 | 14 | * 02/08/00 george Creation. Copied from uscanf.c |
michael@0 | 15 | ****************************************************************************** |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | #include "unicode/utypes.h" |
michael@0 | 19 | |
michael@0 | 20 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 21 | |
michael@0 | 22 | #include "unicode/putil.h" |
michael@0 | 23 | #include "unicode/ustdio.h" |
michael@0 | 24 | #include "unicode/ustring.h" |
michael@0 | 25 | #include "uscanf.h" |
michael@0 | 26 | #include "ufile.h" |
michael@0 | 27 | #include "ufmt_cmn.h" |
michael@0 | 28 | |
michael@0 | 29 | #include "cmemory.h" |
michael@0 | 30 | #include "cstring.h" |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 34 | u_sscanf(const UChar *buffer, |
michael@0 | 35 | const char *patternSpecification, |
michael@0 | 36 | ... ) |
michael@0 | 37 | { |
michael@0 | 38 | va_list ap; |
michael@0 | 39 | int32_t converted; |
michael@0 | 40 | |
michael@0 | 41 | va_start(ap, patternSpecification); |
michael@0 | 42 | converted = u_vsscanf(buffer, patternSpecification, ap); |
michael@0 | 43 | va_end(ap); |
michael@0 | 44 | |
michael@0 | 45 | return converted; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 49 | u_sscanf_u(const UChar *buffer, |
michael@0 | 50 | const UChar *patternSpecification, |
michael@0 | 51 | ... ) |
michael@0 | 52 | { |
michael@0 | 53 | va_list ap; |
michael@0 | 54 | int32_t converted; |
michael@0 | 55 | |
michael@0 | 56 | va_start(ap, patternSpecification); |
michael@0 | 57 | converted = u_vsscanf_u(buffer, patternSpecification, ap); |
michael@0 | 58 | va_end(ap); |
michael@0 | 59 | |
michael@0 | 60 | return converted; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ |
michael@0 | 64 | u_vsscanf(const UChar *buffer, |
michael@0 | 65 | const char *patternSpecification, |
michael@0 | 66 | va_list ap) |
michael@0 | 67 | { |
michael@0 | 68 | int32_t converted; |
michael@0 | 69 | UChar *pattern; |
michael@0 | 70 | UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE]; |
michael@0 | 71 | int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1; |
michael@0 | 72 | |
michael@0 | 73 | /* convert from the default codepage to Unicode */ |
michael@0 | 74 | if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) { |
michael@0 | 75 | pattern = (UChar *)uprv_malloc(size * sizeof(UChar)); |
michael@0 | 76 | if(pattern == 0) { |
michael@0 | 77 | return 0; |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | else { |
michael@0 | 81 | pattern = patBuffer; |
michael@0 | 82 | } |
michael@0 | 83 | u_charsToUChars(patternSpecification, pattern, size); |
michael@0 | 84 | |
michael@0 | 85 | /* do the work */ |
michael@0 | 86 | converted = u_vsscanf_u(buffer, pattern, ap); |
michael@0 | 87 | |
michael@0 | 88 | /* clean up */ |
michael@0 | 89 | if (pattern != patBuffer) { |
michael@0 | 90 | uprv_free(pattern); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | return converted; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ |
michael@0 | 97 | u_vsscanf_u(const UChar *buffer, |
michael@0 | 98 | const UChar *patternSpecification, |
michael@0 | 99 | va_list ap) |
michael@0 | 100 | { |
michael@0 | 101 | int32_t converted; |
michael@0 | 102 | UFILE inStr; |
michael@0 | 103 | |
michael@0 | 104 | inStr.fConverter = NULL; |
michael@0 | 105 | inStr.fFile = NULL; |
michael@0 | 106 | inStr.fOwnFile = FALSE; |
michael@0 | 107 | #if !UCONFIG_NO_TRANSLITERATION |
michael@0 | 108 | inStr.fTranslit = NULL; |
michael@0 | 109 | #endif |
michael@0 | 110 | inStr.fUCBuffer[0] = 0; |
michael@0 | 111 | inStr.str.fBuffer = (UChar *)buffer; |
michael@0 | 112 | inStr.str.fPos = (UChar *)buffer; |
michael@0 | 113 | inStr.str.fLimit = buffer + u_strlen(buffer); |
michael@0 | 114 | |
michael@0 | 115 | if(u_locbund_init(&inStr.str.fBundle, "en_US_POSIX") == 0) { |
michael@0 | 116 | return 0; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | converted = u_scanf_parse(&inStr, patternSpecification, ap); |
michael@0 | 120 | |
michael@0 | 121 | u_locbund_close(&inStr.str.fBundle); |
michael@0 | 122 | |
michael@0 | 123 | /* return # of items converted */ |
michael@0 | 124 | return converted; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 128 |