📄 flex_string_shell.h
字号:
data() + pos + n, s); return n; } void swap(flex_string& rhs) { Storage& srhs = rhs; this->Storage::swap(srhs); } // 21.3.6 string operations: const value_type* c_str() const { return Storage::c_str(); } const value_type* data() const { return Storage::data(); } allocator_type get_allocator() const { return Storage::get_allocator(); } size_type find(const flex_string& str, size_type pos = 0) const { return find(str.data(), pos, str.length()); } size_type find (const value_type* s, size_type pos, size_type n) const { for (; pos <= size(); ++pos) { if (traits_type::compare(data() + pos, s, n) == 0) { return pos; } } return npos; } size_type find (const value_type* s, size_type pos = 0) const { return find(s, pos, traits_type::length(s)); } size_type find (value_type c, size_type pos = 0) const { return find(&c, pos, 1); } size_type rfind(const flex_string& str, size_type pos = npos) const { return rfind(str.data(), pos, str.length()); } size_type rfind(const value_type* s, size_type pos, size_type n) const { if (n > length()) return npos; pos = Min(pos, length() - n); if (n == 0) return pos; const_iterator i(begin() + pos); for (; ; --i) { if (traits_type::eq(*i, *s) && traits_type::compare(&*i, s, n) == 0) { return i - begin(); } if (i == begin()) break; } return npos; } size_type rfind(const value_type* s, size_type pos = npos) const { return rfind(s, pos, traits_type::length(s)); } size_type rfind(value_type c, size_type pos = npos) const { return rfind(&c, pos, 1); } size_type find_first_of(const flex_string& str, size_type pos = 0) const { return find_first_of(str.data(), pos, str.length()); } size_type find_first_of(const value_type* s, size_type pos, size_type n) const { if (pos > length() || n == 0) return npos; const_iterator i(begin() + pos), finish(end()); for (; i != finish; ++i) { if (traits_type::find(s, n, *i) != 0) { return i - begin(); } } return npos; } size_type find_first_of(const value_type* s, size_type pos = 0) const { return find_first_of(s, pos, traits_type::length(s)); } size_type find_first_of(value_type c, size_type pos = 0) const { return find_first_of(&c, pos, 1); } size_type find_last_of (const flex_string& str, size_type pos = npos) const { return find_last_of(str.data(), pos, str.length()); } size_type find_last_of (const value_type* s, size_type pos, size_type n) const { if (!empty() && n > 0) { pos = Min(pos, length() - 1); const_iterator i(begin() + pos); for (;; --i) { if (traits_type::find(s, n, *i) != 0) { return i - begin(); } if (i == begin()) break; } } return npos; } size_type find_last_of (const value_type* s, size_type pos = npos) const { return find_last_of(s, pos, traits_type::length(s)); } size_type find_last_of (value_type c, size_type pos = npos) const { return find_last_of(&c, pos, 1); } size_type find_first_not_of(const flex_string& str, size_type pos = 0) const { return find_first_not_of(str.data(), pos, str.size()); } size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const { if (pos < length()) { const_iterator i(begin() + pos), finish(end()); for (; i != finish; ++i) { if (traits_type::find(s, n, *i) == 0) { return i - begin(); } } } return npos; } size_type find_first_not_of(const value_type* s, size_type pos = 0) const { return find_first_not_of(s, pos, traits_type::length(s)); } size_type find_first_not_of(value_type c, size_type pos = 0) const { return find_first_not_of(&c, pos, 1); } size_type find_last_not_of(const flex_string& str, size_type pos = npos) const { return find_last_not_of(str.data(), pos, str.length()); } size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const { if (!this->empty()) { pos = Min(pos, size() - 1); const_iterator i(begin() + pos); for (;; --i) { if (traits_type::find(s, n, *i) == 0) { return i - begin(); } if (i == begin()) break; } } return npos; } size_type find_last_not_of(const value_type* s, size_type pos = npos) const { return find_last_not_of(s, pos, traits_type::length(s)); } size_type find_last_not_of (value_type c, size_type pos = npos) const { return find_last_not_of(&c, pos, 1); } flex_string substr(size_type pos = 0, size_type n = npos) const { Enforce(pos <= size(), static_cast<std::out_of_range*>(0), ""); return flex_string(data() + pos, Min(n, size() - pos)); } int compare(const flex_string& str) const { // FIX due to Goncalo N M de Carvalho July 18, 2005 return compare(0, size(), str); } int compare(size_type pos1, size_type n1, const flex_string& str) const { return compare(pos1, n1, str.data(), str.size()); } // FIX to compare: added the TC // (http://www.comeaucomputing.com/iso/lwg-defects.html number 5) // Thanks to Caleb Epstein for the fix int compare(size_type pos1, size_type n1, const value_type* s) const { return compare(pos1, n1, s, traits_type::length(s)); } int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const { Enforce(pos1 <= size(), static_cast<std::out_of_range*>(0), ""); Procust(n1, size() - pos1); const int r = traits_type::compare(data(), s, Min(n1, n2)); return r != 0 ? r : n1 > n2 ? 1 : n1 < n2 ? -1 : 0; } int compare(size_type pos1, size_type n1, const flex_string& str, size_type pos2, size_type n2) const { Enforce(pos2 <= str.size(), static_cast<std::out_of_range*>(0), ""); return compare(pos1, n1, str.data() + pos2, Min(n2, str.size() - pos2)); } int compare(const value_type* s) const { return traits_type::compare(data(), s, Max(length(),traits_type::length(s))); }};// non-member functionstemplate <typename E, class T, class A, class S>flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs, const flex_string<E, T, A, S>& rhs){ flex_string<E, T, A, S> result; result.reserve(lhs.size() + rhs.size()); result.append(lhs).append(rhs); return result;}template <typename E, class T, class A, class S>flex_string<E, T, A, S> operator+(const typename flex_string<E, T, A, S>::value_type* lhs, const flex_string<E, T, A, S>& rhs){ flex_string<E, T, A, S> result; const typename flex_string<E, T, A, S>::size_type len = flex_string<E, T, A, S>::traits_type::length(lhs); result.reserve(len + rhs.size()); result.append(lhs, len).append(rhs); return result;}template <typename E, class T, class A, class S>flex_string<E, T, A, S> operator+( typename flex_string<E, T, A, S>::value_type lhs, const flex_string<E, T, A, S>& rhs){ flex_string<E, T, A, S> result; result.reserve(1 + rhs.size()); result.push_back(lhs); result.append(rhs); return result;}template <typename E, class T, class A, class S>flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs, const typename flex_string<E, T, A, S>::value_type* rhs){ typedef typename flex_string<E, T, A, S>::size_type size_type; typedef typename flex_string<E, T, A, S>::traits_type traits_type; flex_string<E, T, A, S> result; const size_type len = traits_type::length(rhs); result.reserve(lhs.size() + len); result.append(lhs).append(rhs, len); return result;}template <typename E, class T, class A, class S>flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs, typename flex_string<E, T, A, S>::value_type rhs){ flex_string<E, T, A, S> result; result.reserve(lhs.size() + 1); result.append(lhs); result.push_back(rhs); return result;}template <typename E, class T, class A, class S>bool operator==(const flex_string<E, T, A, S>& lhs, const flex_string<E, T, A, S>& rhs){ return lhs.compare(rhs) == 0; }template <typename E, class T, class A, class S>bool operator==(const typename flex_string<E, T, A, S>::value_type* lhs, const flex_string<E, T, A, S>& rhs){ return rhs == lhs; }template <typename E, class T, class A, class S>bool operator==(const flex_string<E, T, A, S>& lhs, const typename flex_string<E, T, A, S>::value_type* rhs){ return lhs.compare(rhs) == 0; }template <typename E, class T, class A, class S>bool operator!=(const flex_string<E, T, A, S>& lhs, const flex_string<E, T, A, S>& rhs){ return !(lhs == rhs); }template <typename E, class T, class A, class S>bool operator!=(const typename flex_string<E, T, A, S>::value_type* lhs, const flex_string<E, T, A, S>& rhs){ return !(lhs == rhs); }template <typename E, class T, class A, class S>bool operator!=(const flex_string<E, T, A, S>& lhs, const typename flex_string<E, T, A, S>::value_type* rhs){ return !(lhs == rhs); }template <typename E, class T, class A, class S>bool operator<(const flex_string<E, T, A, S>& lhs, const flex_string<E, T, A, S>& rhs){ return lhs.compare(rhs) < 0; }template <typename E, class T, class A, class S>bool operator<(const flex_string<E, T, A, S>& lhs, const typename flex_string<E, T, A, S>::value_type* rhs){ return lhs.compare(rhs) < 0; }template <typename E, class T, class A, class S>bool operator<(const typename flex_string<E, T, A, S>::value_type* lhs, const flex_string<E, T, A, S>& rhs){ return rhs.compare(lhs) > 0; }template <typename E, class T, class A, class S>bool operator>(const flex_string<E, T, A, S>& lhs, const flex_string<E, T, A, S>& rhs){ return rhs < lhs; }template <typename E, class T, class A, class S>bool operator>(const flex_string<E, T, A, S>& lhs, const typename flex_string<E, T, A, S>::value_type* rhs){ return rhs < lhs; }template <typename E, class T, class A, class S>bool operator>(const typename flex_string<E, T, A, S>::value_type* lhs, const flex_string<E, T, A, S>& rhs){ return rhs < lhs; }template <typename E, class T, class A, class S>bool operator<=(const flex_string<E, T, A, S>& lhs, const flex_string<E, T, A, S>& rhs){ return !(rhs < lhs); }template <typename E, class T, class A, class S>bool operator<=(const flex_string<E, T, A, S>& lhs, const typename flex_string<E, T, A, S>::value_type* rhs){ return !(rhs < lhs); }template <typename E, class T, class A, class S>bool operator<=(const typename flex_string<E, T, A, S>::value_type* lhs, const flex_string<E, T, A, S>& rhs){ return !(rhs < lhs); }template <typename E, class T, class A, class S>bool operator>=(const flex_string<E, T, A, S>& lhs, const flex_string<E, T, A, S>& rhs){ return !(lhs < rhs); }template <typename E, class T, class A, class S>bool operator>=(const flex_string<E, T, A, S>& lhs, const typename flex_string<E, T, A, S>::value_type* rhs){ return !(lhs < rhs); }template <typename E, class T, class A, class S>bool operator>=(const typename flex_string<E, T, A, S>::value_type* lhs, const flex_string<E, T, A, S>& rhs){ return !(lhs < rhs); }// subclause 21.3.7.8://void swap(flex_string<E, T, A, S>& lhs, flex_string<E, T, A, S>& rhs); // to dotemplate <typename E, class T, class A, class S>std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>&operator>>( std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>& is, flex_string<E, T, A, S>& str);template <typename E, class T, class A, class S>std::basic_ostream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>&operator<<( std::basic_ostream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>& os, const flex_string<E, T, A, S>& str){ return os << str.c_str(); }template <typename E, class T, class A, class S>std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>&getline( std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>& is, flex_string<E, T, A, S>& str, typename flex_string<E, T, A, S>::value_type delim);template <typename E, class T, class A, class S>std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>&getline( std::basic_istream<typename flex_string<E, T, A, S>::value_type, typename flex_string<E, T, A, S>::traits_type>& is, flex_string<E, T, A, S>& str);template <typename E1, class T, class A, class S>const typename flex_string<E1, T, A, S>::size_typeflex_string<E1, T, A, S>::npos = static_cast<typename flex_string<E1, T, A, S>::size_type>(-1);#endif // FLEX_STRING_SHELL_INC_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -