2001-02-09 01:45:45 +00:00
|
|
|
/*
|
2001-03-21 22:07:51 +00:00
|
|
|
******************************************************************************
|
2001-02-09 01:45:45 +00:00
|
|
|
*
|
2014-09-05 21:27:11 +00:00
|
|
|
* Copyright (C) 2000-2014, International Business Machines
|
2001-02-09 01:45:45 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
2001-03-21 22:07:51 +00:00
|
|
|
******************************************************************************
|
2001-02-09 01:45:45 +00:00
|
|
|
*
|
|
|
|
* File sscanf.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/08/00 george Creation. Copied from uscanf.c
|
2001-03-21 22:07:51 +00:00
|
|
|
******************************************************************************
|
2001-02-09 01:45:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2002-10-01 01:26:49 +00:00
|
|
|
|
2014-09-05 21:27:11 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_CONVERSION
|
2002-10-01 01:26:49 +00:00
|
|
|
|
2004-10-18 03:03:13 +00:00
|
|
|
#include "unicode/putil.h"
|
2001-02-09 01:45:45 +00:00
|
|
|
#include "unicode/ustdio.h"
|
|
|
|
#include "unicode/ustring.h"
|
2004-04-28 22:19:41 +00:00
|
|
|
#include "uscanf.h"
|
2004-04-16 01:08:35 +00:00
|
|
|
#include "ufile.h"
|
2004-05-03 06:03:21 +00:00
|
|
|
#include "ufmt_cmn.h"
|
2001-02-09 01:45:45 +00:00
|
|
|
|
2002-02-28 01:42:40 +00:00
|
|
|
#include "cmemory.h"
|
2004-05-03 06:41:58 +00:00
|
|
|
#include "cstring.h"
|
2001-02-09 01:45:45 +00:00
|
|
|
|
|
|
|
|
2004-05-03 05:21:24 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2003-07-12 07:21:51 +00:00
|
|
|
u_sscanf(const UChar *buffer,
|
|
|
|
const char *patternSpecification,
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int32_t converted;
|
|
|
|
|
|
|
|
va_start(ap, patternSpecification);
|
2004-04-28 23:36:51 +00:00
|
|
|
converted = u_vsscanf(buffer, patternSpecification, ap);
|
2003-07-12 07:21:51 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
2004-05-03 05:21:24 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2003-07-12 07:21:51 +00:00
|
|
|
u_sscanf_u(const UChar *buffer,
|
|
|
|
const UChar *patternSpecification,
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int32_t converted;
|
|
|
|
|
|
|
|
va_start(ap, patternSpecification);
|
2004-04-28 23:36:51 +00:00
|
|
|
converted = u_vsscanf_u(buffer, patternSpecification, ap);
|
2003-07-12 07:21:51 +00:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
|
|
|
u_vsscanf(const UChar *buffer,
|
|
|
|
const char *patternSpecification,
|
|
|
|
va_list ap)
|
|
|
|
{
|
|
|
|
int32_t converted;
|
|
|
|
UChar *pattern;
|
|
|
|
UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE];
|
2004-05-03 06:41:58 +00:00
|
|
|
int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1;
|
2003-07-12 07:21:51 +00:00
|
|
|
|
|
|
|
/* convert from the default codepage to Unicode */
|
|
|
|
if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) {
|
|
|
|
pattern = (UChar *)uprv_malloc(size * sizeof(UChar));
|
|
|
|
if(pattern == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pattern = patBuffer;
|
|
|
|
}
|
|
|
|
u_charsToUChars(patternSpecification, pattern, size);
|
|
|
|
|
|
|
|
/* do the work */
|
2004-04-28 23:36:51 +00:00
|
|
|
converted = u_vsscanf_u(buffer, pattern, ap);
|
2003-07-12 07:21:51 +00:00
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
if (pattern != patBuffer) {
|
|
|
|
uprv_free(pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
2004-04-16 04:27:29 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
2003-08-05 07:39:12 +00:00
|
|
|
u_vsscanf_u(const UChar *buffer,
|
|
|
|
const UChar *patternSpecification,
|
|
|
|
va_list ap)
|
2001-02-09 01:45:45 +00:00
|
|
|
{
|
2004-05-03 06:03:21 +00:00
|
|
|
int32_t converted;
|
2004-04-16 04:27:29 +00:00
|
|
|
UFILE inStr;
|
2004-05-03 05:21:24 +00:00
|
|
|
|
2004-04-16 04:27:29 +00:00
|
|
|
inStr.fConverter = NULL;
|
|
|
|
inStr.fFile = NULL;
|
|
|
|
inStr.fOwnFile = FALSE;
|
2004-06-10 23:51:33 +00:00
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
2004-04-16 04:27:29 +00:00
|
|
|
inStr.fTranslit = NULL;
|
2004-06-10 23:51:33 +00:00
|
|
|
#endif
|
2004-04-16 04:27:29 +00:00
|
|
|
inStr.fUCBuffer[0] = 0;
|
|
|
|
inStr.str.fBuffer = (UChar *)buffer;
|
|
|
|
inStr.str.fPos = (UChar *)buffer;
|
|
|
|
inStr.str.fLimit = buffer + u_strlen(buffer);
|
2001-02-09 01:45:45 +00:00
|
|
|
|
2004-04-28 23:36:51 +00:00
|
|
|
if(u_locbund_init(&inStr.str.fBundle, "en_US_POSIX") == 0) {
|
2002-02-28 01:42:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-02-09 01:45:45 +00:00
|
|
|
|
2004-05-20 18:22:41 +00:00
|
|
|
converted = u_scanf_parse(&inStr, patternSpecification, ap);
|
2002-02-28 01:42:40 +00:00
|
|
|
|
2004-04-16 04:27:29 +00:00
|
|
|
u_locbund_close(&inStr.str.fBundle);
|
2001-02-09 01:45:45 +00:00
|
|
|
|
2002-02-28 01:42:40 +00:00
|
|
|
/* return # of items converted */
|
|
|
|
return converted;
|
2001-02-09 01:45:45 +00:00
|
|
|
}
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
2003-09-25 21:14:35 +00:00
|
|
|
|