9 #ifndef PQXX_INTERNAL_ENCODINGS_HXX
10 #define PQXX_INTERNAL_ENCODINGS_HXX
15 #include <string_view>
34 get_byte(std::string_view buffer, std::size_t offset) noexcept
36 assert(offset < std::size(buffer));
37 return static_cast<unsigned char>(buffer[offset]);
50 char const *encoding_name, std::string_view buffer, std::size_t start,
51 std::size_t count,
sl loc);
65 char const *encoding_name, std::string_view buffer, std::size_t start,
72 between_inc(
unsigned char value,
unsigned bottom,
unsigned top) noexcept
74 return value >= bottom and value <= top;
88 static constexpr
inline std::size_t
89 call(std::string_view, std::size_t start,
sl);
106 static_assert((... and ((NEEDLE & 0x80) == 0)));
108 auto const sz{std::size(haystack)};
132 if ((... or (data[here] == NEEDLE)))
157 call(std::string_view, std::size_t start,
sl) noexcept
181 call(std::string_view buffer, std::size_t start,
sl loc)
183 auto const byte1{
get_byte(buffer, start)};
189 else if (start + 2 <= std::size(buffer))
204 "variable-width two-byte encoding", buffer, start, loc);
218 call(std::string_view buffer, std::size_t start,
sl loc)
220 auto const byte1{
get_byte(buffer, start)};
223 auto const sz{std::size(buffer)};
227 if (start + 2 > sz) [[unlikely]]
230 auto const byte2{
get_byte(buffer, start + 1)};
233 if (byte2 == 0x7f) [[unlikely]]
239 if (start + 4 > sz) [[unlikely]]
263 call(std::string_view buffer, std::size_t start,
sl loc)
265 auto const byte1{
get_byte(buffer, start)};
282 if (start + 2 > std::size(buffer)) [[unlikely]]
301 template<
char... NEEDLE>
307 static_assert((... and (
static_cast<unsigned char>(NEEDLE) < 0x80)));
311 static_assert((... and not
between_inc(NEEDLE,
'A',
'Z')));
312 static_assert((... and not
between_inc(NEEDLE,
'a',
'z')));
318 "Tried to read text without knowing its encoding.", loc};
334 "Unexpected encoding group: {}.",
335 static_cast<std::underlying_type_t<encoding_group>
>(enc)),
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:304
PQXX_PURE PQXX_INLINE_ONLY constexpr PQXX_HOT unsigned char get_byte(std::string_view buffer, std::size_t offset) noexcept
Extract byte from buffer, return as unsigned char.
Definition: encodings.hxx:34
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_INLINE_COV constexpr PQXX_HOT 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:102
PQXX_PURE PQXX_INLINE_ONLY constexpr PQXX_HOT bool between_inc(unsigned char value, unsigned bottom, unsigned top) noexcept
Does value lie between bottom and top, inclusive?
Definition: encodings.hxx:72
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
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
std::source_location sl
Convenience alias for std::source_location. It's just too long.
Definition: types.hxx:38
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
PQXX_INLINE_ONLY PQXX_PURE static constexpr PQXX_HOT std::size_t call(std::string_view, std::size_t start, sl) noexcept
Definition: encodings.hxx:157
static constexpr PQXX_INLINE_ONLY std::size_t call(std::string_view buffer, std::size_t start, sl loc)
Definition: encodings.hxx:218
static constexpr PQXX_INLINE_ONLY std::size_t call(std::string_view buffer, std::size_t start, sl loc)
Definition: encodings.hxx:263
static constexpr PQXX_INLINE_ONLY std::size_t call(std::string_view buffer, std::size_t start, sl loc)
Definition: encodings.hxx:181
Wrapper struct template for "find next glyph" functions.
Definition: encodings.hxx:84
static constexpr std::size_t call(std::string_view, std::size_t start, sl)
Find the next glyph in buffer after position start.