return find_last_not_of(&c, pos, 1);
}
- basic_fbstring substr(size_type pos = 0, size_type n = npos) const {
+ basic_fbstring substr(size_type pos = 0, size_type n = npos) const& {
enforce(pos <= size(), std::__throw_out_of_range, "");
return basic_fbstring(data() + pos, std::min(n, size() - pos));
}
+ basic_fbstring substr(size_type pos = 0, size_type n = npos) && {
+ enforce(pos <= size(), std::__throw_out_of_range, "");
+ erase(0, pos);
+ if (n < size()) resize(n);
+ return std::move(*this);
+ }
+
int compare(const basic_fbstring& str) const {
// FIX due to Goncalo N M de Carvalho July 18, 2005
return compare(0, size(), str);
};
// non-member functions
-// C++11 21.4.8.1/2
+// C++11 21.4.8.1/1
template <typename E, class T, class A, class S>
inline
basic_fbstring<E, T, A, S> operator+(const basic_fbstring<E, T, A, S>& lhs,
return std::move(lhs.append(rhs));
}
+// C++11 21.4.8.1/5
template <typename E, class T, class A, class S>
inline
basic_fbstring<E, T, A, S> operator+(
- const typename basic_fbstring<E, T, A, S>::value_type* lhs,
+ const E* lhs,
const basic_fbstring<E, T, A, S>& rhs) {
//
basic_fbstring<E, T, A, S> result;
- const typename basic_fbstring<E, T, A, S>::size_type len =
- basic_fbstring<E, T, A, S>::traits_type::length(lhs);
+ const auto len = basic_fbstring<E, T, A, S>::traits_type::length(lhs);
result.reserve(len + rhs.size());
result.append(lhs, len).append(rhs);
return result;
}
+// C++11 21.4.8.1/6
template <typename E, class T, class A, class S>
inline
basic_fbstring<E, T, A, S> operator+(
- typename basic_fbstring<E, T, A, S>::value_type lhs,
+ const E* lhs,
+ basic_fbstring<E, T, A, S>&& rhs) {
+ //
+ const auto len = basic_fbstring<E, T, A, S>::traits_type::length(lhs);
+ if (rhs.capacity() >= len + rhs.size()) {
+ // Good, at least we don't need to reallocate
+ return std::move(rhs.insert(rhs.begin(), lhs, lhs + len));
+ }
+ // Meh, no go. Do it by hand since we have len already.
+ basic_fbstring<E, T, A, S> result;
+ result.reserve(len + rhs.size());
+ result.append(lhs, len).append(rhs);
+ return result;
+}
+
+// C++11 21.4.8.1/7
+template <typename E, class T, class A, class S>
+inline
+basic_fbstring<E, T, A, S> operator+(
+ E lhs,
const basic_fbstring<E, T, A, S>& rhs) {
basic_fbstring<E, T, A, S> result;
return result;
}
+// C++11 21.4.8.1/8
+template <typename E, class T, class A, class S>
+inline
+basic_fbstring<E, T, A, S> operator+(
+ E lhs,
+ basic_fbstring<E, T, A, S>&& rhs) {
+ //
+ if (rhs.capacity() > rhs.size()) {
+ // Good, at least we don't need to reallocate
+ return std::move(rhs.insert(rhs.begin(), lhs));
+ }
+ // Meh, no go. Forward to operator+(E, const&).
+ auto const& rhsC = rhs;
+ return lhs + rhsC;
+}
+
+// C++11 21.4.8.1/9
template <typename E, class T, class A, class S>
inline
basic_fbstring<E, T, A, S> operator+(
const basic_fbstring<E, T, A, S>& lhs,
- const typename basic_fbstring<E, T, A, S>::value_type* rhs) {
+ const E* rhs) {
typedef typename basic_fbstring<E, T, A, S>::size_type size_type;
typedef typename basic_fbstring<E, T, A, S>::traits_type traits_type;
return result;
}
+// C++11 21.4.8.1/10
+template <typename E, class T, class A, class S>
+inline
+basic_fbstring<E, T, A, S> operator+(
+ basic_fbstring<E, T, A, S>&& lhs,
+ const E* rhs) {
+ //
+ return std::move(lhs += rhs);
+}
+
+// C++11 21.4.8.1/11
template <typename E, class T, class A, class S>
inline
basic_fbstring<E, T, A, S> operator+(
const basic_fbstring<E, T, A, S>& lhs,
- typename basic_fbstring<E, T, A, S>::value_type rhs) {
+ E rhs) {
basic_fbstring<E, T, A, S> result;
result.reserve(lhs.size() + 1);
return result;
}
+// C++11 21.4.8.1/12
+template <typename E, class T, class A, class S>
+inline
+basic_fbstring<E, T, A, S> operator+(
+ basic_fbstring<E, T, A, S>&& lhs,
+ E rhs) {
+ //
+ return std::move(lhs += rhs);
+}
+
template <typename E, class T, class A, class S>
inline
bool operator==(const basic_fbstring<E, T, A, S>& lhs,
Num2String(test, test.find(str, random(0, test.size())));
}
+template <class String> void clause11_21_4_7_2_a1(String & test) {
+ String str = String(test).substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.find(str, random(0, test.size())));
+}
+
+template <class String> void clause11_21_4_7_2_a2(String & test) {
+ auto const& cTest = test;
+ String str = cTest.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.find(str, random(0, test.size())));
+}
+
template <class String> void clause11_21_4_7_2_b(String & test) {
auto from = random(0, test.size());
auto length = random(0, test.size() - from);
random(0, str.size())));
}
+template <class String> void clause11_21_4_7_2_b1(String & test) {
+ auto from = random(0, test.size());
+ auto length = random(0, test.size() - from);
+ String str = String(test).substr(from, length);
+ Num2String(test, test.find(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+}
+
+template <class String> void clause11_21_4_7_2_b2(String & test) {
+ auto from = random(0, test.size());
+ auto length = random(0, test.size() - from);
+ const auto& cTest = test;
+ String str = cTest.substr(from, length);
+ Num2String(test, test.find(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+}
+
template <class String> void clause11_21_4_7_2_c(String & test) {
String str = test.substr(
random(0, test.size()),
random(0, test.size())));
}
+template <class String> void clause11_21_4_7_2_c1(String & test) {
+ String str = String(test).substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.find(str.c_str(),
+ random(0, test.size())));
+}
+
+template <class String> void clause11_21_4_7_2_c2(String & test) {
+ const auto& cTest = test;
+ String str = cTest.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.find(str.c_str(),
+ random(0, test.size())));
+}
+
template <class String> void clause11_21_4_7_2_d(String & test) {
Num2String(test, test.find(
random('a', 'z'),
}
template <class String> void clause11_21_4_8_1_b(String & test) {
+ String s1;
+ randomString(&s1, maxString);
+ String s2;
+ randomString(&s2, maxString);
+ test = move(s1) + s2;
+}
+
+template <class String> void clause11_21_4_8_1_c(String & test) {
+ String s1;
+ randomString(&s1, maxString);
+ String s2;
+ randomString(&s2, maxString);
+ test = s1 + move(s2);
+}
+
+template <class String> void clause11_21_4_8_1_d(String & test) {
+ String s1;
+ randomString(&s1, maxString);
+ String s2;
+ randomString(&s2, maxString);
+ test = move(s1) + move(s2);
+}
+
+template <class String> void clause11_21_4_8_1_e(String & test) {
String s;
randomString(&s, maxString);
String s1;
test = s.c_str() + s1;
}
-template <class String> void clause11_21_4_8_1_c(String & test) {
+template <class String> void clause11_21_4_8_1_f(String & test) {
+ String s;
+ randomString(&s, maxString);
+ String s1;
+ randomString(&s1, maxString);
+ test = s.c_str() + move(s1);
+}
+
+template <class String> void clause11_21_4_8_1_g(String & test) {
String s;
randomString(&s, maxString);
test = typename String::value_type(random('a', 'z')) + s;
}
-template <class String> void clause11_21_4_8_1_d(String & test) {
+template <class String> void clause11_21_4_8_1_h(String & test) {
+ String s;
+ randomString(&s, maxString);
+ test = typename String::value_type(random('a', 'z')) + move(s);
+}
+
+template <class String> void clause11_21_4_8_1_i(String & test) {
String s;
randomString(&s, maxString);
String s1;
test = s + s1.c_str();
}
-template <class String> void clause11_21_4_8_1_e(String & test) {
+template <class String> void clause11_21_4_8_1_j(String & test) {
String s;
randomString(&s, maxString);
String s1;
randomString(&s1, maxString);
- test = s + s1.c_str();
+ test = move(s) + s1.c_str();
}
-template <class String> void clause11_21_4_8_1_f(String & test) {
+template <class String> void clause11_21_4_8_1_k(String & test) {
String s;
randomString(&s, maxString);
test = s + typename String::value_type(random('a', 'z'));
}
+template <class String> void clause11_21_4_8_1_l(String & test) {
+ String s;
+ randomString(&s, maxString);
+ String s1;
+ randomString(&s1, maxString);
+ test = move(s) + s1.c_str();
+}
+
// Numbering here is from C++11
template <class String> void clause11_21_4_8_9_a(String & test) {
basic_stringstream<typename String::value_type> stst(test.c_str());
TEST_CLAUSE(21_4_7_1);
TEST_CLAUSE(21_4_7_2_a);
+ TEST_CLAUSE(21_4_7_2_a1);
+ TEST_CLAUSE(21_4_7_2_a2);
TEST_CLAUSE(21_4_7_2_b);
+ TEST_CLAUSE(21_4_7_2_b1);
+ TEST_CLAUSE(21_4_7_2_b2);
TEST_CLAUSE(21_4_7_2_c);
+ TEST_CLAUSE(21_4_7_2_c1);
+ TEST_CLAUSE(21_4_7_2_c2);
TEST_CLAUSE(21_4_7_2_d);
TEST_CLAUSE(21_4_7_3_a);
TEST_CLAUSE(21_4_7_3_b);
TEST_CLAUSE(21_4_8_1_d);
TEST_CLAUSE(21_4_8_1_e);
TEST_CLAUSE(21_4_8_1_f);
+ TEST_CLAUSE(21_4_8_1_g);
+ TEST_CLAUSE(21_4_8_1_h);
+ TEST_CLAUSE(21_4_8_1_i);
+ TEST_CLAUSE(21_4_8_1_j);
+ TEST_CLAUSE(21_4_8_1_k);
+ TEST_CLAUSE(21_4_8_1_l);
TEST_CLAUSE(21_4_8_9_a);
}