Line data Source code
1 : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
2 : * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
3 : */
4 :
5 : #ifndef SOLIDSYSLOGUTF8_H
6 : #define SOLIDSYSLOGUTF8_H
7 :
8 : #include "SolidSyslogExternC.h"
9 :
10 : #include <stdbool.h>
11 :
12 : SOLIDSYSLOG_EXTERN_C_BEGIN
13 :
14 : /* Byte-level UTF-8 lead and continuation classifiers per RFC 3629 section 4.
15 : * These cover the disjoint top-bit patterns only - overlong / surrogate /
16 : * above-Unicode validity is composed on top by callers that need it. */
17 :
18 577717 : static inline bool SolidSyslogUtf8_IsAsciiByte(char byte)
19 : {
20 577717 : return ((unsigned char) byte & 0x80U) == 0U;
21 : }
22 :
23 140 : static inline bool SolidSyslogUtf8_IsContinuationByte(char byte)
24 : {
25 140 : return ((unsigned char) byte & 0xC0U) == 0x80U;
26 : }
27 :
28 59763 : static inline bool SolidSyslogUtf8_IsTwoByteLead(char byte)
29 : {
30 59763 : return ((unsigned char) byte & 0xE0U) == 0xC0U;
31 : }
32 :
33 97287 : static inline bool SolidSyslogUtf8_IsThreeByteLead(char byte)
34 : {
35 97287 : return ((unsigned char) byte & 0xF0U) == 0xE0U;
36 : }
37 :
38 134708 : static inline bool SolidSyslogUtf8_IsFourByteLead(char byte)
39 : {
40 134708 : return ((unsigned char) byte & 0xF8U) == 0xF0U;
41 : }
42 :
43 : SOLIDSYSLOG_EXTERN_C_END
44 :
45 : #endif /* SOLIDSYSLOGUTF8_H */
|