From 06c6855258bf25246c46a1f628b8a8a8185029a7 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 13 Sep 2017 11:16:32 -0400 Subject: Rewrite IsHyphen using string operations The existing code did end of range checks by making sure that the value was never less then 0. This isn't correct when using an unsigned type, since 0 - 1 will wrap around to the max possible value, and thus still be less then 0. Additionally the existing code was hard to follow due to the complexity of some of the low level operations being performed. It has been rewritten using higher level string operations to make it clearer and correct. BUG=chromium:763256 Change-Id: Ib8bf5ca0e29e73724c4a1c4781362e8a8fc30149 Reviewed-on: https://pdfium-review.googlesource.com/13690 Commit-Queue: Ryan Harrison Reviewed-by: Tom Sepez --- core/fxcrt/cfx_bytestring_unittest.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'core/fxcrt/cfx_bytestring_unittest.cpp') diff --git a/core/fxcrt/cfx_bytestring_unittest.cpp b/core/fxcrt/cfx_bytestring_unittest.cpp index dcb8577b65..a4c5187c11 100644 --- a/core/fxcrt/cfx_bytestring_unittest.cpp +++ b/core/fxcrt/cfx_bytestring_unittest.cpp @@ -999,6 +999,14 @@ TEST(fxcrt, ByteStringCMid) { EXPECT_EQ("", longer_string.Mid(4, 3)); } +TEST(fxcrt, ByteStringCTrimmedRight) { + CFX_ByteStringC fred("FRED"); + EXPECT_EQ("FRED", fred.TrimmedRight('E')); + EXPECT_EQ("FRE", fred.TrimmedRight('D')); + CFX_ByteStringC fredd("FREDD"); + EXPECT_EQ("FRE", fred.TrimmedRight('D')); +} + TEST(fxcrt, ByteStringCElementAccess) { // CFX_ByteStringC includes the NUL terminator for non-empty strings. CFX_ByteStringC abc("abc"); -- cgit v1.2.3