9 #ifndef PQXX_INTERNAL_ENCODINGS_HXX
10 #define PQXX_INTERNAL_ENCODINGS_HXX
15 #include <string_view>
40 get_byte(std::string_view buffer, std::size_t offset) noexcept
42 assert(offset < std::size(buffer));
43 return static_cast<unsigned char>(buffer[offset]);
56 char const *encoding_name, std::string_view buffer, std::size_t start,
57 std::size_t count,
sl loc);
71 char const *encoding_name, std::string_view buffer, std::size_t start,
78 between_inc(
unsigned char value,
unsigned bottom,
unsigned top) noexcept
80 return value >= bottom and value <= top;
94 static constexpr
inline std::size_t
95 call(std::string_view, std::size_t start,
sl);
112 static_assert((... and ((NEEDLE & 0x80) == 0)));
114 auto const sz{std::size(haystack)};
115 auto const data{std::data(haystack)};
138 if ((... or (data[here] == NEEDLE)))
163 call(std::string_view, std::size_t start,
sl) noexcept
187 call(std::string_view buffer, std::size_t start,
sl loc)
189 auto const byte1{
get_byte(buffer, start)};
195 else if (start + 2 <= std::size(buffer))
210 "variable-width two-byte encoding", buffer, start, loc);
224 call(std::string_view buffer, std::size_t start,
sl loc)
226 auto const byte1{
get_byte(buffer, start)};
229 auto const sz{std::size(buffer)};
233 if (start + 2 > sz) [[unlikely]]
236 auto const byte2{
get_byte(buffer, start + 1)};
239 if (byte2 == 0x7f) [[unlikely]]
245 if (start + 4 > sz) [[unlikely]]
269 call(std::string_view buffer, std::size_t start,
sl loc)
271 auto const byte1{
get_byte(buffer, start)};
288 if (start + 2 > std::size(buffer)) [[unlikely]]
307 template<
char... NEEDLE>
313 static_assert((... and (
static_cast<unsigned char>(NEEDLE) < 0x80)));
317 static_assert((... and not
between_inc(NEEDLE,
'A',
'Z')));
318 static_assert((... and not
between_inc(NEEDLE,
'a',
'z')));
324 "Tried to read text without knowing its encoding.", loc};
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:599
Internal error in libpqxx library.
Definition: except.hxx:558
Private namespace for libpqxx's internal use; do not access.
Definition: connection.cxx:333
void throw_for_truncated_character(char const *encoding, std::string_view buffer, std::size_t start, sl loc)
Throw an error reporting that the input is truncated in mid-character.
Definition: encodings.cxx:273
PQXX_PURE PQXX_RETURNS_NONNULL constexpr PQXX_INLINE_COV char_finder_func * get_char_finder(encoding_group enc, sl loc)
Look up a character search function for an encoding group.
Definition: encodings.hxx:310
void throw_for_encoding_error(char const *encoding, std::string_view buffer, std::size_t start, std::size_t count, sl loc)
Throw an error reporting that input text is not properly encoded.
Definition: encodings.cxx:261
PQXX_PURE constexpr PQXX_INLINE_ONLY bool between_inc(unsigned char value, unsigned bottom, unsigned top) noexcept
Does value lie between bottom and top, inclusive?
Definition: encodings.hxx:78
char const * name_encoding(int encoding_id) noexcept
Return PostgreSQL's name for encoding enum value.
Definition: encodings.cxx:234
constexpr encoding_group enc_group(std::string_view encoding_name, sl loc)
Look up encoding group for an encoding by name.
Definition: encodings.cxx:56
constexpr PQXX_INLINE_COV std::size_t find_ascii_char(std::string_view haystack, std::size_t here, sl loc)
Find any of the ASCII characters in NEEDLE in haystack.
Definition: encodings.hxx:108
PQXX_PURE constexpr PQXX_INLINE_ONLY unsigned char get_byte(std::string_view buffer, std::size_t offset) noexcept
Extract byte from buffer, return as unsigned char.
Definition: encodings.hxx:40
std::size_t(std::string_view haystack, std::size_t start, sl) char_finder_func
Function type: "find first occurrence of any of these ASCII characters.".
Definition: encoding_group.hxx:110
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
std::source_location sl
Convenience alias for std::source_location. It's just too long.
Definition: types.hxx:38
PQXX_LIBEXPORT std::string to_string(field_ref const &value, ctx)
Convert a field_ref to a string.
Definition: field.hxx:891
encoding_group
Definition: encoding_group.hxx:40
@ two_tier
Low byte is ASCII, high byte starts a 2-byte character.
@ sjis
Non-ASCII-safe: Japanese JIS and Shift JIS.
@ unknown
Default: indeterminate encoding. All we know is it supports ASCII.
@ ascii_safe
"ASCII-safe" encodings.
@ gb18030
Non-ASCII-safe: GB18030 for Chinese (Traditional & Simplified).
format
Format code: is data text or binary?
Definition: types.hxx:121
#define PQXX_DECLARE_ENUM_CONVERSION(ENUM)
Macro: Define a string conversion for an enum type.
Definition: strconv.hxx:617
PQXX_INLINE_ONLY static constexpr PQXX_PURE std::size_t call(std::string_view, std::size_t start, sl) noexcept
Definition: encodings.hxx:163
static constexpr PQXX_INLINE_ONLY std::size_t call(std::string_view buffer, std::size_t start, sl loc)
Definition: encodings.hxx:224
static constexpr PQXX_INLINE_ONLY std::size_t call(std::string_view buffer, std::size_t start, sl loc)
Definition: encodings.hxx:269
static constexpr PQXX_INLINE_ONLY std::size_t call(std::string_view buffer, std::size_t start, sl loc)
Definition: encodings.hxx:187
Wrapper struct template for "find next glyph" functions.
Definition: encodings.hxx:90
static constexpr std::size_t call(std::string_view, std::size_t start, sl)
Find the next glyph in buffer after position start.