1/*-----------------------------------------------------------------------
4 * Portions Copyright (c) 1999-2025, PostgreSQL Global Development Group
6 * src/include/utils/ascii.h
8 *-----------------------------------------------------------------------
19 * Verify a chunk of bytes for valid ASCII.
21 * Returns false if the input contains any zero bytes or bytes with the
22 * high-bit set. Input len must be a multiple of the chunk size (8 or 16).
27 const unsigned char *
const s_end = s +
len;
40 /* Capture any zero bytes in this chunk. */
44 * First, add 0x7f to each byte. This sets the high bit in each byte,
45 * unless it was a zero. If any resulting high bits are zero, the
46 * corresponding high bits in the zero accumulator will be cleared.
48 * If none of the bytes in the chunk had the high bit set, the max
49 * value each byte can have after the addition is 0x7f + 0x7f = 0xfe,
50 * and we don't need to worry about carrying over to the next byte. If
51 * any input bytes did have the high bit set, it doesn't matter
52 * because we check for those separately.
58 * Set all bits in each lane of the highbit accumulator where input
65 /* Capture all set bits in this chunk. */
71 /* Check if any high bits in the high bit accumulator got set. */
76 /* Check if any high bits in the zero accumulator got cleared. */
void ascii_safe_strlcpy(char *dest, const char *src, size_t destsiz)
static bool is_valid_ascii(const unsigned char *s, int len)
Assert(PointerIsAligned(start, uint64))
static Vector8 vector8_broadcast(const uint8 c)
static void vector8_load(Vector8 *v, const uint8 *s)
static Vector8 vector8_or(const Vector8 v1, const Vector8 v2)
static bool vector8_is_highbit_set(const Vector8 v)