Commit 390e2d16 authored by Marco Bubke's avatar Marco Bubke

Utils: Add iterator constructors to small string

Change-Id: Ib8fcacd5dc520842cf5cee73ea21c021221158ca
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 7610e487
......@@ -127,6 +127,16 @@ public:
: SmallString(SmallString::fromQString(qString))
{}
template<typename BeginIterator,
typename EndIterator,
typename = typename std::enable_if<std::is_same<BeginIterator, EndIterator>::value>::type
>
SmallString(BeginIterator begin, EndIterator end)
: SmallString(&(*begin), size_type(end - begin))
{
}
~SmallString() noexcept
{
if (Q_UNLIKELY(hasAllocatedMemory()))
......
......@@ -80,6 +80,33 @@ TEST(SmallString, ShortSmallStringIsShortSmallString)
#endif
}
TEST(SmallString, CreateFromCStringIterators)
{
char sourceText[] = "this is very very very very very much text";
SmallString text(sourceText, &sourceText[sizeof(sourceText) - 1]);
ASSERT_THAT(text, SmallString("this is very very very very very much text"));
}
TEST(SmallString, CreateFromQByteArrayIterators)
{
QByteArray sourceText = "this is very very very very very much text";
SmallString text(sourceText.begin(), sourceText.end());
ASSERT_THAT(text, SmallString("this is very very very very very much text"));
}
TEST(SmallString, CreateFromSmallStringIterators)
{
SmallString sourceText = "this is very very very very very much text";
SmallString text(sourceText.begin(), sourceText.end());
ASSERT_THAT(text, SmallString("this is very very very very very much text"));
}
TEST(SmallString, ShortSmallStringIsReference)
{
SmallString longText("very very very very very long text");
......
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