11#include "utf8validator.h"
15static inline bool isChar8Bit(
signed char ch)
20static inline bool isUtf8TupelIndicator(
unsigned char ch)
22 return (ch & 0xE0) == 0xC0;
25static inline bool isUtf8OverlongTupel(
unsigned char ch)
27 return (ch & 0xFE) == 0xC0;
30static inline bool isUtf8TripleIndicator(
unsigned char ch)
32 return (ch & 0xF0) == 0xE0;
35static inline bool isUtf8OverlongTriple(
unsigned char ch1,
unsigned char ch2)
37 return (ch1 & 0xFF) == 0xE0 && (ch2 & 0xE0) == 0x80;
40static inline bool isUtf8QuartetIndicator(
unsigned char ch)
42 return (ch & 0xF8) == 0xF0;
45static inline bool isUtf8OverlongQuartet(
unsigned char ch1,
unsigned char ch2)
47 return (ch1 & 0xFF) == 0xF0 && (ch2 & 0xF0) == 0x80;
50static inline bool isUtf8QuintetIndicator(
unsigned char ch)
52 return (ch & 0xFC) == 0xF8;
55static inline bool isUtf8OverlongQuintet(
unsigned char ch1,
unsigned char ch2)
57 return (ch1 & 0xFF) == 0xF8 && (ch2 & 0xF8) == 0x80;
60static inline bool isUtf8SextetIndicator(
unsigned char ch)
62 return (ch & 0xFE) == 0xFC;
65static inline bool isUtf8OverlongSextet(
unsigned char ch1,
unsigned char ch2)
67 return (ch1 & 0xFF) == 0xFC && (ch2 & 0xFC) == 0x80;
70static inline bool isUtf8Continuation(
unsigned char ch)
72 return (ch & 0xC0) == 0x80;
75bool KSieve::isValidUtf8(
const char *s,
unsigned int len)
77 for (
unsigned int i = 0; i < len; ++i) {
78 const unsigned char ch = s[i];
79 if (!isChar8Bit(ch)) {
82 if (isUtf8TupelIndicator(ch)) {
86 if (isUtf8OverlongTupel(ch)) {
89 if (!isUtf8Continuation(s[i + 1])) {
93 }
else if (isUtf8TripleIndicator(ch)) {
97 if (isUtf8OverlongTriple(ch, s[i + 1])) {
100 if (!isUtf8Continuation(s[i + 2])) {
104 }
else if (isUtf8QuartetIndicator(ch)) {
108 if (isUtf8OverlongQuartet(ch, s[i + 1])) {
111 if (!isUtf8Continuation(s[i + 2]) || !isUtf8Continuation(s[i + 3])) {
115 }
else if (isUtf8QuintetIndicator(ch)) {
119 if (isUtf8OverlongQuintet(ch, s[i + 1])) {
122 if (!isUtf8Continuation(s[i + 2]) || !isUtf8Continuation(s[i + 3]) || !isUtf8Continuation(s[i + 4])) {
126 }
else if (isUtf8SextetIndicator(ch)) {
130 if (isUtf8OverlongSextet(ch, s[i + 1])) {
133 if (!isUtf8Continuation(s[i + 2]) || !isUtf8Continuation(s[i + 3]) || !isUtf8Continuation(s[i + 4])
134 || !isUtf8Continuation(s[i + 5])) {
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.