3 /* _PDCLIB_atomax( const char * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
9 #define _PDCLIB_INT_H _PDCLIB_INT_H
10 #include <_PDCLIB_int.h>
14 _PDCLIB_intmax_t _PDCLIB_atomax( const char * s )
16 _PDCLIB_intmax_t rc = 0;
19 /* TODO: In other than "C" locale, additional patterns may be defined */
20 while ( isspace( *s ) ) ++s;
22 else if ( *s == '-' ) sign = *(s++);
23 /* TODO: Earlier version was missing tolower() but was not caught by tests */
24 while ( ( x = memchr( _PDCLIB_digits, tolower(*(s++)), 10 ) ) != NULL )
26 rc = rc * 10 + ( x - _PDCLIB_digits );
28 return ( sign == '+' ) ? rc : -rc;
32 #include <_PDCLIB_test.h>
36 /* basic functionality */
37 TESTCASE( _PDCLIB_atomax( "123" ) == 123 );
38 /* testing skipping of leading whitespace and trailing garbage */
39 TESTCASE( _PDCLIB_atomax( " \n\v\t\f123xyz" ) == 123 );