5 /* _PDCLIB_strtox_prelim( const char *, char *, int * )
7 This file is part of the Public Domain C Library (PDCLib).
8 Permission is granted to use, modify, and / or redistribute at will.
13 const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base )
15 /* skipping leading whitespace */
16 while ( isspace( *p ) ) ++p;
17 /* determining / skipping sign */
18 if ( *p != '+' && *p != '-' ) *sign = '+';
20 /* determining base */
24 if ( ( *base == 0 || *base == 16 ) && ( *p == 'x' || *p == 'X' ) )
29 else if ( *base == 0 )
46 #include <_PDCLIB_test.h>
52 char test1[] = " 123";
53 char test2[] = "\t+0123";
54 char test3[] = "\v-0x123";
56 TESTCASE( _PDCLIB_strtox_prelim( test1, &sign, &base ) == &test1[2] );
57 TESTCASE( sign == '+' );
58 TESTCASE( base == 10 );
61 TESTCASE( _PDCLIB_strtox_prelim( test2, &sign, &base ) == &test2[3] );
62 TESTCASE( sign == '+' );
63 TESTCASE( base == 8 );
66 TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[4] );
67 TESTCASE( sign == '-' );
68 TESTCASE( base == 16 );
71 TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[2] );
72 TESTCASE( sign == '-' );
73 TESTCASE( base == 10 );