Commit b2c8d761 authored by Marco Bubke's avatar Marco Bubke

Utils: Add constructor for character pointer

Change-Id: I12bd787caf911502a666de2c324bb74b8bd7b0aa
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent c8e90be9
......@@ -114,6 +114,15 @@ public:
{
}
template<typename Type,
typename = typename std::enable_if<std::is_pointer<Type>::value>::type
>
SmallString(Type characterPointer) noexcept
: SmallString(characterPointer, std::strlen(characterPointer))
{
static_assert(!std::is_array<Type>::value, "Input type is array and not char pointer!");
}
SmallString(const QString &qString)
: SmallString(SmallString::fromQString(qString))
{}
......
......@@ -87,6 +87,14 @@ TEST(SmallString, ShortSmallStringIsReference)
ASSERT_TRUE(longText.isReadOnlyReference());
}
TEST(SmallString, SmallStringContructorIsNotReference)
{
const char *shortCSmallString = "short string";
auto shortText = SmallString(shortCSmallString);
ASSERT_TRUE(shortText.isShortString());
}
TEST(SmallString, ShortSmallStringIsNotReference)
{
const char *shortCSmallString = "short string";
......@@ -95,6 +103,14 @@ TEST(SmallString, ShortSmallStringIsNotReference)
ASSERT_FALSE(shortText.isReadOnlyReference());
}
TEST(SmallString, LongSmallStringConstrutorIsAllocated)
{
const char *longCSmallString = "very very very very very long text";
auto longText = SmallString(longCSmallString);
ASSERT_TRUE(longText.hasAllocatedMemory());
}
TEST(SmallString, MaximumShortSmallString)
{
SmallString maximumShortText("very very very very short text", 30);
......
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