mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- The scanf() family now supports character ranges for the %[
conversion. Note that this is a non-standard feature! git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14970 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -76,6 +76,9 @@
|
|||||||
- Ported acosh(), acoshf(), asinh(), asinhf(), lgamma(), lgammaf(),
|
- Ported acosh(), acoshf(), asinh(), asinhf(), lgamma(), lgammaf(),
|
||||||
remainder() and remainderf() for C99.
|
remainder() and remainderf() for C99.
|
||||||
|
|
||||||
|
- The scanf() family now supports character ranges for the %[
|
||||||
|
conversion. Note that this is a non-standard feature!
|
||||||
|
|
||||||
|
|
||||||
c.lib 1.192 (12.5.2005)
|
c.lib 1.192 (12.5.2005)
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: stdio_vfscanf.c,v 1.16 2005-05-29 08:19:36 obarthel Exp $
|
* $Id: stdio_vfscanf.c,v 1.17 2005-06-03 11:12:12 obarthel Exp $
|
||||||
*
|
*
|
||||||
* :ts=4
|
* :ts=4
|
||||||
*
|
*
|
||||||
@ -1752,6 +1752,8 @@ vfscanf(FILE *stream, const char *format, va_list arg)
|
|||||||
{
|
{
|
||||||
char * s_ptr;
|
char * s_ptr;
|
||||||
char set[256];
|
char set[256];
|
||||||
|
const unsigned char * scanset;
|
||||||
|
size_t scanset_length,i;
|
||||||
int pick;
|
int pick;
|
||||||
|
|
||||||
if(NOT assignment_suppressed)
|
if(NOT assignment_suppressed)
|
||||||
@ -1814,14 +1816,48 @@ vfscanf(FILE *stream, const char *format, va_list arg)
|
|||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Collect the other characters to form the range. */
|
/* Figure out how many characters are in the scanset. */
|
||||||
while((c = (*(unsigned char *)format)) != '\0')
|
scanset = (const unsigned char *)format;
|
||||||
{
|
|
||||||
|
for(scanset_length = 0 ; scanset[scanset_length] != '\0' && scanset[scanset_length] != ']' ; scanset_length++)
|
||||||
format++;
|
format++;
|
||||||
|
|
||||||
/* This would end the range. */
|
/* We already skipped everything but the righ bracket. */
|
||||||
if(c == ']')
|
if((*format) == ']')
|
||||||
break;
|
format++;
|
||||||
|
|
||||||
|
/* Now have a look at the specification. We support a non-standard
|
||||||
|
scanf() family feature which permits you to specify ranges of
|
||||||
|
characters rather than spelling out each character included in
|
||||||
|
the range. */
|
||||||
|
for(i = 0 ; i < scanset_length ; i++)
|
||||||
|
{
|
||||||
|
c = scanset[i];
|
||||||
|
|
||||||
|
/* Could this be a range? It's not a range if it
|
||||||
|
is the first or the last character in the
|
||||||
|
specification. */
|
||||||
|
if(c == '-' && i != 0 && i != scanset_length - 1)
|
||||||
|
{
|
||||||
|
int first,last,j;
|
||||||
|
|
||||||
|
/* Pick the first and the last character in
|
||||||
|
the range, e.g. for "[A-Z]" the first would
|
||||||
|
be the 'A' and the 'Z' would be the last. */
|
||||||
|
first = scanset[i-1];
|
||||||
|
last = scanset[i+1];
|
||||||
|
|
||||||
|
/* Everything in the scanset now
|
||||||
|
goes into the set. */
|
||||||
|
for(j = first ; j <= last ; j++)
|
||||||
|
set[j] = pick;
|
||||||
|
|
||||||
|
/* Skip the character which marked the
|
||||||
|
end of the range and resume scanning. */
|
||||||
|
i++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
assert( 0 <= c && c <= 255 );
|
assert( 0 <= c && c <= 255 );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user