@@ -967,7 +967,6 @@ namespace cppstringstests
967967 Assert::AreEqual (L" cdab" , L" abcdab" cs.removeprefix (L" ab" ).c_str ());
968968 }
969969
970-
971970 TEST_METHOD (removesuffix)
972971 {
973972 pcs::CppString s (" abcd" );
@@ -985,7 +984,6 @@ namespace cppstringstests
985984 Assert::AreEqual (L" abcd" , L" abcdab" cs.removesuffix (L" ab" ).c_str ());
986985 }
987986
988-
989987 TEST_METHOD (replace)
990988 {
991989 pcs::CppString s (" abbaa" );
@@ -1022,5 +1020,118 @@ namespace cppstringstests
10221020 Assert::AreEqual (L" AAbbAAAA" , ws.replace (L" a" , L" AA" , 3 ).c_str ());
10231021 Assert::AreEqual (L" aBBaa" , ws.replace (L" b" , L" B" , 5 ).c_str ());
10241022 }
1023+
1024+ TEST_METHOD (rfind)
1025+ {
1026+ size_t found_pos;
1027+
1028+ pcs::CppString test{ " ABC0123456789." };
1029+ for (int c = 0 ; c <= 255 ; ++c) {
1030+ char ch{ char (c) };
1031+ Assert::AreEqual (test.MyBaseClass ::rfind (ch), test.rfind (ch));
1032+
1033+ found_pos = test.substr (2 ).MyBaseClass ::rfind (ch);
1034+ if (found_pos == pcs::CppString::npos)
1035+ Assert::AreEqual (found_pos, test.rfind (ch, 2 ));
1036+ else
1037+ Assert::AreEqual (found_pos, test.rfind (ch, 2 ) - 2 );
1038+
1039+ found_pos = test.substr (2 , 5 ).MyBaseClass ::rfind (ch);
1040+ if (found_pos == pcs::CppString::npos)
1041+ Assert::AreEqual (found_pos, test.rfind (ch, 2 , pcs::CppString::size_type (5 + 2 - 1 )));
1042+ else
1043+ Assert::AreEqual (found_pos, test.rfind (ch, 2 , pcs::CppString::size_type (5 + 2 - 1 )) - 2 );
1044+
1045+ CppString s (ch);
1046+ Assert::AreEqual (test.MyBaseClass ::rfind (s), test.rfind (s));
1047+ found_pos = test.substr (2 ).MyBaseClass ::rfind (s);
1048+ if (found_pos == pcs::CppString::npos)
1049+ Assert::AreEqual (found_pos, test.rfind (s, 2 ));
1050+ else
1051+ Assert::AreEqual (found_pos, test.rfind (s, 2 ) - 2 );
1052+
1053+ found_pos = test.substr (2 , 5 ).MyBaseClass ::rfind (s);
1054+ if (found_pos == pcs::CppString::npos)
1055+ Assert::AreEqual (found_pos, test.rfind (s, 2 , pcs::CppString::size_type (5 + 2 - 1 )));
1056+ else
1057+ Assert::AreEqual (found_pos, test.rfind (s, 2 , pcs::CppString::size_type (5 + 2 - 1 )) - 2 );
1058+
1059+ if (c > 0 ) {
1060+ char str[2 ]{ ch, 0 };
1061+ Assert::AreEqual (test.MyBaseClass ::rfind (str), test.rfind (str));
1062+
1063+ found_pos = test.substr (2 ).MyBaseClass ::rfind (str);
1064+ if (found_pos == pcs::CppString::npos)
1065+ Assert::AreEqual (found_pos, test.rfind (str, 2 ));
1066+ else
1067+ Assert::AreEqual (found_pos, test.rfind (str, 2 ) - 2 );
1068+
1069+ found_pos = test.substr (2 , 5 ).MyBaseClass ::rfind (str);
1070+ if (found_pos == pcs::CppString::npos)
1071+ Assert::AreEqual (found_pos, test.rfind (str, 2 , pcs::CppString::size_type (5 + 2 - 1 )));
1072+ else
1073+ Assert::AreEqual (found_pos, test.rfind (str, 2 , pcs::CppString::size_type (5 + 2 - 1 )) - 2 );
1074+ }
1075+ }
1076+ Assert::AreEqual (pcs::CppString::npos, test.rfind (" A" , 1 ));
1077+ Assert::AreEqual (test.size (), test.rfind (" " ));
1078+ Assert::AreEqual (pcs::CppString::npos, test.rfind (" ." , 14 ));
1079+ Assert::AreEqual (size_t (13 ), test.rfind (" ." , 13 ));
1080+
1081+ pcs::CppWString wtest{ L" ABC0123456789." };
1082+ for (int wc = 0 ; wc <= 0xffff ; ++wc) {
1083+ wchar_t wch{ wchar_t (wc) };
1084+
1085+ found_pos = wtest.substr (2 ).MyBaseClass ::rfind (wch);
1086+ if (found_pos == pcs::CppString::npos)
1087+ Assert::AreEqual (found_pos, wtest.rfind (wch, 2 ));
1088+ else
1089+ Assert::AreEqual (found_pos, wtest.rfind (wch, 2 ) - 2 );
1090+
1091+ found_pos = wtest.substr (2 , 5 ).MyBaseClass ::rfind (wch);
1092+ if (found_pos == pcs::CppString::npos)
1093+ Assert::AreEqual (found_pos, wtest.rfind (wch, 2 , pcs::CppString::size_type (5 + 2 - 1 )));
1094+ else
1095+ Assert::AreEqual (found_pos, wtest.rfind (wch, 2 , pcs::CppString::size_type (5 + 2 - 1 )) - 2 );
1096+
1097+ CppWString ws (wch);
1098+ Assert::AreEqual (wtest.MyBaseClass ::rfind (ws), wtest.rfind (ws));
1099+
1100+ found_pos = wtest.substr (2 ).MyBaseClass ::rfind (ws);
1101+ if (found_pos == pcs::CppString::npos)
1102+ Assert::AreEqual (found_pos, wtest.rfind (ws, 2 ));
1103+ else
1104+ Assert::AreEqual (found_pos, wtest.rfind (ws, 2 ) - 2 );
1105+
1106+ found_pos = wtest.substr (2 , 5 ).MyBaseClass ::rfind (ws);
1107+ if (found_pos == pcs::CppString::npos)
1108+ Assert::AreEqual (found_pos, wtest.rfind (ws, 2 , pcs::CppString::size_type (5 + 2 - 1 )));
1109+ else
1110+ Assert::AreEqual (found_pos, wtest.rfind (ws, 2 , pcs::CppString::size_type (5 + 2 - 1 )) - 2 );
1111+
1112+
1113+ if (wc > 0 ) {
1114+ wchar_t wstr[2 ]{ wch, 0 };
1115+ Assert::AreEqual (wtest.MyBaseClass ::rfind (wstr), wtest.rfind (wstr));
1116+
1117+ found_pos = wtest.substr (2 ).MyBaseClass ::rfind (wstr);
1118+ if (found_pos == pcs::CppString::npos)
1119+ Assert::AreEqual (found_pos, wtest.rfind (wstr, 2 ));
1120+ else
1121+ Assert::AreEqual (found_pos, wtest.rfind (wstr, 2 ) - 2 );
1122+
1123+ found_pos = wtest.substr (2 , 5 ).MyBaseClass ::rfind (wstr);
1124+ if (found_pos == pcs::CppString::npos)
1125+ Assert::AreEqual (found_pos, wtest.rfind (wstr, 2 , pcs::CppString::size_type (5 + 2 - 1 )));
1126+ else
1127+ Assert::AreEqual (found_pos, wtest.rfind (wstr, 2 , pcs::CppString::size_type (5 + 2 - 1 )) - 2 );
1128+ }
1129+ }
1130+ Assert::AreEqual (pcs::CppString::npos, wtest.rfind (L" A" , 1 ));
1131+ Assert::AreEqual (wtest.size (), wtest.rfind (L" " ));
1132+ Assert::AreEqual (pcs::CppString::npos, wtest.rfind (L" ." , 14 ));
1133+ Assert::AreEqual (size_t (13 ), wtest.rfind (L" ." , 13 ));
1134+ }
1135+
10251136 };
10261137}
0 commit comments