9#ifndef PQXX_H_ENCODINGS
10#define PQXX_H_ENCODINGS
16#include "pqxx/internal/concat.hxx"
17#include "pqxx/internal/encoding_group.hxx"
22PQXX_DECLARE_ENUM_CONVERSION(pqxx::internal::encoding_group);
32PQXX_LIBEXPORT encoding_group
enc_group(
int );
54 std::size_t
here = 0
u)
57 auto const data{std::data(
haystack)};
61 PQXX_ASSUME(next >
here);
86template<
typename CALLABLE>
95 PQXX_ASSUME(next >
here);
104constexpr PQXX_PURE
unsigned char
116 s <<
"Invalid byte sequence for encoding " <<
encoding_name <<
" at byte "
117 <<
start <<
": " << std::hex << std::setw(2) << std::setfill(
'0');
118 for (std::size_t
i{0};
i < count; ++
i)
129constexpr PQXX_PURE
bool
146 PQXX_PURE
static std::size_t
160template<encoding_group
ENC,
char...
NEEDLE>
161PQXX_PURE
inline std::size_t
166 static_assert((...
and ((
NEEDLE & 0x80) == 0)));
169 auto const data{std::data(
haystack)};
175 PQXX_ASSUME(next >
here);
209template<encoding_group
ENC,
char...
NEEDLE>
215 static_assert((...
and ((
NEEDLE >> 7) == 0)));
218 auto const data{std::data(
haystack)};
225 PQXX_ASSUME(next >
here);
234 static PQXX_PURE
constexpr std::size_t
239 PQXX_UNLIKELY
return std::string::npos;
249 static PQXX_PURE std::size_t
253 PQXX_UNLIKELY
return std::string::npos;
289 static PQXX_PURE std::size_t
293 return std::string::npos;
320 static PQXX_PURE std::size_t
324 return std::string::npos;
373 static PQXX_PURE std::size_t
377 PQXX_UNLIKELY
return std::string::npos;
400 static PQXX_PURE std::size_t
405 return std::string::npos;
444 static PQXX_PURE std::size_t
448 PQXX_UNLIKELY
return std::string::npos;
489 static PQXX_PURE std::size_t
493 PQXX_UNLIKELY
return std::string::npos;
536 static PQXX_PURE std::size_t
540 PQXX_UNLIKELY
return std::string::npos;
573 static PQXX_PURE std::size_t
577 PQXX_UNLIKELY
return std::string::npos;
630 static PQXX_PURE std::size_t
634 return std::string::npos;
667 static PQXX_PURE std::size_t
671 PQXX_UNLIKELY
return std::string::npos;
710 static PQXX_PURE std::size_t
714 PQXX_UNLIKELY
return std::string::npos;
784constexpr inline encoding_group
789 case encoding_group::MONOBYTE:
790 case encoding_group::EUC_CN:
791 case encoding_group::EUC_JP:
792 case encoding_group::EUC_KR:
793 case encoding_group::EUC_TW:
794 case encoding_group::MULE_INTERNAL:
795 case encoding_group::UTF8:
799 return encoding_group::MONOBYTE;
801 default: PQXX_UNLIKELY
return enc;
820 case encoding_group::MONOBYTE:
821 return pqxx::internal::find_ascii_char<
822 encoding_group::MONOBYTE,
NEEDLE...>;
823 case encoding_group::BIG5:
824 return pqxx::internal::find_ascii_char<encoding_group::BIG5,
NEEDLE...>;
825 case encoding_group::GB18030:
826 return pqxx::internal::find_ascii_char<encoding_group::GB18030,
NEEDLE...>;
827 case encoding_group::GBK:
828 return pqxx::internal::find_ascii_char<encoding_group::GBK,
NEEDLE...>;
829 case encoding_group::JOHAB:
830 return pqxx::internal::find_ascii_char<encoding_group::JOHAB,
NEEDLE...>;
831 case encoding_group::SJIS:
832 return pqxx::internal::find_ascii_char<encoding_group::SJIS,
NEEDLE...>;
833 case encoding_group::UHC:
834 return pqxx::internal::find_ascii_char<encoding_group::UHC,
NEEDLE...>;
838 "Unexpected encoding group: ",
as_if,
" (mapped from ",
enc,
").")};
854 case encoding_group::MONOBYTE:
856 encoding_group::MONOBYTE,
NEEDLE...>;
857 case encoding_group::BIG5:
859 case encoding_group::GB18030:
861 encoding_group::GB18030,
NEEDLE...>;
862 case encoding_group::GBK:
864 case encoding_group::JOHAB:
866 case encoding_group::SJIS:
868 case encoding_group::UHC:
873 "Unexpected encoding group: ",
as_if,
" (mapped from ",
enc,
").")};
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition except.hxx:266
Internal error in libpqxx library.
Definition except.hxx:242
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
std::string concat(TYPE... item)
Efficiently combine a bunch of items into one big string.
Definition concat.hxx:31
PQXX_PURE constexpr char_finder_func * get_char_finder(encoding_group enc)
Look up a character search function for an encoding group.
Definition encodings.hxx:815
PQXX_PURE std::size_t find_s_ascii_char(std::string_view haystack, std::size_t here)
Find first of NEEDLE ASCII chars in haystack.
Definition encodings.hxx:211
PQXX_PURE char const * name_encoding(int encoding_id)
Return PostgreSQL's name for encoding enum value.
PQXX_PURE constexpr char_finder_func * get_s_char_finder(encoding_group enc)
Look up a "sentry" character search function for an encoding group.
Definition encodings.hxx:849
pqxx::internal::encoding_group enc_group(std::string_view encoding_name)
Convert libpq encoding name to its libpqxx encoding group.
Definition encodings.cxx:35
void for_glyphs(encoding_group enc, CALLABLE callback, char const buffer[], std::size_t buffer_len, std::size_t start=0)
Iterate over the glyphs in a buffer.
Definition encodings.hxx:87
PQXX_LIBEXPORT glyph_scanner_func * get_glyph_scanner(encoding_group)
Look up the glyph scanner function for a given encoding group.
std::size_t(std::string_view haystack, std::size_t start) char_finder_func
Function type: "find first occurrence of specific any of ASCII characters.".
Definition encoding_group.hxx:70
std::size_t find_char(glyph_scanner_func *scanner, std::string_view haystack, std::size_t here=0u)
Find any of the ASCII characters NEEDLE in haystack.
Definition encodings.hxx:52
constexpr encoding_group map_ascii_search_group(encoding_group enc) noexcept
Just for searching an ASCII character, what encoding can we use here?
Definition encodings.hxx:785
std::size_t(char const buffer[], std::size_t buffer_len, std::size_t start) glyph_scanner_func
Function type: "find the end of the current glyph.".
Definition encoding_group.hxx:52
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition strconv.hxx:558
Wrapper struct template for "find next glyph" functions.
Definition encodings.hxx:143
static PQXX_PURE std::size_t call(char const buffer[], std::size_t buffer_len, std::size_t start)
Find the next glyph in buffer after position start.