17 int main(
const int argc ,
const char* argv[] ) {
21 #define exec_TEST(t) void t(); t();
40 #define eqstr(a,b) ( 0==strcmp(a,b) )
45 char str[128] =
"IMG_20190112_151835.jpg";
46 unsigned long num[12];
47 unsigned long chk[] = { 2019,01,12,15,18,35,0 };
67 char str[128] =
"IMG_2019.0112_151835.jpg";
85 char str[128] =
"IMG_2018-02.bak";
95 template <
size_t DIM=12>
103 template <
size_t DIM>
105 size_t dim_ret =
sizeof(vec)/
sizeof(*vec);
106 intmax_t ret_vec[ dim_ret ];
107 size_t ret =
atoi_vec(str.c_str(), ret_vec, dim_ret);
108 if ( ret!= N ) {
return false; }
109 for (
size_t i=0; i<N; ++i ) {
110 if ( ret_vec[i] != vec[i] ) {
return false; }
119 assertTrue(
N_vec<>( {
"N,lambda->5,1 (1,1,2,2)->4", 7, { 5,1, 1,1,2,2, 4 } } ).check_ok() );
123 assertTrue(
N_vec<>( {
"55,101 (1,1,2,2)->4", 7, { 55,101, 1,1,2,2, 4 } } ).check_ok() );
125 assertTrue(
N_vec<>( {
"oiOEI!&(*_)->-", 0, { 12,101, 1,1,2,2, 4 } } ).check_ok() );
132 assertTrue(
N_vec<>( {
"1 2 3 4 5 6 7 8 9 -0 -1 -2 -3", 12, {1,2,3,4,5,6,7,8,9,0,-1,-2} } ).check_ok() );
138 assertTrue(
N_vec<>( {
"N,lambda->5,1 (1,1,-2,2)->4", 7, { 5,1, 1,1,-2,2, 4 } } ).check_ok() );
142 assertTrue(
N_vec<>( {
"-00055,101 (1,1,2,2)->4", 7, { -55,101, 1,1,2,2, 4 } } ).check_ok() );
144 assertTrue(
N_vec<>( {
"oiOEI*!&(*_)->", 0, { 12,101, 1,1,2,2, 4 } } ).check_ok() );
149 char str[] =
" 000 6 -21 \t 5 \r\n 5 5 - 3 3 3 2 -";
150 int RES[] = { 000,6,-21, 5, 5,5, 3,3,3,2 };
155 const size_t dim_VEC =
sizeof(VEC)/
sizeof(*VEC);
156 const size_t dim_RES =
sizeof(RES)/
sizeof(*RES);
158 for (
size_t i=0; i<((dim_VEC)); ++i ) { VEC[i] = 0; }
162 for ( i=k=0; i<dim_RES; ++i,++k ) {
165 for ( i=k; i<((dim_VEC)); ++i ) {
172 intmax_t VEC[24], N=0;
173 const size_t dim_VEC =
sizeof(VEC)/
sizeof(*VEC);
174 char str[] =
"0012345 \t \r\n \f 99 ";
180 char xtr[] =
"0012345.. $)(*^@!_.. 99 ";
187 const size_t DIM = 24, TEN=10;
189 for (
size_t i=0; i<DIM; ++i ) { VEC[i] = 0; }
191 char str[] =
"0,1,2,3,4,5,6,7,8,9 | -9 8 -7 6 -5 4 -3 2 1 -0 =";
196 for (
size_t i=0; i<TEN; ++i ) {
199 for (
size_t i=TEN; i<DIM; ++i ) {
212 t[0] = {
"...(5,4)->(N,lambda)", 2, {5,4} };
213 t[1] = {
"5,4]->9", 3, { 5,4, 9 } };
214 t[2] = {
"55,101 (1,1,2,2)->4", 7, { 55,101, 1,1,2,2, 4 } };
234 size_t dim_ret =
sizeof(
vec)/
sizeof(*
vec);
235 uintmax_t ret_vec[ dim_ret ];
236 size_t ret =
atou_vec(
str.c_str(), ret_vec, dim_ret);
237 if ( ret!=
N ) {
return false; }
238 for (
size_t i=0; i<
N; ++i ) {
239 if ( ret_vec[i] !=
vec[i] ) {
return false; }
248 assertTrue(
N_vecU( {
"N,lambda->5,1 (1,1,2,2)->4", 7, { 5,1, 1,1,2,2, 4 } } ).check_ok() );
252 assertTrue(
N_vecU( {
"55,101 (1,1,2,2)->4", 7, { 55,101, 1,1,2,2, 4 } } ).check_ok() );
254 assertTrue(
N_vecU( {
"oiOEI*!&(*_)->", 0, { 12,101, 1,1,2,2, 4 } } ).check_ok() );
261 assertTrue(
N_vecU( {
"1 2 3 4 5 6 7 8 9 -0 -1 -2 -3", 12, {1,2,3,4,5,6,7,8,9,0,1,2} } ).check_ok() );
266 char str[128] =
"IMG_20190112_151835.jpg";
267 size_t len =
atou_vec( str, NUM, dim );
269 assertTrue( NUM[0]==20190112 && NUM[1]==151835 );
272 char str[128] =
"IMG_2019-01/12_15:18.35.jpg";
274 size_t len =
atou_vec( str, NUM, 6 );
276 assertTrue( NUM[0]==2019 && NUM[1]== 1 && NUM[2]==12 );
277 assertTrue( NUM[3]==15 && NUM[4]==18 && NUM[5]==35 );
283 char str[128] =
"IMG_20190112_151835.jpg";
284 size_t len =
atou_vec( str, NUM, dim );
286 assertTrue( NUM[0]==20190112 && NUM[1]==151835 );
288 char str[128] =
"IMG_2019-01/12_15:18.35.jpg";
290 size_t len =
atou_vec( str, NUM, 6 );
292 assertTrue( NUM[0]==2019 && NUM[1]== 1 && NUM[2]==12 );
293 assertTrue( NUM[3]==15 && NUM[4]==18 && NUM[5]==35 );
298 char str[] =
" 000 6 -21 \t 5 \r\n 5 5 3 3 3 2 -";
299 size_t RES[] = { 000,6, 21, 5, 5,5,3,3,3,2 };
300 uintmax_t VEC[24], dim;
304 const size_t dim_VEC =
sizeof(VEC)/
sizeof(*VEC);
305 const size_t dim_RES =
sizeof(RES)/
sizeof(*RES);
307 for (
size_t i=0; i<((dim_VEC)); ++i ) { VEC[i] = 0; }
312 for ( i=k=0; i<dim_RES; ++i,++k ) {
315 for ( i=k; i<((dim_VEC)); ++i ) {
322 uintmax_t VEC[24], dim=0;
323 const size_t dim_VEC =
sizeof(VEC)/
sizeof(*VEC);
324 char str[] =
"0012345 \t \r\n \f 99 ";
330 char xtr[] =
"0012345.. $)(*^@!_.. 99 ";
337 const size_t DIM = 24, TEN=10;
339 for (
size_t i=0; i<DIM; ++i ) { VEC[i] = 0; }
341 char str[] =
"0,1,2,3,4,5,6,7,8,9 | -9 8 -7 6 -5 4 -3 2 1 -0 =";
346 for (
unsigned i=0; i<TEN; ++i ) {
349 for (
unsigned i=TEN; i<DIM; ++i ) {
379 pDst =
utoa_sz( 101, dst5 , 10 , ((
sizeof(dst5) )) );
384 pDst =
utoa_sz( 987654321, dst7 , 10 , ((
sizeof(dst7) )) );
389 pDst =
utoa_sz( 123, dst32 , 10 , ((4+1)) );
393 pDst =
utoa_sz( 11, dst32 , ((3)), ((5+1)) );
397 pDst =
utoa_sz( 0*0, dst32 , 16 , ((5+1)) );
408 template <
unsigned N>
418 for (
unsigned i=0; i<2*N; ++i) {
419 if (
m_prev[i] !=
chX ) {
return false; }
420 if (
m_post[i] !=
chX ) {
return false; }
425 if (n==0 || n>N) {
return false; }
427 for (
unsigned i=0; i<n; ++i ) {
428 if (
m_val[i] ==
chX ) {
return false; }
430 if (
m_val[n] != 0) {
return false; }
431 for (
unsigned i=n+1; i<2*N; ++i ) {
432 if (
m_val[i] !=
chX ) {
return false; }
437 void set(
const char * v ) {
439 memcpy(
m_val, v, N );
504 strcpy( num ,
" " ); strcat(num,
" 32584729.25" );
510 strcpy( num ,
"" ); strcat(num,
" 32584729.25" );
516 strcpy( num ,
" " ); strcat(num,
" 32584729.25" );
519 assertTrue( 0==strcmp( num ,
"3|25|84|729.25" ) );
523 strcpy( num ,
"123" );
526 strcpy( num ,
"1234" );
529 strcpy( num ,
" 1234" );
537 strcpy( num,
"...**20191231.." );
542 strcpy( num,
"...**12312019.." );
547 strcpy( num,
"...**1234567.." );
557 strcpy( num,
".a.=|$+12345678.00" );
558 first =
insnsep( num,
',' , 3 );
559 assertTrue( 0==strcmp(first,
"+12,345,678.00" ) );
560 assertTrue( 0==strcmp(num,
".a.=+12,345,678.00" ) );
562 if (first!=num) { --first; *first =
'$'; }
563 assertTrue( 0==strcmp(first,
"$+12,345,678.00" ) );
565 strcpy( num,
".|.|-12345.." );
566 first =
insnsep( num,
',', 3 );
568 assertTrue( 0==strcmp(num,
".|.-12,345.." ) );
569 if (first!=num ) { *num =
'$';
570 while (--first!=num ) { *first=
'*'; }
572 assertTrue( 0==strcmp(first,
"$**-12,345.." ) );
574 strcpy( num,
" -0" );
577 strcpy( num,
" +000000" );
583 strcpy( num,
"???.xx" );
585 strcpy( num,
"123.00" );
598 strcpy( num,
"ab!...0000.00" );
599 first =
insnsep( num,
',' , 1 );
600 assertTrue( 0==strcmp(first,
"0,0,0,0.00" ) );
601 assertTrue( 0==strcmp(num,
"ab!0,0,0,0.00" ) );
604 strcpy( num,
".a.=$+123456.00" );
605 first =
insnsep( num,
',' , 3 );
606 assertTrue( 0==strcmp(first,
"+123,456.00" ) );
607 assertTrue( 0==strcmp(num,
".a.=+123,456.00" ) );
609 if (first>num) { --first; *first =
'$'; }
610 assertTrue( 0==strcmp(first,
"$+123,456.00" ) );
612 strcpy( num,
".|.20191231.." );
613 first =
insnsep( num,
'/', 2 );
614 assertTrue( 0==strcmp(first,
"20/19/12/31.." ) );
615 assertTrue( 0==strcmp(num,
"20/19/12/31.." ) );
617 memmove( first+2 ,first+3, 1+strlen(first+3) );
618 assertTrue( 0==strcmp(first,
"2019/12/31.." ) );
620 strcpy( num,
".|.20191231.." );
621 first =
insnsep( num,
'/', 4 );
622 assertTrue( 0==strcmp(first,
"2019/1231.." ) );
624 memmove( first-1 ,first, 7 ); --first; *(first+7) =
'/';
625 assertTrue( 0==strcmp(first,
"2019/12/31.." ) );
629 strcpy( num,
" 2019-12-31.." );
630 first =
insnsep( num,
',' , 3 );
633 strcpy( num,
" +2019-12-31.." );
634 first =
insnsep( num,
',' , 3 );
637 strcpy( num,
" +0" );
640 strcpy( num,
" -00" );
643 strcpy( num,
" -000" );
651 strcpy( num,
"-00" );
653 strcpy( num,
"-000" );
658 strcpy( num,
"-12" );
660 strcpy( num,
"-123" );
662 strcpy( num,
" +123" );
665 strcpy( num,
" +1234" );
668 strcpy( num,
" +12345" );
670 strcpy( num,
" +12345" );
672 strcpy( num,
"+1,23,45" );
676 strcpy( num,
"-12" );
678 strcpy( num,
" -12" );
680 strcpy( num,
"-1,2" );
681 strcpy( num,
" +123" );
683 strcpy( num,
" +123" );
686 strcpy( num,
" +1234" );
688 strcpy( num,
" +1234" );
691 strcpy( num,
" +12345" );
693 strcpy( num,
" +12345" );
695 strcpy( num,
"+1,2,3,4,5" );
696 strcpy( num,
" +123456" );
698 strcpy( num,
" +123456" );
700 strcpy( num,
"+1,2,3,4,5,6" );
701 strcpy( num,
" +1234567" );
703 strcpy( num,
"+1,2,3,4,5,6,7" );
705 strcpy( num,
"-0000" );
707 strcpy( num,
" -0000" );
711 strcpy( num,
" -0000" );
714 strcpy( num,
" +00000" );
720 strcpy( num,
"...20191231.." );
728 strcpy( num,
".123.00" );
731 strcpy( num,
"..123.00" );
734 strcpy( num,
"0.00" );
735 first =
insnsep( num,
',' , 3 );
739 first =
insnsep( num,
',' , 1 );
742 first =
insnsep( num,
',' , 9 );
745 first =
insnsep( num,
',' , 2 );
747 strcpy( num,
" 12" );
748 first =
insnsep( num,
',' , 1 );
750 strcpy( num,
"123" );
751 first =
insnsep( num,
',' , 1 );
754 strcpy( num,
"000000.00" );
755 first =
insnsep( num,
',' , 3 );
758 strcpy( num,
" 000000.00" );
759 first =
insnsep( num,
':' , 3 );
763 strcpy( num,
" 0...0...0...01.00" );
764 first =
insnsep( num,
',' , 3 );
767 strcpy( num,
" ...... 0.00" );
768 first =
insnsep( num,
',' , 1 );
771 strcpy( num,
".|.20191231.." );
772 first =
insnsep( num,
'/', 2 );
773 assertTrue( 0==strcmp(first,
"20/19/12/31.." ) );
775 *(first+2)=*(first+1);
776 *(first+1)=*(first+0);
779 assertTrue( 0==strcmp(first,
"2019/12/31.." ) );
781 if (*first) {*num = *first; }
793 snprintf( str,40,
"%llu", UINT64_MAX );
796 snprintf( str,40,
"%" "lld", INT64_MIN );
802 snprintf( str,64,
"%u",
sizeof(int64_t) );
805 snprintf( str,128,
"%" "I64u", UINT64_MAX );
808 snprintf( str,128,
"%lld", INT64_MIN );
811 snprintf( str,128,
"%" "I64i", INT64_MIN );
819 #define PRIuMAX "I64u"
822 memset( str,20,
' ');
826 first =
insnsep( str,
',' , 3 );
829 assertTrue( strlen(first)==2+6*4 && 26==2+6*4 );
835 memset( str,16,
' ');
836 strcpy( str+16,
"340282366920938463463374607431768211456" );
837 first =
insnsep( str,
',' , 3 );
838 assertTrue(
eqstr(
"340,282,366,920,938,463,463,374,607,431,768,211,456", first ) );
839 assertTrue( strlen(first)==51 && 51==13*4-1 );
843 if (
sizeof(
double)==
sizeof(
long double) ) {
844 assertTrue(
sizeof(
double)==
sizeof(
long double) );
847 assertTrue(
sizeof(
double) <
sizeof(
long double) );
849 assertFalse( 2 *
sizeof(
double) ==
sizeof(
long double) );