intl/icu/source/io/uscanf.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1998-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 uscanf.c
michael@0 10 *
michael@0 11 * Modification History:
michael@0 12 *
michael@0 13 * Date Name Description
michael@0 14 * 12/02/98 stephen Creation.
michael@0 15 * 03/13/99 stephen Modified for new C API.
michael@0 16 ******************************************************************************
michael@0 17 */
michael@0 18
michael@0 19 #include "unicode/utypes.h"
michael@0 20
michael@0 21 #if !UCONFIG_NO_FORMATTING
michael@0 22
michael@0 23 #include "unicode/putil.h"
michael@0 24 #include "unicode/ustdio.h"
michael@0 25 #include "unicode/ustring.h"
michael@0 26 #include "uscanf.h"
michael@0 27 #include "ufile.h"
michael@0 28 #include "ufmt_cmn.h"
michael@0 29
michael@0 30 #include "cmemory.h"
michael@0 31 #include "cstring.h"
michael@0 32
michael@0 33
michael@0 34 U_CAPI int32_t U_EXPORT2
michael@0 35 u_fscanf(UFILE *f,
michael@0 36 const char *patternSpecification,
michael@0 37 ... )
michael@0 38 {
michael@0 39 va_list ap;
michael@0 40 int32_t converted;
michael@0 41
michael@0 42 va_start(ap, patternSpecification);
michael@0 43 converted = u_vfscanf(f, patternSpecification, ap);
michael@0 44 va_end(ap);
michael@0 45
michael@0 46 return converted;
michael@0 47 }
michael@0 48
michael@0 49 U_CAPI int32_t U_EXPORT2
michael@0 50 u_fscanf_u(UFILE *f,
michael@0 51 const UChar *patternSpecification,
michael@0 52 ... )
michael@0 53 {
michael@0 54 va_list ap;
michael@0 55 int32_t converted;
michael@0 56
michael@0 57 va_start(ap, patternSpecification);
michael@0 58 converted = u_vfscanf_u(f, patternSpecification, ap);
michael@0 59 va_end(ap);
michael@0 60
michael@0 61 return converted;
michael@0 62 }
michael@0 63
michael@0 64 U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
michael@0 65 u_vfscanf(UFILE *f,
michael@0 66 const char *patternSpecification,
michael@0 67 va_list ap)
michael@0 68 {
michael@0 69 int32_t converted;
michael@0 70 UChar *pattern;
michael@0 71 UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE];
michael@0 72 int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1;
michael@0 73
michael@0 74 /* convert from the default codepage to Unicode */
michael@0 75 if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) {
michael@0 76 pattern = (UChar *)uprv_malloc(size * sizeof(UChar));
michael@0 77 if(pattern == 0) {
michael@0 78 return 0;
michael@0 79 }
michael@0 80 }
michael@0 81 else {
michael@0 82 pattern = patBuffer;
michael@0 83 }
michael@0 84 u_charsToUChars(patternSpecification, pattern, size);
michael@0 85
michael@0 86 /* do the work */
michael@0 87 converted = u_vfscanf_u(f, pattern, ap);
michael@0 88
michael@0 89 /* clean up */
michael@0 90 if (pattern != patBuffer) {
michael@0 91 uprv_free(pattern);
michael@0 92 }
michael@0 93
michael@0 94 return converted;
michael@0 95 }
michael@0 96
michael@0 97 U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
michael@0 98 u_vfscanf_u(UFILE *f,
michael@0 99 const UChar *patternSpecification,
michael@0 100 va_list ap)
michael@0 101 {
michael@0 102 return u_scanf_parse(f, patternSpecification, ap);
michael@0 103 }
michael@0 104
michael@0 105 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 106

mercurial