Utils: Add carriage return strip method to SmallString

Sometimes you want to compare unix and windows texts in tests. This is a
convenient function to remove the carriage returns.

Change-Id: I164298b70d3d775dd45903ea3753ac0e68ed2fdc
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2016-11-28 13:57:33 +01:00
parent 2758f05af2
commit 600b85defa
2 changed files with 18 additions and 0 deletions

View File

@@ -472,6 +472,15 @@ public:
setSize(newSize); setSize(newSize);
} }
BasicSmallString toCarriageReturnsStripped() const
{
BasicSmallString text = *this;
text.replace("\r", "");
return text;
}
constexpr static constexpr static
size_type shortStringCapacity() noexcept size_type shortStringCapacity() noexcept
{ {

View File

@@ -1050,3 +1050,12 @@ TEST(SmallString, ReplaceByPositionEqualSizedTexts)
ASSERT_THAT(text, SmallString("this is very very very very very much text")); ASSERT_THAT(text, SmallString("this is very very very very very much text"));
} }
TEST(SmallString, CompareTextWithDifferentLineEndings)
{
SmallString unixText("some \ntext");
SmallString windowsText("some \n\rtext");
auto convertedText = windowsText.toCarriageReturnsStripped();
ASSERT_THAT(unixText, convertedText);
}