mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:59:56 +00:00
[SmallString] Add explicit conversion to std::string
With the conversion between StringRef and std::string now being explicit, converting SmallStrings becomes more tedious. This patch adds an explicit operator so you can write std::string(Str) instead of Str.str().str(). Differential revision: https://reviews.llvm.org/D73640
This commit is contained in:
parent
f5970fd81b
commit
59878130bd
@ -275,6 +275,8 @@ public:
|
||||
/// Implicit conversion to StringRef.
|
||||
operator StringRef() const { return str(); }
|
||||
|
||||
explicit operator std::string() const { return str().str(); }
|
||||
|
||||
// Extra operators.
|
||||
const SmallString &operator=(StringRef RHS) {
|
||||
this->clear();
|
||||
|
@ -96,6 +96,20 @@ TEST_F(SmallStringTest, AppendSmallVector) {
|
||||
EXPECT_STREQ("abcabc", theString.c_str());
|
||||
}
|
||||
|
||||
TEST_F(SmallStringTest, StringRefConversion) {
|
||||
StringRef abc = "abc";
|
||||
theString.assign(abc.begin(), abc.end());
|
||||
StringRef theStringRef = theString;
|
||||
EXPECT_EQ("abc", theStringRef);
|
||||
}
|
||||
|
||||
TEST_F(SmallStringTest, StdStringConversion) {
|
||||
StringRef abc = "abc";
|
||||
theString.assign(abc.begin(), abc.end());
|
||||
std::string theStdString = std::string(theString);
|
||||
EXPECT_EQ("abc", theStdString);
|
||||
}
|
||||
|
||||
TEST_F(SmallStringTest, Substr) {
|
||||
theString = "hello";
|
||||
EXPECT_EQ("lo", theString.substr(3));
|
||||
|
Loading…
Reference in New Issue
Block a user