3 /* _PDCLIB_strtox_prelim( const char *, char *, int * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
11 const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base )
13 /* skipping leading whitespace */
14 while ( isspace( *p ) ) ++p;
15 /* determining / skipping sign */
16 if ( *p != '+' && *p != '-' ) *sign = '+';
18 /* determining base */
22 if ( ( *base == 0 || *base == 16 ) && ( *p == 'x' || *p == 'X' ) )
27 else if ( *base == 0 )
40 return ( ( *base >= 2 ) && ( *base <= 36 ) ) ? p : NULL;
44 #include <_PDCLIB_test.h>
50 char test1[] = " 123";
51 char test2[] = "\t+0123";
52 char test3[] = "\v-0x123";
53 TESTCASE( _PDCLIB_strtox_prelim( test1, &sign, &base ) == &test1[2] );
54 TESTCASE( sign == '+' );
55 TESTCASE( base == 10 );
58 TESTCASE( _PDCLIB_strtox_prelim( test2, &sign, &base ) == &test2[3] );
59 TESTCASE( sign == '+' );
60 TESTCASE( base == 8 );
63 TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[4] );
64 TESTCASE( sign == '-' );
65 TESTCASE( base == 16 );
68 TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[2] );
69 TESTCASE( sign == '-' );
70 TESTCASE( base == 10 );
72 TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL );
74 TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL );