forked from qt-creator/qt-creator
Utils: Add std::string conversion constructor and operator to small string
Change-Id: Ia76d7647fc8d2c9b72bc5bce2e7a6e2c3fcc18cc Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#pragma push_macro("constexpr")
|
#pragma push_macro("constexpr")
|
||||||
@@ -127,6 +128,10 @@ public:
|
|||||||
: SmallString(SmallString::fromQString(qString))
|
: SmallString(SmallString::fromQString(qString))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
SmallString(const std::string &stdString)
|
||||||
|
: SmallString(stdString.data(), stdString.size())
|
||||||
|
{}
|
||||||
|
|
||||||
template<typename BeginIterator,
|
template<typename BeginIterator,
|
||||||
typename EndIterator,
|
typename EndIterator,
|
||||||
typename = typename std::enable_if<std::is_same<BeginIterator, EndIterator>::value>::type
|
typename = typename std::enable_if<std::is_same<BeginIterator, EndIterator>::value>::type
|
||||||
@@ -216,6 +221,11 @@ public:
|
|||||||
return toQString();
|
return toQString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator std::string() const
|
||||||
|
{
|
||||||
|
return std::string(data(), size());
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
SmallString fromUtf8(const char *characterPointer)
|
SmallString fromUtf8(const char *characterPointer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -131,6 +131,11 @@ public:
|
|||||||
return clonedVector;
|
return clonedVector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator std::vector<std::string>() const
|
||||||
|
{
|
||||||
|
return std::vector<std::string>(begin(), end());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t totalByteSize() const
|
std::size_t totalByteSize() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -319,6 +319,15 @@ TEST(SmallString, RBeginPlusOneIsEqualREndForSmallStringWidthSizeOne)
|
|||||||
ASSERT_THAT(beginPlusOne, Eq(text.rend()));
|
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)
|
TEST(SmallString, ToQString)
|
||||||
{
|
{
|
||||||
SmallString text("short string");
|
SmallString text("short string");
|
||||||
|
|||||||
Reference in New Issue
Block a user