|
@ -8,6 +8,7 @@ |
|
|
#include <string> |
|
|
#include <string> |
|
|
#include <stdexcept> |
|
|
#include <stdexcept> |
|
|
#include <iosfwd> |
|
|
#include <iosfwd> |
|
|
|
|
|
#include <boost/operators.hpp> |
|
|
#include <pEp/identity_list.h> |
|
|
#include <pEp/identity_list.h> |
|
|
|
|
|
|
|
|
namespace pEp { |
|
|
namespace pEp { |
|
@ -82,7 +83,7 @@ public: |
|
|
|
|
|
|
|
|
/// class holding a NFC-conform Unicode string.
|
|
|
/// class holding a NFC-conform Unicode string.
|
|
|
/// content is mostly read-only, because arbitrary modifications might destroy NFC conformacy.
|
|
|
/// content is mostly read-only, because arbitrary modifications might destroy NFC conformacy.
|
|
|
class nfc_string |
|
|
class nfc_string : public boost::totally_ordered2<nfc_string, std::basic_string_view<CharT>> |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
typedef std::basic_string<CharT> String; |
|
|
typedef std::basic_string<CharT> String; |
|
@ -195,10 +196,10 @@ public: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// stolen from C++20
|
|
|
/// stolen from C++20
|
|
|
bool starts_with(StringView s) const; |
|
|
bool starts_with(StringView s) const noexcept; |
|
|
|
|
|
|
|
|
/// stolen from C++20
|
|
|
/// stolen from C++20
|
|
|
bool ends_with(StringView s) const; |
|
|
bool ends_with(StringView s) const noexcept; |
|
|
|
|
|
|
|
|
/// delegates all 5 find() overloads to s
|
|
|
/// delegates all 5 find() overloads to s
|
|
|
template<typename... Args> |
|
|
template<typename... Args> |
|
@ -210,8 +211,6 @@ public: |
|
|
/// might throw illegal_utf, if a multi-char sequence is clipped.
|
|
|
/// might throw illegal_utf, if a multi-char sequence is clipped.
|
|
|
nfc_string substr(std::size_t pos=0, std::size_t count=npos) const; |
|
|
nfc_string substr(std::size_t pos=0, std::size_t count=npos) const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
std::basic_string<CharT> s; |
|
|
std::basic_string<CharT> s; |
|
|
|
|
|
|
|
@ -249,10 +248,25 @@ inline |
|
|
typename |
|
|
typename |
|
|
UTF<CharT>::nfc_string operator+(const T& left, const typename UTF<CharT>::nfc_string& right) |
|
|
UTF<CharT>::nfc_string operator+(const T& left, const typename UTF<CharT>::nfc_string& right) |
|
|
{ |
|
|
{ |
|
|
UTF<CharT> left_s{left}; |
|
|
typename UTF<CharT>::nfc_string left_s{left}; |
|
|
return left_s+=right; |
|
|
return left_s+=right; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<class CharT> |
|
|
|
|
|
inline |
|
|
|
|
|
bool operator<(const typename UTF<CharT>::nfc_string& left, std::basic_string_view<CharT> right) |
|
|
|
|
|
{ |
|
|
|
|
|
return left<right; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template<class CharT> |
|
|
|
|
|
inline |
|
|
|
|
|
bool operator==(const typename UTF<CharT>::nfc_string& left, std::basic_string_view<CharT> right) |
|
|
|
|
|
{ |
|
|
|
|
|
return left==right; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// convenient alias names:
|
|
|
/// convenient alias names:
|
|
|
using UTF8 = UTF<char>; |
|
|
using UTF8 = UTF<char>; |
|
|
using UTF16 = UTF<char16_t>; |
|
|
using UTF16 = UTF<char16_t>; |
|
|