Commit 600b85de authored by Marco Bubke's avatar Marco Bubke

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's avatarTim Jenssen <tim.jenssen@qt.io>
parent 2758f05a
......@@ -472,6 +472,15 @@ public:
setSize(newSize);
}
BasicSmallString toCarriageReturnsStripped() const
{
BasicSmallString text = *this;
text.replace("\r", "");
return text;
}
constexpr static
size_type shortStringCapacity() noexcept
{
......
......@@ -1050,3 +1050,12 @@ TEST(SmallString, ReplaceByPositionEqualSizedTexts)
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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment