intl/icu/source/io/uscanf.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/io/uscanf.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +/*
     1.5 +******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1998-2004, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +******************************************************************************
    1.11 +*
    1.12 +* File uscanf.c
    1.13 +*
    1.14 +* Modification History:
    1.15 +*
    1.16 +*   Date        Name        Description
    1.17 +*   12/02/98    stephen        Creation.
    1.18 +*   03/13/99    stephen     Modified for new C API.
    1.19 +******************************************************************************
    1.20 +*/
    1.21 +
    1.22 +#include "unicode/utypes.h"
    1.23 +
    1.24 +#if !UCONFIG_NO_FORMATTING
    1.25 +
    1.26 +#include "unicode/putil.h"
    1.27 +#include "unicode/ustdio.h"
    1.28 +#include "unicode/ustring.h"
    1.29 +#include "uscanf.h"
    1.30 +#include "ufile.h"
    1.31 +#include "ufmt_cmn.h"
    1.32 +
    1.33 +#include "cmemory.h"
    1.34 +#include "cstring.h"
    1.35 +
    1.36 +
    1.37 +U_CAPI int32_t U_EXPORT2
    1.38 +u_fscanf(UFILE        *f,
    1.39 +         const char    *patternSpecification,
    1.40 +         ... )
    1.41 +{
    1.42 +    va_list ap;
    1.43 +    int32_t converted;
    1.44 +
    1.45 +    va_start(ap, patternSpecification);
    1.46 +    converted = u_vfscanf(f, patternSpecification, ap);
    1.47 +    va_end(ap);
    1.48 +
    1.49 +    return converted;
    1.50 +}
    1.51 +
    1.52 +U_CAPI int32_t U_EXPORT2
    1.53 +u_fscanf_u(UFILE        *f,
    1.54 +           const UChar    *patternSpecification,
    1.55 +           ... )
    1.56 +{
    1.57 +    va_list ap;
    1.58 +    int32_t converted;
    1.59 +
    1.60 +    va_start(ap, patternSpecification);
    1.61 +    converted = u_vfscanf_u(f, patternSpecification, ap);
    1.62 +    va_end(ap);
    1.63 +
    1.64 +    return converted;
    1.65 +}
    1.66 +
    1.67 +U_CAPI int32_t  U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
    1.68 +u_vfscanf(UFILE        *f,
    1.69 +          const char    *patternSpecification,
    1.70 +          va_list        ap)
    1.71 +{
    1.72 +    int32_t converted;
    1.73 +    UChar *pattern;
    1.74 +    UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE];
    1.75 +    int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1;
    1.76 +
    1.77 +    /* convert from the default codepage to Unicode */
    1.78 +    if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) {
    1.79 +        pattern = (UChar *)uprv_malloc(size * sizeof(UChar));
    1.80 +        if(pattern == 0) {
    1.81 +            return 0;
    1.82 +        }
    1.83 +    }
    1.84 +    else {
    1.85 +        pattern = patBuffer;
    1.86 +    }
    1.87 +    u_charsToUChars(patternSpecification, pattern, size);
    1.88 +
    1.89 +    /* do the work */
    1.90 +    converted = u_vfscanf_u(f, pattern, ap);
    1.91 +
    1.92 +    /* clean up */
    1.93 +    if (pattern != patBuffer) {
    1.94 +        uprv_free(pattern);
    1.95 +    }
    1.96 +
    1.97 +    return converted;
    1.98 +}
    1.99 +
   1.100 +U_CAPI int32_t  U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
   1.101 +u_vfscanf_u(UFILE       *f,
   1.102 +            const UChar *patternSpecification,
   1.103 +            va_list     ap)
   1.104 +{
   1.105 +    return u_scanf_parse(f, patternSpecification, ap);
   1.106 +}
   1.107 +
   1.108 +#endif /* #if !UCONFIG_NO_FORMATTING */
   1.109 +

mercurial