18#ifndef MAGICKCORE_TOKEN_PRIVATE_H
19#define MAGICKCORE_TOKEN_PRIVATE_H
21#if defined(__cplusplus) || defined(c_plusplus)
29#define MaxMultibyteCodes 6
31extern MagickPrivate MagickBooleanType
32 IsGlob(
const char *) magick_attribute((__pure__));
44 utf_info[MaxMultibyteCodes] =
46 { 0x80, 0x00, 0x000007f, 0x0000000 },
47 { 0xE0, 0xC0, 0x00007ff, 0x0000080 },
48 { 0xF0, 0xE0, 0x000ffff, 0x0000800 },
49 { 0xF8, 0xF0, 0x01fffff, 0x0010000 },
50 { 0xFC, 0xF8, 0x03fffff, 0x0200000 },
51 { 0xFE, 0xFC, 0x7ffffff, 0x4000000 },
54static inline unsigned char *ConvertLatin1ToUTF8(
55 const unsigned char *magick_restrict content)
73 for (p=content; *p !=
'\0'; p++)
74 length+=(*p & 0x80) != 0 ? 2 : 1;
75 utf8=(
unsigned char *) NULL;
77 utf8=(
unsigned char *) AcquireQuantumMemory(length+1UL,
sizeof(*utf8));
78 if (utf8 == (
unsigned char *) NULL)
79 return((
unsigned char *) NULL);
81 for (p=content; *p !=
'\0'; p++)
85 *q++=(
unsigned char) c;
88 *q++=(
unsigned char) (0xc0 | ((c >> 6) & 0x3f));
89 *q++=(
unsigned char) (0x80 | (c & 0x3f));
96static inline int GetNextUTFCode(
const char *magick_restrict text,
97 unsigned int *magick_restrict octets)
110 if (text == (
const char *) NULL)
115 code=(int) (*text++) & 0xff;
117 for (i=0; i < MaxMultibyteCodes; i++)
119 if ((code & utf_info[i].code_mask) == utf_info[i].code_value)
121 unicode&=utf_info[i].utf_mask;
122 if (unicode < utf_info[i].utf_value)
124 *octets=(
unsigned int) (i+1);
127 c=(int) (*text++ ^ 0x80) & 0xff;
130 if (unicode > 0x10FFFF)
132 unicode=(unicode << 6) | c;
138static inline int GetUTFCode(
const char *magick_restrict text)
143 return(GetNextUTFCode(text,&octets));
146static inline unsigned int GetUTFOctets(
const char *magick_restrict text)
151 (void) GetNextUTFCode(text,&octets);
155static inline MagickBooleanType IsNonBreakingUTFSpace(
const int code)
162static inline MagickBooleanType IsUTFSpace(
const int code)
164 if (((code >= 0x0009) && (code <= 0x000d)) || (code == 0x0020) ||
165 (code == 0x0085) || (code == 0x00a0) || (code == 0x1680) ||
166 (code == 0x180e) || ((code >= 0x2000) && (code <= 0x200a)) ||
167 (code == 0x2028) || (code == 0x2029) || (code == 0x202f) ||
168 (code == 0x205f) || (code == 0x3000))
173static inline MagickBooleanType IsUTFValid(
int code)
178 mask=(int) 0x7fffffff;
179 if (((code & ~mask) != 0) && ((code < 0xd800) || (code > 0xdfff)) &&
180 (code != 0xfffe) && (code != 0xffff))
185static inline MagickBooleanType IsUTFAscii(
int code)
191 if ((code & ~mask) != 0)
196#if defined(__cplusplus) || defined(c_plusplus)