C++17 is minimum requirement now. So replace pEp::string_view with std::string_view etc.
parent
2330093cff
commit
01941f70ad
|
@ -12,7 +12,7 @@ DEBUG=1
|
|||
PREFIX?=$(HOME)
|
||||
ENGINE_LIB_PATH=$(PREFIX)/lib
|
||||
ENGINE_INC_PATH=$(PREFIX)/include
|
||||
LANG_VERSION=c++14
|
||||
LANG_VERSION=c++17
|
||||
|
||||
CXXFLAGS+=-fPIC
|
||||
|
||||
|
|
26
src/nfc.cc
26
src/nfc.cc
|
@ -118,7 +118,7 @@ namespace
|
|||
};
|
||||
|
||||
|
||||
std::string escape(pEp::string_view s)
|
||||
std::string escape(std::string_view s)
|
||||
{
|
||||
std::string ret; ret.reserve(s.size() + 16 );
|
||||
for(char c : s)
|
||||
|
@ -136,7 +136,7 @@ namespace
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string escape(pEp::u16string_view s)
|
||||
std::string escape(std::u16string_view s)
|
||||
{
|
||||
std::string ret; ret.reserve(s.size() + 16 );
|
||||
for(char16_t c : s)
|
||||
|
@ -224,7 +224,7 @@ namespace
|
|||
|
||||
namespace pEp {
|
||||
|
||||
std::string escape_utf16(u16string_view s)
|
||||
std::string escape_utf16(std::u16string_view s)
|
||||
{
|
||||
return escape(s);
|
||||
}
|
||||
|
@ -435,11 +435,11 @@ std::basic_string<CharT> UTF<CharT>::generate(const std::u32string& u32)
|
|||
|
||||
|
||||
|
||||
illegal_utf::illegal_utf( string_view s, unsigned position, const std::string& reason)
|
||||
illegal_utf::illegal_utf( std::string_view s, unsigned position, const std::string& reason)
|
||||
: std::runtime_error( "Illegal UTF-8 string \"" + escape(s) + "\" at position " + std::to_string(position) + ": " + reason )
|
||||
{}
|
||||
|
||||
illegal_utf::illegal_utf( u16string_view s, unsigned position, const std::string& reason)
|
||||
illegal_utf::illegal_utf( std::u16string_view s, unsigned position, const std::string& reason)
|
||||
: std::runtime_error( "Illegal UTF-16 string \"" + escape(s) + "\" at position " + std::to_string(position) + ": " + reason )
|
||||
{}
|
||||
|
||||
|
@ -449,7 +449,7 @@ illegal_utf::illegal_utf( const std::string& msg )
|
|||
{}
|
||||
|
||||
|
||||
void assert_utf8(string_view s)
|
||||
void assert_utf8(std::string_view s)
|
||||
{
|
||||
const char* begin = s.data();
|
||||
const char* const end = s.data() + s.size();
|
||||
|
@ -470,7 +470,7 @@ void assert_utf8(string_view s)
|
|||
|
||||
// creates a NFD string from s
|
||||
template<class CharT>
|
||||
std::u32string UTF<CharT>::fromUtf_decompose(basic_string_view<CharT> s)
|
||||
std::u32string UTF<CharT>::fromUtf_decompose(std::basic_string_view<CharT> s)
|
||||
{
|
||||
std::u32string u32s;
|
||||
u32s.reserve( static_cast<std::size_t>(s.size()*1.25) );
|
||||
|
@ -555,7 +555,7 @@ std::u32string createNFC(std::u32string nfd)
|
|||
|
||||
|
||||
template<class CharT>
|
||||
IsNFC UTF<CharT>::isNFC_quick_check(basic_string_view<CharT> s)
|
||||
IsNFC UTF<CharT>::isNFC_quick_check(std::basic_string_view<CharT> s)
|
||||
{
|
||||
const CharT* begin = s.data();
|
||||
const CharT* const end = s.data() + s.size();
|
||||
|
@ -585,7 +585,7 @@ IsNFC UTF<CharT>::isNFC_quick_check(basic_string_view<CharT> s)
|
|||
|
||||
|
||||
template<class CharT>
|
||||
bool UTF<CharT>::isNFC(basic_string_view<CharT> s)
|
||||
bool UTF<CharT>::isNFC(std::basic_string_view<CharT> s)
|
||||
{
|
||||
switch( isNFC_quick_check(s) )
|
||||
{
|
||||
|
@ -618,7 +618,7 @@ try{
|
|||
|
||||
// s is ''moved'' to the return value if possible so no copy is done here.
|
||||
template<class CharT>
|
||||
std::basic_string<CharT> UTF<CharT>::toNFC(basic_string_view<CharT> s)
|
||||
std::basic_string<CharT> UTF<CharT>::toNFC(std::basic_string_view<CharT> s)
|
||||
{
|
||||
if(isNFC_quick_check(s)==IsNFC::Yes)
|
||||
return std::basic_string<CharT>{s};
|
||||
|
@ -628,7 +628,7 @@ std::basic_string<CharT> UTF<CharT>::toNFC(basic_string_view<CharT> s)
|
|||
|
||||
|
||||
template<>
|
||||
size_t UTF<char>::utf_length(u32string_view s)
|
||||
size_t UTF<char>::utf_length(std::u32string_view s)
|
||||
{
|
||||
size_t len = 0;
|
||||
for(const char32_t c : s)
|
||||
|
@ -659,7 +659,7 @@ size_t UTF<char>::utf_length(u32string_view s)
|
|||
|
||||
|
||||
template<>
|
||||
size_t UTF<char16_t>::utf_length(u32string_view s)
|
||||
size_t UTF<char16_t>::utf_length(std::u32string_view s)
|
||||
{
|
||||
size_t len = 0;
|
||||
for(const char32_t c : s)
|
||||
|
@ -685,7 +685,7 @@ size_t UTF<char16_t>::utf_length(u32string_view s)
|
|||
|
||||
// convenience function to avoid ::strdup(pEp::toNFC<char>(text).c_str());
|
||||
// and unecessary temporary std::string etc.
|
||||
char* strdup_NFC(string_view s)
|
||||
char* strdup_NFC(std::string_view s)
|
||||
{
|
||||
if(UTF8::isNFC_quick_check(s)==IsNFC::Yes)
|
||||
return ::new_string(s.data(), s.size());
|
||||
|
|
29
src/nfc.hh
29
src/nfc.hh
|
@ -4,7 +4,7 @@
|
|||
#ifndef LIBPEPDATATYPES_NFC_HH
|
||||
#define LIBPEPDATATYPES_NFC_HH
|
||||
|
||||
#include "string_view.hh" // to switch between std::string_view or boost::string_view.hh
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <iosfwd>
|
||||
|
@ -25,8 +25,8 @@ std::ostream& operator<<(std::ostream& o, IsNFC is_nfc);
|
|||
class illegal_utf : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
illegal_utf( string_view, unsigned position, const std::string& reason);
|
||||
illegal_utf(u16string_view, unsigned position, const std::string& reason);
|
||||
illegal_utf( std::string_view, unsigned position, const std::string& reason);
|
||||
illegal_utf(std::u16string_view, unsigned position, const std::string& reason);
|
||||
protected:
|
||||
explicit illegal_utf(const std::string& message);
|
||||
};
|
||||
|
@ -51,22 +51,22 @@ public:
|
|||
/// return No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe"
|
||||
/// might throw illegal_utf exception
|
||||
static
|
||||
IsNFC isNFC_quick_check(basic_string_view<CharT> s);
|
||||
IsNFC isNFC_quick_check(std::basic_string_view<CharT> s);
|
||||
|
||||
/// runs first quick check and a deep test if quick check returns "Maybe".
|
||||
static
|
||||
bool isNFC(basic_string_view<CharT> s);
|
||||
bool isNFC(std::basic_string_view<CharT> s);
|
||||
|
||||
/// returns true if the sequence is valid UTF-8
|
||||
bool isUtf(const CharT* begin, const CharT* end);
|
||||
|
||||
/// converts a C++ string (in UTF-8/-16) into NFC form
|
||||
static
|
||||
std::basic_string<CharT> toNFC(basic_string_view<CharT> s);
|
||||
std::basic_string<CharT> toNFC(std::basic_string_view<CharT> s);
|
||||
|
||||
/// calculates the number of "code units" in the target Unicode Transfer Format.
|
||||
static
|
||||
size_t utf_length(u32string_view s);
|
||||
size_t utf_length(std::u32string_view s);
|
||||
|
||||
/// generates a whole u32string at once
|
||||
static
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
|
||||
/// creates an NFD u32string from UTF-8/UTF-16 input string s
|
||||
static
|
||||
std::u32string fromUtf_decompose(basic_string_view<CharT> s);
|
||||
std::u32string fromUtf_decompose(std::basic_string_view<CharT> s);
|
||||
};
|
||||
|
||||
using UTF8 = UTF<char>;
|
||||
|
@ -82,7 +82,7 @@ using UTF16 = UTF<char16_t>;
|
|||
|
||||
|
||||
// throws illegal_utf8 exception if s is not valid UTF-8
|
||||
void assert_utf8(string_view s);
|
||||
void assert_utf8(std::string_view s);
|
||||
|
||||
|
||||
// convert NFD to NFC
|
||||
|
@ -92,11 +92,11 @@ std::u32string createNFC(std::u32string nfd_string);
|
|||
// return No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe"
|
||||
// might throw illegal_utf exception
|
||||
template<class CharT>
|
||||
IsNFC isNFC_quick_check(basic_string_view<CharT> s);
|
||||
IsNFC isNFC_quick_check(std::basic_string_view<CharT> s);
|
||||
|
||||
// runs first quick check and a deep test if quick check returns "Maybe".
|
||||
template<class CharT>
|
||||
bool isNFC(basic_string_view<CharT> s);
|
||||
bool isNFC(std::basic_string_view<CharT> s);
|
||||
|
||||
// returns true if the sequence is valid UTF-8
|
||||
bool isUtf8(const char* begin, const char* end);
|
||||
|
@ -104,15 +104,16 @@ bool isUtf8(const char* begin, const char* end);
|
|||
// converts a C++ string (in UTF-8) into NFC form
|
||||
// s is ''moved'' to the return value if possible so no copy is done here.
|
||||
template<class CharT>
|
||||
std::basic_string<CharT> toNFC(basic_string_view<CharT> s);
|
||||
std::basic_string<CharT> toNFC(std::basic_string_view<CharT> s);
|
||||
*/
|
||||
|
||||
// creates a UTF-8-encoded NFC string from s
|
||||
std::string toNFC_8(u16string_view s);
|
||||
std::string toNFC_8(std::u16string_view s);
|
||||
|
||||
// convenience functions to avoid ::strdup(pEp::toNFC<char>(text).c_str());
|
||||
// and unecessary temporary std::string etc.
|
||||
char* strdup_NFC(string_view s);
|
||||
char* strdup_NFC(std::string_view s);
|
||||
|
||||
pEp_identity *identity_dup_NFC(const ::pEp_identity* value);
|
||||
::identity_list* identity_list_dup_NFC(const ::identity_list* value);
|
||||
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// This file is under GNU General Public License 3.0
|
||||
// see LICENSE.txt
|
||||
|
||||
#ifndef PEP_DATATYPES_STRING_VIEW_HH
|
||||
#define PEP_DATATYPES_STRING_VIEW_HH
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace pEp
|
||||
{
|
||||
template<class CharT>
|
||||
using basic_string_view = std::basic_string_view<CharT>;
|
||||
|
||||
typedef std::string_view string_view;
|
||||
typedef std::u16string_view u16string_view;
|
||||
typedef std::u32string_view u32string_view;
|
||||
}
|
||||
|
||||
namespace pEp
|
||||
{
|
||||
constexpr
|
||||
string_view operator""_sv(const char* s, size_t sz) noexcept
|
||||
{
|
||||
return string_view(s,sz);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // PEP_DATATYPES_STRING_VIEW_HH
|
Loading…
Reference in New Issue