Browse Source

make nfc_string complete...

master
roker 4 years ago
parent
commit
d8bcff63f3
  1. 24
      src/nfc.cc
  2. 24
      src/nfc.hh

24
src/nfc.cc

@ -684,10 +684,32 @@ size_t UTF<char16_t>::utf_length(std::u32string_view s)
template<class CharT>
UTF<CharT>::nfc_string::nfc_string(std::basic_string_view<CharT> src)
UTF<CharT>::nfc_string::nfc_string(StringView src)
: s{ UTF<CharT>::toNFC(src) }
{}
template<class CharT>
UTF<CharT>::nfc_string::nfc_string(String&& src)
: s{ isNFC_quick_check(src)==IsNFC::Yes ? std::move(src) : toNFC(src) }
{}
template<class CharT>
typename
UTF<CharT>::nfc_string& UTF<CharT>::nfc_string::assign(StringView src)
{
s = toNFC(src);
return *this;
}
template<class CharT>
typename
UTF<CharT>::nfc_string& UTF<CharT>::nfc_string::assign(String&& src)
{
s = (isNFC_quick_check(src)==IsNFC::Yes) ? std::move(src) : toNFC(src);
return *this;
}
// convenience function to avoid ::strdup(pEp::toNFC<char>(text).c_str());
// and unecessary temporary std::string etc.

24
src/nfc.hh

@ -82,7 +82,8 @@ public:
class nfc_string
{
public:
typedef std::basic_string<CharT> String;
typedef std::basic_string<CharT> String;
typedef std::basic_string_view<CharT> StringView;
/// only const_reference is supported.
typedef typename String::const_reference const_reference;
@ -92,13 +93,17 @@ public:
typedef typename String::const_iterator const_iterator;
explicit nfc_string(std::basic_string_view<CharT> src);
explicit nfc_string(std::basic_string <CharT>&& src);
explicit nfc_string(StringView src);
explicit nfc_string(String && src);
/// construct from a NUL-terminated src
explicit nfc_string(const CharT* src);
explicit nfc_string(const CharT* src)
: nfc_string{ StringView{src} }
{}
nfc_string(const CharT* src, size_t length);
nfc_string(const CharT* src, size_t length)
: nfc_string{ StringView{src, length} }
{}
nfc_string(const nfc_string& src) = default;
nfc_string( nfc_string&& src) = default;
@ -106,8 +111,8 @@ public:
nfc_string& operator=(const nfc_string& src) = default;
nfc_string& operator=( nfc_string&& src) = default;
nfc_string& assign(String&& src);
nfc_string& assign(std::basic_string_view<CharT> src);
nfc_string& assign(StringView src);
nfc_string& assign(String && src);
/// read-only: shares representation
@ -121,6 +126,11 @@ public:
std::size_t size() const noexcept { return s.size(); }
bool empty() const noexcept { return s.empty(); }
const_iterator begin() const noexcept { return s.cbegin(); }
const_iterator cbegin() const noexcept { return s.cbegin(); } /// r/o access only
const_iterator end() const noexcept { return s.cend(); }
const_iterator cend() const noexcept { return s.cend(); } /// r/o access only
private:
std::basic_string<CharT> s;
};

Loading…
Cancel
Save