@@ -701,53 +701,53 @@ namespace cppstringstests
701701 TEST_METHOD (count)
702702 {
703703 pcs::CppString s (" abcabcabcdefabca bca bcabca" );
704- Assert::AreEqual (3ULL , s.count (" abca" ));
705- Assert::AreEqual (6ULL , s.count (" bca" ));
706- Assert::AreEqual (0ULL , s.count (" A" ));
707- Assert::AreEqual (2ULL , s.count (" abca" , 4 ));
708- Assert::AreEqual (5ULL , s.count (" bca" , 2 ));
709- Assert::AreEqual (0ULL , s.count (" A" , 3 ));
710- Assert::AreEqual (1ULL , s.count (" abca" , 4 , s.size () - 5 ));
711- Assert::AreEqual (4ULL , s.count (" bca" , 2 , s.size () - 2 ));
712- Assert::AreEqual (0ULL , s.count (" A" , 3 , s.size () + 4 ));
704+ Assert::AreEqual (pcs::CppString::size_type ( 3 ) , s.count (" abca" ));
705+ Assert::AreEqual (pcs::CppString::size_type ( 6 ) , s.count (" bca" ));
706+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , s.count (" A" ));
707+ Assert::AreEqual (pcs::CppString::size_type ( 2 ) , s.count (" abca" , 4 ));
708+ Assert::AreEqual (pcs::CppString::size_type ( 5 ) , s.count (" bca" , 2 ));
709+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , s.count (" A" , 3 ));
710+ Assert::AreEqual (pcs::CppString::size_type ( 1 ) , s.count (" abca" , 4 , s.size () - 5 ));
711+ Assert::AreEqual (pcs::CppString::size_type ( 4 ) , s.count (" bca" , 2 , s.size () - 2 ));
712+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , s.count (" A" , 3 , s.size () + 4 ));
713713
714714 pcs::CppWString ws (L" abcabcabcdefabca bca bcabca" );
715- Assert::AreEqual (3ULL , ws.count (L" abca" ));
716- Assert::AreEqual (6ULL , ws.count (L" bca" ));
717- Assert::AreEqual (0ULL , ws.count (L" A" ));
718- Assert::AreEqual (2ULL , ws.count (L" abca" , 4 ));
719- Assert::AreEqual (5ULL , ws.count (L" bca" , 2 ));
720- Assert::AreEqual (0ULL , ws.count (L" A" , 3 ));
721- Assert::AreEqual (1ULL , ws.count (L" abca" , 4 , s.size () - 5 ));
722- Assert::AreEqual (4ULL , ws.count (L" bca" , 2 , s.size () - 2 ));
723- Assert::AreEqual (0ULL , ws.count (L" A" , 3 , s.size () + 4 ));
715+ Assert::AreEqual (pcs::CppString::size_type ( 3 ) , ws.count (L" abca" ));
716+ Assert::AreEqual (pcs::CppString::size_type ( 6 ) , ws.count (L" bca" ));
717+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , ws.count (L" A" ));
718+ Assert::AreEqual (pcs::CppString::size_type ( 2 ) , ws.count (L" abca" , 4 ));
719+ Assert::AreEqual (pcs::CppString::size_type ( 5 ) , ws.count (L" bca" , 2 ));
720+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , ws.count (L" A" , 3 ));
721+ Assert::AreEqual (pcs::CppString::size_type ( 1 ) , ws.count (L" abca" , 4 , s.size () - 5 ));
722+ Assert::AreEqual (pcs::CppString::size_type ( 4 ) , ws.count (L" bca" , 2 , s.size () - 2 ));
723+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , ws.count (L" A" , 3 , s.size () + 4 ));
724724 }
725725
726726 TEST_METHOD (count_n)
727727 {
728728 pcs::CppString s (" abcabcabcdefabca bca bcabca" );
729729 const pcs::CppString::size_type len{ s.size () };
730- Assert::AreEqual (3ULL , s.count_n (" abca" , 0 , len));
731- Assert::AreEqual (6ULL , s.count_n (" bca" , 0 , len));
732- Assert::AreEqual (0ULL , s.count_n (" A" , 0 , len));
733- Assert::AreEqual (2ULL , s.count_n (" abca" , 4 , len - 4 ));
734- Assert::AreEqual (5ULL , s.count_n (" bca" , 2 , len - 2 ));
735- Assert::AreEqual (0ULL , s.count_n (" A" , 3 , len - 3 ));
736- Assert::AreEqual (1ULL , s.count_n (" abca" , 4 , len - 5 ));
737- Assert::AreEqual (4ULL , s.count_n (" bca" , 2 , len - 3 ));
738- Assert::AreEqual (0ULL , s.count_n (" A" , 3 , len + 4 ));
730+ Assert::AreEqual (pcs::CppString::size_type ( 3 ) , s.count_n (" abca" , 0 , len));
731+ Assert::AreEqual (pcs::CppString::size_type ( 6 ) , s.count_n (" bca" , 0 , len));
732+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , s.count_n (" A" , 0 , len));
733+ Assert::AreEqual (pcs::CppString::size_type ( 2 ) , s.count_n (" abca" , 4 , len - 4 ));
734+ Assert::AreEqual (pcs::CppString::size_type ( 5 ) , s.count_n (" bca" , 2 , len - 2 ));
735+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , s.count_n (" A" , 3 , len - 3 ));
736+ Assert::AreEqual (pcs::CppString::size_type ( 1 ) , s.count_n (" abca" , 4 , len - 5 ));
737+ Assert::AreEqual (pcs::CppString::size_type ( 4 ) , s.count_n (" bca" , 2 , len - 3 ));
738+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , s.count_n (" A" , 3 , len + 4 ));
739739
740740 pcs::CppWString ws (L" abcabcabcdefabca bca bcabca" );
741741 const pcs::CppWString::size_type wlen{ ws.size () };
742- Assert::AreEqual (3ULL , ws.count_n (L" abca" , 0 , wlen));
743- Assert::AreEqual (6ULL , ws.count_n (L" bca" , 0 , wlen));
744- Assert::AreEqual (0ULL , ws.count_n (L" A" , 0 , wlen));
745- Assert::AreEqual (2ULL , ws.count_n (L" abca" , 4 , wlen - 4 ));
746- Assert::AreEqual (5ULL , ws.count_n (L" bca" , 2 , wlen - 2 ));
747- Assert::AreEqual (0ULL , ws.count_n (L" A" , 3 , wlen - 3 ));
748- Assert::AreEqual (1ULL , ws.count_n (L" abca" , 4 , wlen - 5 ));
749- Assert::AreEqual (4ULL , ws.count_n (L" bca" , 2 , wlen - 3 ));
750- Assert::AreEqual (0ULL , ws.count_n (L" A" , 3 , wlen + 4 ));
742+ Assert::AreEqual (pcs::CppString::size_type ( 3 ) , ws.count_n (L" abca" , 0 , wlen));
743+ Assert::AreEqual (pcs::CppString::size_type ( 6 ) , ws.count_n (L" bca" , 0 , wlen));
744+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , ws.count_n (L" A" , 0 , wlen));
745+ Assert::AreEqual (pcs::CppString::size_type ( 2 ) , ws.count_n (L" abca" , 4 , wlen - 4 ));
746+ Assert::AreEqual (pcs::CppString::size_type ( 5 ) , ws.count_n (L" bca" , 2 , wlen - 2 ));
747+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , ws.count_n (L" A" , 3 , wlen - 3 ));
748+ Assert::AreEqual (pcs::CppString::size_type ( 1 ) , ws.count_n (L" abca" , 4 , wlen - 5 ));
749+ Assert::AreEqual (pcs::CppString::size_type ( 4 ) , ws.count_n (L" bca" , 2 , wlen - 3 ));
750+ Assert::AreEqual (pcs::CppString::size_type ( 0 ) , ws.count_n (L" A" , 3 , wlen + 4 ));
751751 }
752752
753753 TEST_METHOD (endswith)
@@ -3312,5 +3312,188 @@ namespace cppstringstests
33123312 Assert::AreEqual (L" " , wres[8 ].c_str ());
33133313 }
33143314
3315+ TEST_METHOD (splitline)
3316+ {
3317+ #pragma warning(push)
3318+ #pragma warning(disable: 4566) // to get no warning when current page code is not compatible with next unicode points
3319+ {
3320+ CppString text{ " \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r " };
3321+ std::vector<CppString> lines{ text.splitlines () };
3322+ std::vector<CppString> expected{ " " , " abc" , " cde" , " efg" , " ghi" , " ijk" , " klm" , " mno" , " " , " opq" , " qrs" , " stu" , " uvw" , " wxy" , " zzz" , " ." };
3323+ auto exp_it{ expected.cbegin () };
3324+ auto lin_it{ lines.cbegin () };
3325+ for (; lin_it != lines.cend () && exp_it != expected.cend (); ++lin_it, ++exp_it) {
3326+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3327+ }
3328+ Assert::IsFalse (lin_it != lines.cend ());
3329+ Assert::IsFalse (exp_it != expected.cend ());
3330+ }
3331+
3332+ {
3333+ CppString text{ " \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r\n " };
3334+ std::vector<CppString> lines{ text.splitlines () };
3335+ std::vector<CppString> expected{ " " , " abc" , " cde" , " efg" , " ghi" , " ijk" , " klm" , " mno" , " " , " opq" , " qrs" , " stu" , " uvw" , " wxy" , " zzz" , " ." };
3336+ auto exp_it{ expected.cbegin () };
3337+ auto lin_it{ lines.cbegin () };
3338+ for (; lin_it != lines.cend () && exp_it != expected.cend (); ++lin_it, ++exp_it) {
3339+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3340+ }
3341+ Assert::IsFalse (lin_it != lines.cend ());
3342+ Assert::IsFalse (exp_it != expected.cend ());
3343+ }
3344+
3345+ {
3346+ CppString text{ " \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\n\r " };
3347+ std::vector<CppString> lines{ text.splitlines () };
3348+ std::vector<CppString> expected{ " " , " abc" , " cde" , " efg" , " ghi" , " ijk" , " klm" , " mno" , " " , " opq" , " qrs" , " stu" , " uvw" , " wxy" , " zzz" , " ." , " " };
3349+ auto exp_it{ expected.cbegin () };
3350+ auto lin_it{ lines.cbegin () };
3351+ for (; lin_it != lines.cend () && exp_it != expected.cend (); ++lin_it, ++exp_it) {
3352+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3353+ }
3354+ Assert::IsFalse (lin_it != lines.cend ());
3355+ Assert::IsFalse (exp_it != expected.cend ());
3356+ }
3357+
3358+ {
3359+ CppString text{ " \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r " };
3360+ std::vector<CppString> lines{ text.splitlines (true ) };
3361+ std::vector<CppString> expected{
3362+ " \v " , " abc\013 " , " cde\f " , " efg\x0c " , " ghi\x1c " , " ijk\x1d " , " klm\x1d " , " mno\r\n " ,
3363+ " \n " , " opq\r " , " qrs\v " , " stu\r " , " uvw\n " , " wxy\r\n " , " zzz\x0c " , " .\r "
3364+ };
3365+ auto exp_it{ expected.cbegin () };
3366+ auto lin_it{ lines.cbegin () };
3367+ for (; lin_it != lines.cend () && exp_it != expected.cend (); ++lin_it, ++exp_it) {
3368+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3369+ }
3370+ Assert::IsFalse (lin_it != lines.cend ());
3371+ Assert::IsFalse (exp_it != expected.cend ());
3372+ }
3373+
3374+ {
3375+ CppString text{ " \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r\n " };
3376+ std::vector<CppString> lines{ text.splitlines (true ) };
3377+ std::vector<CppString> expected{
3378+ " \v " , " abc\013 " , " cde\f " , " efg\x0c " , " ghi\x1c " , " ijk\x1d " , " klm\x1d " , " mno\r\n " ,
3379+ " \n " , " opq\r " , " qrs\v " , " stu\r " , " uvw\n " , " wxy\r\n " , " zzz\x0c " , " .\r\n "
3380+ };
3381+ auto exp_it{ expected.cbegin () };
3382+ auto lin_it{ lines.cbegin () };
3383+ for (; lin_it != lines.cend () && exp_it != expected.cend (); ++lin_it, ++exp_it) {
3384+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3385+ }
3386+ Assert::IsFalse (lin_it != lines.cend ());
3387+ Assert::IsFalse (exp_it != expected.cend ());
3388+ }
3389+
3390+ {
3391+ CppString text{ " \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\n\r " };
3392+ std::vector<CppString> lines{ text.splitlines (true ) };
3393+ std::vector<CppString> expected{
3394+ " \v " , " abc\013 " , " cde\f " , " efg\x0c " , " ghi\x1c " , " ijk\x1d " , " klm\x1d " , " mno\r\n " ,
3395+ " \n " , " opq\r " , " qrs\v " , " stu\r " , " uvw\n " , " wxy\r\n " , " zzz\x0c " , " .\n " , " \r "
3396+ };
3397+ auto exp_it{ expected.cbegin () };
3398+ auto lin_it{ lines.cbegin () };
3399+ for (; lin_it != lines.cend () && exp_it != expected.cend (); ++lin_it, ++exp_it) {
3400+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3401+ }
3402+ Assert::IsFalse (lin_it != lines.cend ());
3403+ Assert::IsFalse (exp_it != expected.cend ());
3404+ }
3405+
3406+
3407+ {
3408+ CppWString wtext{ L" \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r " };
3409+ std::vector<CppWString> wlines{ wtext.splitlines () };
3410+ std::vector<CppWString> wexpected{ L" " , L" abc" , L" cde" , L" efg" , L" ghi" , L" ijk" , L" klm" , L" mno" , L" " , L" opq" , L" qrs" , L" stu" , L" uvw" , L" wxy" , L" zzz" , L" ." };
3411+ auto exp_it{ wexpected.cbegin () };
3412+ auto lin_it{ wlines.cbegin () };
3413+ for (; lin_it != wlines.cend () && exp_it != wexpected.cend (); ++lin_it, ++exp_it) {
3414+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3415+ }
3416+ Assert::IsFalse (lin_it != wlines.cend ());
3417+ Assert::IsFalse (exp_it != wexpected.cend ());
3418+ }
3419+
3420+ {
3421+ CppWString wtext{ L" \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r\n " };
3422+ std::vector<CppWString> wlines{ wtext.splitlines () };
3423+ std::vector<CppWString> wexpected{ L" " , L" abc" , L" cde" , L" efg" , L" ghi" , L" ijk" , L" klm" , L" mno" , L" " , L" opq" , L" qrs" , L" stu" , L" uvw" , L" wxy" , L" zzz" , L" ." };
3424+ auto exp_it{ wexpected.cbegin () };
3425+ auto lin_it{ wlines.cbegin () };
3426+ for (; lin_it != wlines.cend () && exp_it != wexpected.cend (); ++lin_it, ++exp_it) {
3427+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3428+ }
3429+ Assert::IsFalse (lin_it != wlines.cend ());
3430+ Assert::IsFalse (exp_it != wexpected.cend ());
3431+ }
3432+
3433+ {
3434+ CppWString wtext{ L" \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\n\r " };
3435+ std::vector<CppWString> wlines{ wtext.splitlines () };
3436+ std::vector<CppWString> wexpected{ L" " , L" abc" , L" cde" , L" efg" , L" ghi" , L" ijk" , L" klm" , L" mno" , L" " , L" opq" , L" qrs" , L" stu" , L" uvw" , L" wxy" , L" zzz" , L" ." , L" " };
3437+ auto exp_it{ wexpected.cbegin () };
3438+ auto lin_it{ wlines.cbegin () };
3439+ for (; lin_it != wlines.cend () && exp_it != wexpected.cend (); ++lin_it, ++exp_it) {
3440+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3441+ }
3442+ Assert::IsFalse (lin_it != wlines.cend ());
3443+ Assert::IsFalse (exp_it != wexpected.cend ());
3444+ }
3445+
3446+ {
3447+ CppWString wtext{ L" \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r " };
3448+ std::vector<CppWString> wlines{ wtext.splitlines (true ) };
3449+ std::vector<CppWString> wexpected{
3450+ L" \v " , L" abc\013 " , L" cde\f " , L" efg\x0c " , L" ghi\x1c " , L" ijk\x1d " , L" klm\x1d " , L" mno\r\n " ,
3451+ L" \n " , L" opq\r " , L" qrs\v " , L" stu\r " , L" uvw\n " , L" wxy\r\n " , L" zzz\x0c " , L" .\r "
3452+ };
3453+ auto exp_it{ wexpected.cbegin () };
3454+ auto lin_it{ wlines.cbegin () };
3455+ for (; lin_it != wlines.cend () && exp_it != wexpected.cend (); ++lin_it, ++exp_it) {
3456+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3457+ }
3458+ Assert::IsFalse (lin_it != wlines.cend ());
3459+ Assert::IsFalse (exp_it != wexpected.cend ());
3460+ }
3461+
3462+ {
3463+ CppWString wtext{ L" \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\r\n " };
3464+ std::vector<CppWString> wlines{ wtext.splitlines (true ) };
3465+ std::vector<CppWString> wexpected{
3466+ L" \v " , L" abc\013 " , L" cde\f " , L" efg\x0c " , L" ghi\x1c " , L" ijk\x1d " , L" klm\x1d " , L" mno\r\n " ,
3467+ L" \n " , L" opq\r " , L" qrs\v " , L" stu\r " , L" uvw\n " , L" wxy\r\n " , L" zzz\x0c " , L" .\r\n "
3468+ };
3469+ auto exp_it{ wexpected.cbegin () };
3470+ auto lin_it{ wlines.cbegin () };
3471+ for (; lin_it != wlines.cend () && exp_it != wexpected.cend (); ++lin_it, ++exp_it) {
3472+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3473+ }
3474+ Assert::IsFalse (lin_it != wlines.cend ());
3475+ Assert::IsFalse (exp_it != wexpected.cend ());
3476+ }
3477+
3478+ {
3479+ CppWString wtext{ L" \v abc\013 cde\f efg\x0c ghi\x1c ijk\x1d klm\x1d mno\r\n\n opq\r qrs\v stu\r uvw\n wxy\r\n zzz\x0c .\n\r " };
3480+ std::vector<CppWString> wlines{ wtext.splitlines (true ) };
3481+ std::vector<CppWString> wexpected{
3482+ L" \v " , L" abc\013 " , L" cde\f " , L" efg\x0c " , L" ghi\x1c " , L" ijk\x1d " , L" klm\x1d " , L" mno\r\n " ,
3483+ L" \n " , L" opq\r " , L" qrs\v " , L" stu\r " , L" uvw\n " , L" wxy\r\n " , L" zzz\x0c " , L" .\n " , L" \r "
3484+ };
3485+ auto exp_it{ wexpected.cbegin () };
3486+ auto lin_it{ wlines.cbegin () };
3487+ for (; lin_it != wlines.cend () && exp_it != wexpected.cend (); ++lin_it, ++exp_it) {
3488+ Assert::AreEqual (exp_it->c_str (), lin_it->c_str ());
3489+ }
3490+ Assert::IsFalse (lin_it != wlines.cend ());
3491+ Assert::IsFalse (exp_it != wexpected.cend ());
3492+ }
3493+
3494+ #pragma warning(pop)
3495+
3496+ }
3497+
33153498 };
33163499}
0 commit comments