diff options
author | Lei Zhang <thestig@chromium.org> | 2017-11-21 18:07:00 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-21 18:07:00 +0000 |
commit | 135c6601bd9d12bd935371d3122f8e75391de75b (patch) | |
tree | 185227ece2aa6cceb58911d2b25871dab4860251 /core/fxcrt/bytestring_unittest.cpp | |
parent | f276e78e190e04b25c3f05b35a28ecdd30bdcf21 (diff) | |
download | pdfium-135c6601bd9d12bd935371d3122f8e75391de75b.tar.xz |
Add {Byte/Wide}String::Trim().
So callers no longer have to call str.TrimLeft(); str.TrimRight();
Change-Id: If931eaa8d891f487b9618ebbeee5ee294e807846
Reviewed-on: https://pdfium-review.googlesource.com/18990
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/bytestring_unittest.cpp')
-rw-r--r-- | core/fxcrt/bytestring_unittest.cpp | 118 |
1 files changed, 76 insertions, 42 deletions
diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp index 08c0e9211c..b45ee0fd5e 100644 --- a/core/fxcrt/bytestring_unittest.cpp +++ b/core/fxcrt/bytestring_unittest.cpp @@ -703,41 +703,75 @@ TEST(ByteString, UpperLower) { EXPECT_EQ("", empty); } -TEST(ByteString, TrimRight) { +TEST(ByteString, Trim) { ByteString fred(" FRED "); - fred.TrimRight(); - EXPECT_EQ(" FRED", fred); - fred.TrimRight('E'); - EXPECT_EQ(" FRED", fred); - fred.TrimRight('D'); - EXPECT_EQ(" FRE", fred); - fred.TrimRight("ERP"); - EXPECT_EQ(" F", fred); + fred.Trim(); + EXPECT_EQ("FRED", fred); + fred.Trim('E'); + EXPECT_EQ("FRED", fred); + fred.Trim('F'); + EXPECT_EQ("RED", fred); + fred.Trim("ERP"); + EXPECT_EQ("D", fred); ByteString blank(" "); - blank.TrimRight("ERP"); + blank.Trim("ERP"); EXPECT_EQ(" ", blank); - blank.TrimRight('E'); + blank.Trim('E'); EXPECT_EQ(" ", blank); - blank.TrimRight(); + blank.Trim(); EXPECT_EQ("", blank); ByteString empty; - empty.TrimRight("ERP"); + empty.Trim("ERP"); EXPECT_EQ("", empty); - empty.TrimRight('E'); + empty.Trim('E'); EXPECT_EQ("", empty); - empty.TrimRight(); + empty.Trim(); EXPECT_EQ("", empty); + + ByteString abc(" ABCCBA "); + abc.Trim("A"); + EXPECT_EQ(" ABCCBA ", abc); + abc.Trim(" A"); + EXPECT_EQ("BCCB", abc); } -TEST(ByteString, TrimRightCopies) { +TEST(ByteString, TrimLeft) { + ByteString fred(" FRED "); + fred.TrimLeft(); + EXPECT_EQ("FRED ", fred); + fred.TrimLeft('E'); + EXPECT_EQ("FRED ", fred); + fred.TrimLeft('F'); + EXPECT_EQ("RED ", fred); + fred.TrimLeft("ERP"); + EXPECT_EQ("D ", fred); + + ByteString blank(" "); + blank.TrimLeft("ERP"); + EXPECT_EQ(" ", blank); + blank.TrimLeft('E'); + EXPECT_EQ(" ", blank); + blank.TrimLeft(); + EXPECT_EQ("", blank); + + ByteString empty; + empty.TrimLeft("ERP"); + EXPECT_EQ("", empty); + empty.TrimLeft('E'); + EXPECT_EQ("", empty); + empty.TrimLeft(); + EXPECT_EQ("", empty); +} + +TEST(ByteString, TrimLeftCopies) { { // With a single reference, no copy takes place. ByteString fred(" FRED "); const char* old_buffer = fred.c_str(); - fred.TrimRight(); - EXPECT_EQ(" FRED", fred); + fred.TrimLeft(); + EXPECT_EQ("FRED ", fred); EXPECT_EQ(old_buffer, fred.c_str()); } { @@ -745,8 +779,8 @@ TEST(ByteString, TrimRightCopies) { ByteString fred(" FRED "); ByteString other_fred = fred; const char* old_buffer = fred.c_str(); - fred.TrimRight(); - EXPECT_EQ(" FRED", fred); + fred.TrimLeft(); + EXPECT_EQ("FRED ", fred); EXPECT_EQ(" FRED ", other_fred); EXPECT_NE(old_buffer, fred.c_str()); } @@ -755,48 +789,48 @@ TEST(ByteString, TrimRightCopies) { ByteString fred("FRED"); ByteString other_fred = fred; const char* old_buffer = fred.c_str(); - fred.TrimRight(); + fred.TrimLeft(); EXPECT_EQ("FRED", fred); EXPECT_EQ("FRED", other_fred); EXPECT_EQ(old_buffer, fred.c_str()); } } -TEST(ByteString, TrimLeft) { +TEST(ByteString, TrimRight) { ByteString fred(" FRED "); - fred.TrimLeft(); - EXPECT_EQ("FRED ", fred); - fred.TrimLeft('E'); - EXPECT_EQ("FRED ", fred); - fred.TrimLeft('F'); - EXPECT_EQ("RED ", fred); - fred.TrimLeft("ERP"); - EXPECT_EQ("D ", fred); + fred.TrimRight(); + EXPECT_EQ(" FRED", fred); + fred.TrimRight('E'); + EXPECT_EQ(" FRED", fred); + fred.TrimRight('D'); + EXPECT_EQ(" FRE", fred); + fred.TrimRight("ERP"); + EXPECT_EQ(" F", fred); ByteString blank(" "); - blank.TrimLeft("ERP"); + blank.TrimRight("ERP"); EXPECT_EQ(" ", blank); - blank.TrimLeft('E'); + blank.TrimRight('E'); EXPECT_EQ(" ", blank); - blank.TrimLeft(); + blank.TrimRight(); EXPECT_EQ("", blank); ByteString empty; - empty.TrimLeft("ERP"); + empty.TrimRight("ERP"); EXPECT_EQ("", empty); - empty.TrimLeft('E'); + empty.TrimRight('E'); EXPECT_EQ("", empty); - empty.TrimLeft(); + empty.TrimRight(); EXPECT_EQ("", empty); } -TEST(ByteString, TrimLeftCopies) { +TEST(ByteString, TrimRightCopies) { { // With a single reference, no copy takes place. ByteString fred(" FRED "); const char* old_buffer = fred.c_str(); - fred.TrimLeft(); - EXPECT_EQ("FRED ", fred); + fred.TrimRight(); + EXPECT_EQ(" FRED", fred); EXPECT_EQ(old_buffer, fred.c_str()); } { @@ -804,8 +838,8 @@ TEST(ByteString, TrimLeftCopies) { ByteString fred(" FRED "); ByteString other_fred = fred; const char* old_buffer = fred.c_str(); - fred.TrimLeft(); - EXPECT_EQ("FRED ", fred); + fred.TrimRight(); + EXPECT_EQ(" FRED", fred); EXPECT_EQ(" FRED ", other_fred); EXPECT_NE(old_buffer, fred.c_str()); } @@ -814,7 +848,7 @@ TEST(ByteString, TrimLeftCopies) { ByteString fred("FRED"); ByteString other_fred = fred; const char* old_buffer = fred.c_str(); - fred.TrimLeft(); + fred.TrimRight(); EXPECT_EQ("FRED", fred); EXPECT_EQ("FRED", other_fred); EXPECT_EQ(old_buffer, fred.c_str()); |