3 /* vsscanf( const char *, const char *, va_list arg )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
15 int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, va_list arg )
17 /* base, flag, n, i, current, s, width, prec, stream, arg */
18 struct _PDCLIB_status_t status = { 0, 0, 0, 0, 0, (char *)s, 0, 0, NULL, NULL };
19 va_copy( status.arg, arg );
21 while ( *format != '\0' )
24 if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) )
26 /* No conversion specifier, match verbatim */
27 if ( isspace( *format ) )
29 /* Whitespace char in format string: Skip all whitespaces */
30 /* No whitespaces in input do not result in matching error */
31 while ( isspace( *status.s ) )
39 /* Non-whitespace char in format string: Match verbatim */
40 if ( *status.s != *format )
55 /* NULL return code indicates input error */
60 /* Continue parsing after conversion specifier */
71 #include <_PDCLIB_test.h>
75 char const * teststring1 = "abc def";
76 char const * teststring2 = "abcdef";
77 char const * teststring3 = "abc%def";
79 TESTCASE( sscanf( teststring2, "abcdef%n", &x ) == 0 );
81 TESTCASE( sscanf( teststring1, "abc def%n", &x ) == 0 );
83 TESTCASE( sscanf( teststring2, "abc def%n", &x ) == 0 );
85 TESTCASE( sscanf( teststring3, "abc%%def%n", &x ) == 0 );