mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
cmString: add methods append and insert
This commit is contained in:
@@ -425,6 +425,16 @@ public:
|
|||||||
r.append(v.data(), v.size());
|
r.append(v.data(), v.size());
|
||||||
return *this = std::move(r);
|
return *this = std::move(r);
|
||||||
}
|
}
|
||||||
|
template <typename T>
|
||||||
|
typename std::enable_if<AsStringView<T>::value, String&>::type append(T&& s)
|
||||||
|
{
|
||||||
|
string_view v = AsStringView<T>::view(std::forward<T>(s));
|
||||||
|
std::string r;
|
||||||
|
r.reserve(this->size() + v.size());
|
||||||
|
r.assign(this->data(), this->size());
|
||||||
|
r.append(v.data(), v.size());
|
||||||
|
return *this = std::move(r);
|
||||||
|
}
|
||||||
|
|
||||||
/** Assign to an empty string. */
|
/** Assign to an empty string. */
|
||||||
void clear() { *this = ""_s; }
|
void clear() { *this = ""_s; }
|
||||||
@@ -432,6 +442,20 @@ public:
|
|||||||
/** Insert 'count' copies of 'ch' at position 'index'. */
|
/** Insert 'count' copies of 'ch' at position 'index'. */
|
||||||
String& insert(size_type index, size_type count, char ch);
|
String& insert(size_type index, size_type count, char ch);
|
||||||
|
|
||||||
|
/** Insert into the string using any type that implements the
|
||||||
|
AsStringView trait. */
|
||||||
|
template <typename T>
|
||||||
|
typename std::enable_if<AsStringView<T>::value, String&>::type insert(
|
||||||
|
size_type index, T&& s)
|
||||||
|
{
|
||||||
|
string_view v = AsStringView<T>::view(std::forward<T>(s));
|
||||||
|
std::string r;
|
||||||
|
r.reserve(this->size() + v.size());
|
||||||
|
r.assign(this->data(), this->size());
|
||||||
|
r.insert(index, v.data(), v.size());
|
||||||
|
return *this = std::move(r);
|
||||||
|
}
|
||||||
|
|
||||||
/** Erase 'count' characters starting at position 'index'. */
|
/** Erase 'count' characters starting at position 'index'. */
|
||||||
String& erase(size_type index = 0, size_type count = npos);
|
String& erase(size_type index = 0, size_type count = npos);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user