@@ -544,6 +544,77 @@ BOOST_AUTO_TEST_CASE(test_IsDigit)
544
544
BOOST_CHECK_EQUAL (IsDigit (9 ), false );
545
545
}
546
546
547
+ BOOST_AUTO_TEST_CASE (test_LocaleIndependentAtoi)
548
+ {
549
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 1234" ), 1'234 );
550
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 0" ), 0 );
551
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 01234" ), 1'234 );
552
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -1234" ), -1'234 );
553
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 1" ), 1 );
554
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 1 " ), 1 );
555
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 1a" ), 1 );
556
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 1.1" ), 1 );
557
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 1.9" ), 1 );
558
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" +01.9" ), 1 );
559
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -1" ), -1 );
560
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -1" ), -1 );
561
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -1 " ), -1 );
562
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -1 " ), -1 );
563
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" +1" ), 1 );
564
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" +1" ), 1 );
565
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" +1 " ), 1 );
566
+
567
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" +-1" ), 0 );
568
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -+1" ), 0 );
569
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" ++1" ), 0 );
570
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" --1" ), 0 );
571
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" " ), 0 );
572
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" aap" ), 0 );
573
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 0x1" ), 0 );
574
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -32482348723847471234" ), 0 );
575
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 32482348723847471234" ), 0 );
576
+
577
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int64_t >(" -9223372036854775809" ), 0 );
578
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int64_t >(" -9223372036854775808" ), -9'223'372'036'854'775'807LL - 1LL );
579
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int64_t >(" 9223372036854775807" ), 9'223'372'036'854'775'807 );
580
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int64_t >(" 9223372036854775808" ), 0 );
581
+
582
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint64_t >(" -1" ), 0U );
583
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint64_t >(" 0" ), 0U );
584
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint64_t >(" 18446744073709551615" ), 18'446'744'073'709'551'615ULL );
585
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint64_t >(" 18446744073709551616" ), 0U );
586
+
587
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -2147483649" ), 0 );
588
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" -2147483648" ), -2'147'483'648LL );
589
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 2147483647" ), 2'147'483'647 );
590
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int32_t >(" 2147483648" ), 0 );
591
+
592
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint32_t >(" -1" ), 0U );
593
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint32_t >(" 0" ), 0U );
594
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint32_t >(" 4294967295" ), 4'294'967'295U );
595
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint32_t >(" 4294967296" ), 0U );
596
+
597
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int16_t >(" -32769" ), 0 );
598
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int16_t >(" -32768" ), -32'768 );
599
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int16_t >(" 32767" ), 32'767 );
600
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int16_t >(" 32768" ), 0 );
601
+
602
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint16_t >(" -1" ), 0U );
603
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint16_t >(" 0" ), 0U );
604
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint16_t >(" 65535" ), 65'535U );
605
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint16_t >(" 65536" ), 0U );
606
+
607
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int8_t >(" -129" ), 0 );
608
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int8_t >(" -128" ), -128 );
609
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int8_t >(" 127" ), 127 );
610
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<int8_t >(" 128" ), 0 );
611
+
612
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint8_t >(" -1" ), 0U );
613
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint8_t >(" 0" ), 0U );
614
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint8_t >(" 255" ), 255U );
615
+ BOOST_CHECK_EQUAL (LocaleIndependentAtoi<uint8_t >(" 256" ), 0U );
616
+ }
617
+
547
618
BOOST_AUTO_TEST_CASE (test_ParseInt32)
548
619
{
549
620
int32_t n;
0 commit comments