Commit 0549c6af authored by Marco Bubke's avatar Marco Bubke

Utils: Add std::string conversion constructor and operator to small string

Change-Id: Ia76d7647fc8d2c9b72bc5bce2e7a6e2c3fcc18cc
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 390e2d16
......@@ -42,6 +42,7 @@
#include <climits>
#include <cstring>
#include <iosfwd>
#include <string>
#include <utility>
#pragma push_macro("constexpr")
......@@ -127,6 +128,10 @@ public:
: SmallString(SmallString::fromQString(qString))
{}
SmallString(const std::string &stdString)
: SmallString(stdString.data(), stdString.size())
{}
template<typename BeginIterator,
typename EndIterator,
typename = typename std::enable_if<std::is_same<BeginIterator, EndIterator>::value>::type
......@@ -216,6 +221,11 @@ public:
return toQString();
}
operator std::string() const
{
return std::string(data(), size());
}
static
SmallString fromUtf8(const char *characterPointer)
{
......
......@@ -131,6 +131,11 @@ public:
return clonedVector;
}
operator std::vector<std::string>() const
{
return std::vector<std::string>(begin(), end());
}
private:
std::size_t totalByteSize() const
{
......
......@@ -319,6 +319,15 @@ TEST(SmallString, RBeginPlusOneIsEqualREndForSmallStringWidthSizeOne)
ASSERT_THAT(beginPlusOne, Eq(text.rend()));
}
TEST(SmallString, ConstructorStandardString)
{
std::string stdStringText = "short string";
auto text = SmallString(stdStringText);
ASSERT_THAT(text, SmallString("short string"));
}
TEST(SmallString, ToQString)
{
SmallString text("short string");
......
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