@@ -3317,8 +3317,8 @@ namespace cppstringstests
33173317#pragma warning(push)
33183318#pragma warning(disable: 4566) // to get no warning when current page code is not compatible with next unicode points
33193319 {
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 () };
3320+ CppString wtext { " \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{ wtext .splitlines () };
33223322 std::vector<CppString> expected{ " " , " abc" , " cde" , " efg" , " ghi" , " ijk" , " klm" , " mno" , " " , " opq" , " qrs" , " stu" , " uvw" , " wxy" , " zzz" , " ." };
33233323 auto exp_it{ expected.cbegin () };
33243324 auto lin_it{ lines.cbegin () };
@@ -3330,8 +3330,8 @@ namespace cppstringstests
33303330 }
33313331
33323332 {
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 () };
3333+ CppString wtext { " \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{ wtext .splitlines () };
33353335 std::vector<CppString> expected{ " " , " abc" , " cde" , " efg" , " ghi" , " ijk" , " klm" , " mno" , " " , " opq" , " qrs" , " stu" , " uvw" , " wxy" , " zzz" , " ." };
33363336 auto exp_it{ expected.cbegin () };
33373337 auto lin_it{ lines.cbegin () };
@@ -3343,8 +3343,8 @@ namespace cppstringstests
33433343 }
33443344
33453345 {
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 () };
3346+ CppString wtext { " \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{ wtext .splitlines () };
33483348 std::vector<CppString> expected{ " " , " abc" , " cde" , " efg" , " ghi" , " ijk" , " klm" , " mno" , " " , " opq" , " qrs" , " stu" , " uvw" , " wxy" , " zzz" , " ." , " " };
33493349 auto exp_it{ expected.cbegin () };
33503350 auto lin_it{ lines.cbegin () };
@@ -3356,8 +3356,8 @@ namespace cppstringstests
33563356 }
33573357
33583358 {
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 ) };
3359+ CppString wtext { " \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{ wtext .splitlines (true ) };
33613361 std::vector<CppString> expected{
33623362 " \v " , " abc\013 " , " cde\f " , " efg\x0c " , " ghi\x1c " , " ijk\x1d " , " klm\x1d " , " mno\r\n " ,
33633363 " \n " , " opq\r " , " qrs\v " , " stu\r " , " uvw\n " , " wxy\r\n " , " zzz\x0c " , " .\r "
@@ -3372,8 +3372,8 @@ namespace cppstringstests
33723372 }
33733373
33743374 {
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 ) };
3375+ CppString wtext { " \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{ wtext .splitlines (true ) };
33773377 std::vector<CppString> expected{
33783378 " \v " , " abc\013 " , " cde\f " , " efg\x0c " , " ghi\x1c " , " ijk\x1d " , " klm\x1d " , " mno\r\n " ,
33793379 " \n " , " opq\r " , " qrs\v " , " stu\r " , " uvw\n " , " wxy\r\n " , " zzz\x0c " , " .\r\n "
@@ -3388,8 +3388,8 @@ namespace cppstringstests
33883388 }
33893389
33903390 {
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 ) };
3391+ CppString wtext { " \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{ wtext .splitlines (true ) };
33933393 std::vector<CppString> expected{
33943394 " \v " , " abc\013 " , " cde\f " , " efg\x0c " , " ghi\x1c " , " ijk\x1d " , " klm\x1d " , " mno\r\n " ,
33953395 " \n " , " opq\r " , " qrs\v " , " stu\r " , " uvw\n " , " wxy\r\n " , " zzz\x0c " , " .\n " , " \r "
@@ -3495,5 +3495,126 @@ namespace cppstringstests
34953495
34963496 }
34973497
3498+ TEST_METHOD (startswith)
3499+ {
3500+ CppString text (" Abcdef" );
3501+ const size_t len{ text.size () };
3502+
3503+ Assert::IsTrue (text.startswith (" A" ));
3504+ Assert::IsTrue (text.startswith (" Ab" ));
3505+ Assert::IsTrue (text.startswith (" Abc" ));
3506+ Assert::IsTrue (text.startswith (" Abcd" ));
3507+ Assert::IsTrue (text.startswith (" Abcde" ));
3508+ Assert::IsTrue (text.startswith (" Abcdef" ));
3509+ Assert::IsFalse (text.startswith (" Abcdefg" ));
3510+ Assert::IsFalse (text.startswith (" a" ));
3511+ Assert::IsFalse (text.startswith (" def" ));
3512+
3513+ Assert::IsTrue (text.startswith (" b" , 1 ));
3514+ Assert::IsTrue (text.startswith (" bc" , 1 ));
3515+ Assert::IsTrue (text.startswith (" bcd" , 1 ));
3516+ Assert::IsFalse (text.startswith (" bcdefg" , 1 ));
3517+ Assert::IsFalse (text.startswith (" A" , 1 ));
3518+ Assert::IsFalse (text.startswith (" def" , 1 ));
3519+
3520+ Assert::IsTrue (text.startswith (" c" , 2 ));
3521+ Assert::IsTrue (text.startswith (" cd" , 2 ));
3522+ Assert::IsTrue (text.startswith (" cde" , 2 ));
3523+ Assert::IsFalse (text.startswith (" cdefg" , 2 ));
3524+ Assert::IsFalse (text.startswith (" Ab" , 2 ));
3525+ Assert::IsFalse (text.startswith (" def" , 2 ));
3526+
3527+ Assert::IsTrue (text.startswith (" d" , 3 ));
3528+ Assert::IsTrue (text.startswith (" de" , 3 ));
3529+ Assert::IsTrue (text.startswith (" def" , 3 ));
3530+ Assert::IsFalse (text.startswith (" defg" , 3 ));
3531+ Assert::IsFalse (text.startswith (" Abc" , 3 ));
3532+ Assert::IsFalse (text.startswith (" ef" , 3 ));
3533+
3534+ Assert::IsTrue (text.startswith (" e" , 4 ));
3535+ Assert::IsTrue (text.startswith (" ef" , 4 ));
3536+ Assert::IsFalse (text.startswith (" efg" , 4 ));
3537+ Assert::IsFalse (text.startswith (" Abcd" , 4 ));
3538+ Assert::IsFalse (text.startswith (" f" , 4 ));
3539+
3540+ Assert::IsTrue (text.startswith (" f" , 5 ));
3541+ Assert::IsFalse (text.startswith (" fg" , 5 ));
3542+ Assert::IsFalse (text.startswith (" Abcde" , 5 ));
3543+ Assert::IsFalse (text.startswith (" g" , 5 ));
3544+
3545+ Assert::IsTrue (text.startswith (" A" , 0 , 0 ));
3546+ Assert::IsFalse (text.startswith (" b" , 0 , 0 ));
3547+ Assert::IsTrue (text.startswith (" b" , 1 , 3 ));
3548+ Assert::IsTrue (text.startswith (" bc" , 1 , 3 ));
3549+ Assert::IsTrue (text.startswith (" bcd" , 1 , 3 ));
3550+ Assert::IsFalse (text.startswith (" bcde" , 1 , 3 ));
3551+
3552+ Assert::IsTrue (text.startswith (" " , 5 , 2 ));
3553+ Assert::IsTrue (text.startswith (" " , 15 , 16 ));
3554+
3555+ Assert::IsTrue (text.startswith ({ " ghi" , " abca" , " Abcd" }, 0 , len - 2 ));
3556+ Assert::IsFalse (text.startswith ({ " def" , " ghi" }, 0 , len - 4 ));
3557+ Assert::IsFalse (text.startswith ({ " def" , " ghi" , " Abcd" }, 0 , len - 4 ));
3558+
3559+
3560+ CppWString wtext (L" Abcdef" );
3561+
3562+ Assert::IsTrue (wtext.startswith (L" A" ));
3563+ Assert::IsTrue (wtext.startswith (L" Ab" ));
3564+ Assert::IsTrue (wtext.startswith (L" Abc" ));
3565+ Assert::IsTrue (wtext.startswith (L" Abcd" ));
3566+ Assert::IsTrue (wtext.startswith (L" Abcde" ));
3567+ Assert::IsTrue (wtext.startswith (L" Abcdef" ));
3568+ Assert::IsFalse (wtext.startswith (L" Abcdefg" ));
3569+ Assert::IsFalse (wtext.startswith (L" a" ));
3570+ Assert::IsFalse (wtext.startswith (L" def" ));
3571+
3572+ Assert::IsTrue (wtext.startswith (L" b" , 1 ));
3573+ Assert::IsTrue (wtext.startswith (L" bc" , 1 ));
3574+ Assert::IsTrue (wtext.startswith (L" bcd" , 1 ));
3575+ Assert::IsFalse (wtext.startswith (L" bcdefg" , 1 ));
3576+ Assert::IsFalse (wtext.startswith (L" A" , 1 ));
3577+ Assert::IsFalse (wtext.startswith (L" def" , 1 ));
3578+
3579+ Assert::IsTrue (wtext.startswith (L" c" , 2 ));
3580+ Assert::IsTrue (wtext.startswith (L" cd" , 2 ));
3581+ Assert::IsTrue (wtext.startswith (L" cde" , 2 ));
3582+ Assert::IsFalse (wtext.startswith (L" cdefg" , 2 ));
3583+ Assert::IsFalse (wtext.startswith (L" Ab" , 2 ));
3584+ Assert::IsFalse (wtext.startswith (L" def" , 2 ));
3585+
3586+ Assert::IsTrue (wtext.startswith (L" d" , 3 ));
3587+ Assert::IsTrue (wtext.startswith (L" de" , 3 ));
3588+ Assert::IsTrue (wtext.startswith (L" def" , 3 ));
3589+ Assert::IsFalse (wtext.startswith (L" defg" , 3 ));
3590+ Assert::IsFalse (wtext.startswith (L" Abc" , 3 ));
3591+ Assert::IsFalse (wtext.startswith (L" ef" , 3 ));
3592+
3593+ Assert::IsTrue (wtext.startswith (L" e" , 4 ));
3594+ Assert::IsTrue (wtext.startswith (L" ef" , 4 ));
3595+ Assert::IsFalse (wtext.startswith (L" efg" , 4 ));
3596+ Assert::IsFalse (wtext.startswith (L" Abcd" , 4 ));
3597+ Assert::IsFalse (wtext.startswith (L" f" , 4 ));
3598+
3599+ Assert::IsTrue (wtext.startswith (L" f" , 5 ));
3600+ Assert::IsFalse (wtext.startswith (L" fg" , 5 ));
3601+ Assert::IsFalse (wtext.startswith (L" Abcde" , 5 ));
3602+ Assert::IsFalse (wtext.startswith (L" g" , 5 ));
3603+
3604+ Assert::IsTrue (wtext.startswith (L" A" , 0 , 0 ));
3605+ Assert::IsFalse (wtext.startswith (L" b" , 0 , 0 ));
3606+ Assert::IsTrue (wtext.startswith (L" b" , 1 , 3 ));
3607+ Assert::IsTrue (wtext.startswith (L" bc" , 1 , 3 ));
3608+ Assert::IsTrue (wtext.startswith (L" bcd" , 1 , 3 ));
3609+ Assert::IsFalse (wtext.startswith (L" bcde" , 1 , 3 ));
3610+
3611+ Assert::IsTrue (wtext.startswith (L" " , 5 , 2 ));
3612+ Assert::IsTrue (wtext.startswith (L" " , 15 , 16 ));
3613+
3614+ Assert::IsTrue (wtext.startswith ({ L" ghi" , L" abca" , L" Abcd" }, 0 , len - 2 ));
3615+ Assert::IsFalse (wtext.startswith ({ L" def" , L" ghi" }, 0 , len - 4 ));
3616+ Assert::IsFalse (wtext.startswith ({ L" def" , L" ghi" , L" Abcd" }, 0 , len - 4 ));
3617+ }
3618+
34983619 };
34993620}
0 commit comments