2 Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
8 http://www.imagemagick.org/script/license.php
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 MagickCore private token methods.
18 #ifndef _MAGICKCORE_TOKEN_PRIVATE_H
19 #define _MAGICKCORE_TOKEN_PRIVATE_H
21 #if defined(__cplusplus) || defined(c_plusplus)
29 #define MaxMultibyteCodes 6
41 utf_info[MaxMultibyteCodes] =
43 { 0x80, 0x00, 0x000007f, 0x0000000 }, /* 1 byte sequence */
44 { 0xE0, 0xC0, 0x00007ff, 0x0000080 }, /* 2 byte sequence */
45 { 0xF0, 0xE0, 0x000ffff, 0x0000800 }, /* 3 byte sequence */
46 { 0xF8, 0xF0, 0x01fffff, 0x0010000 }, /* 4 byte sequence */
47 { 0xFC, 0xF8, 0x03fffff, 0x0200000 }, /* 5 byte sequence */
48 { 0xFE, 0xFC, 0x7ffffff, 0x4000000 }, /* 6 byte sequence */
51 static inline unsigned char *ConvertLatin1ToUTF8(const unsigned char *content)
53 register const unsigned char
56 register unsigned char
69 for (p=content; *p != '\0'; p++)
70 length+=(*p & 0x80) != 0 ? 2 : 1;
71 utf8=(unsigned char *) NULL;
73 utf8=(unsigned char *) AcquireQuantumMemory(length+1UL,sizeof(*utf8));
74 if (utf8 == (unsigned char *) NULL)
75 return((unsigned char *) NULL);
77 for (p=content; *p != '\0'; p++)
84 *q++=0xc0 | ((c >> 6) & 0x3f);
85 *q++=0x80 | (c & 0x3f);
92 static inline ssize_t GetNextUTFCode(const char *text,size_t *octets)
105 if (text == (const char *) NULL)
110 code=(ssize_t) (*text++) & 0xff;
112 for (i=0; i < MaxMultibyteCodes; i++)
114 if ((code & utf_info[i].code_mask) == utf_info[i].code_value)
116 unicode&=utf_info[i].utf_mask;
117 if (unicode < utf_info[i].utf_value)
122 *octets=(size_t) (i+1);
125 c=(ssize_t) (*text++ ^ 0x80) & 0xff;
131 unicode=(unicode << 6) | c;
137 static inline ssize_t GetUTFCode(const char *text)
142 return(GetNextUTFCode(text,&octets));
145 static inline size_t GetUTFOctets(const char *text)
150 (void) GetNextUTFCode(text,&octets);
154 static inline MagickBooleanType IsUTFSpace(ssize_t code)
156 if (((code >= 0x0009) && (code <= 0x000d)) || (code == 0x0020) ||
157 (code == 0x0085) || (code == 0x00a0) || (code == 0x1680) ||
158 (code == 0x180e) || ((code >= 0x2000) && (code <= 0x200a)) ||
159 (code == 0x2028) || (code == 0x2029) || (code == 0x202f) ||
160 (code == 0x205f) || (code == 0x3000))
165 static inline MagickBooleanType IsUTFValid(ssize_t code)
170 mask=(ssize_t) 0x7fffffff;
171 if (((code & ~mask) != 0) && ((code < 0xd800) || (code > 0xdfff)) &&
172 (code != 0xfffe) && (code != 0xffff))
177 static inline MagickBooleanType IsUTFAscii(ssize_t code)
183 if ((code & ~mask) != 0)
188 #if defined(__cplusplus) || defined(c_plusplus)