File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -893,5 +893,22 @@ namespace cppstringstests
893893 Assert::AreEqual (L" cdab" , L" abcdab" cs.removeprefix (L" ab" ).c_str ());
894894 }
895895
896+
897+ TEST_METHOD (removesuffix)
898+ {
899+ pcs::CppString s (" abcd" );
900+ Assert::AreEqual (" ab" , s.removesuffix (" cd" ).c_str ());
901+ Assert::AreEqual (" abcd" , s.removesuffix (" dc" ).c_str ());
902+ Assert::AreEqual (" abcd" , s.removesuffix (" " ).c_str ());
903+ Assert::AreEqual (" abbaba" , " abbabaabcd" cs.removesuffix (" abcd" ).c_str ());
904+ Assert::AreEqual (" abcd" , " abcdab" cs.removesuffix (" ab" ).c_str ());
905+
906+ pcs::CppWString ws (L" abcd" );
907+ Assert::AreEqual (L" ab" , ws.removesuffix (L" cd" ).c_str ());
908+ Assert::AreEqual (L" abcd" , ws.removesuffix (L" dc" ).c_str ());
909+ Assert::AreEqual (L" abcd" , ws.removesuffix (L" " ).c_str ());
910+ Assert::AreEqual (L" abbaba" , L" abbabaabcd" cs.removesuffix (L" abcd" ).c_str ());
911+ Assert::AreEqual (L" abcd" , L" abcdab" cs.removesuffix (L" ab" ).c_str ());
912+ }
896913 };
897914}
Original file line number Diff line number Diff line change @@ -1174,7 +1174,7 @@ namespace pcs // i.e. "pythonic c++ strings"
11741174 {
11751175 if (this ->endswith (suffix)) {
11761176 const size_type suffix_length = suffix.size ();
1177- return this ->substr (0 , this ->size () - suffix_length + 1 );
1177+ return this ->substr (0 , this ->size () - suffix_length);
11781178 }
11791179 else
11801180 return *this ;
You can’t perform that action at this time.
0 commit comments