/*
- Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization
+ Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
dedicated to making software imaging solutions freely available.
You may not use this file except in compliance with the License.
typedef struct
{
- long
+ int
code_mask,
code_value,
utf_mask,
{ 0xFE, 0xFC, 0x7ffffff, 0x4000000 }, /* 6 byte sequence */
};
-static inline long GetNextUTFCode(const char *text,size_t *octets)
+static inline unsigned char *ConvertLatin1ToUTF8(const unsigned char *content)
{
- long
+ register const unsigned char
+ *p;
+
+ register unsigned char
+ *q;
+
+ size_t
+ length;
+
+ unsigned char
+ *utf8;
+
+ unsigned int
+ c;
+
+ length=0;
+ for (p=content; *p != '\0'; p++)
+ length+=(*p & 0x80) != 0 ? 2 : 1;
+ utf8=(unsigned char *) NULL;
+ if (~length >= 1)
+ utf8=(unsigned char *) AcquireQuantumMemory(length+1UL,sizeof(*utf8));
+ if (utf8 == (unsigned char *) NULL)
+ return((unsigned char *) NULL);
+ q=utf8;
+ for (p=content; *p != '\0'; p++)
+ {
+ c=(*p);
+ if ((c & 0x80) == 0)
+ *q++=c;
+ else
+ {
+ *q++=0xc0 | ((c >> 6) & 0x3f);
+ *q++=0x80 | (c & 0x3f);
+ }
+ }
+ *q='\0';
+ return(utf8);
+}
+
+static inline int GetNextUTFCode(const char *text,unsigned int *octets)
+{
+ int
code;
- register long
+ register ssize_t
i;
- register long
+ register int
c,
unicode;
- *octets=0;
+ *octets=1;
if (text == (const char *) NULL)
{
errno=EINVAL;
return(-1);
}
- code=(long) (*text++) & 0xff;
+ code=(int) (*text++) & 0xff;
unicode=code;
for (i=0; i < MaxMultibyteCodes; i++)
{
errno=EILSEQ;
return(-1);
}
- *octets=(size_t) (i+1);
+ *octets=(unsigned int) (i+1);
return(unicode);
}
- c=(long) (*text++ ^ 0x80) & 0xff;
+ c=(int) (*text++ ^ 0x80) & 0xff;
if ((c & 0xc0) != 0)
{
errno=EILSEQ;
return(-1);
}
-static long GetUTFCode(const char *text)
+static inline int GetUTFCode(const char *text)
{
- size_t
+ unsigned int
octets;
return(GetNextUTFCode(text,&octets));
}
-static size_t GetUTFOctets(const char *text)
+static inline unsigned int GetUTFOctets(const char *text)
{
- size_t
+ unsigned int
octets;
(void) GetNextUTFCode(text,&octets);
return(octets);
}
-static inline MagickBooleanType IsUTFSpace(long code)
+static inline MagickBooleanType IsUTFSpace(int code)
{
if (((code >= 0x0009) && (code <= 0x000d)) || (code == 0x0020) ||
(code == 0x0085) || (code == 0x00a0) || (code == 0x1680) ||
return(MagickFalse);
}
-static inline MagickBooleanType IsUTFValid(long code)
+static inline MagickBooleanType IsUTFValid(int code)
{
- long
+ int
mask;
- mask=(long) 0x7fffffff;
+ mask=(int) 0x7fffffff;
if (((code & ~mask) != 0) && ((code < 0xd800) || (code > 0xdfff)) &&
(code != 0xfffe) && (code != 0xffff))
return(MagickFalse);
return(MagickTrue);
}
-static inline MagickBooleanType IsUTFAscii(long code)
+static inline MagickBooleanType IsUTFAscii(int code)
{
- long
+ int
mask;
- mask=(long) 0x7f;
+ mask=(int) 0x7f;
if ((code & ~mask) != 0)
return(MagickFalse);
return(MagickTrue);