]> granicus.if.org Git - imagemagick/blobdiff - magick/token-private.h
(no commit message)
[imagemagick] / magick / token-private.h
index 24483d346a2cc96f225987710b44526c5e686022..9eb663a14acf8769ee85a06c48e5ea8ebdc8352e 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  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.
@@ -30,7 +30,7 @@ extern "C" {
 
 typedef struct
 {
-  long
+  int
     code_mask,
     code_value,
     utf_mask,
@@ -48,25 +48,66 @@ static UTFInfo
     { 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)
 {
-  register 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 ssize_t
     i;
 
-  register long
+  register int
     c,
     unicode;
 
-  long
-    code;
-
-  *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++)
   {
@@ -78,10 +119,10 @@ static inline long GetNextUTFCode(const char *text,size_t *octets)
             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;
@@ -93,24 +134,24 @@ static inline long GetNextUTFCode(const char *text,size_t *octets)
   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) ||
@@ -121,24 +162,24 @@ static inline MagickBooleanType IsUTFSpace(long code)
   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);