compiler/libec: (#205) Fixed integer promotions to follow the C standard (6.3.1.1)
[sdk] / ecere / src / sys / unicode.ec
index 505c9a1..e3c09f4 100644 (file)
@@ -2,7 +2,7 @@ namespace sys;
 
 import "File"
 
-public int UTF8toISO8859_1(char * source, char * dest, int max)
+public int UTF8toISO8859_1(const char * source, char * dest, int max)
 {
    unichar ch;
    int nb;
@@ -20,7 +20,7 @@ public int UTF8toISO8859_1(char * source, char * dest, int max)
    return d;
 }
 
-public uint16 * UTF8toUTF16Len(char * source, int byteCount, int * wordCount)
+public uint16 * UTF8toUTF16Len(const char * source, int byteCount, int * wordCount)
 {
    if(source)
    {
@@ -77,9 +77,9 @@ public uint16 * UTF8toUTF16Len(char * source, int byteCount, int * wordCount)
          }
          if(i < numBytes)
             error = true;
-         if(codePoint > 0x10FFFF || (codePoint >= 0xD800 && codePoint <= 0xDFFF) || 
-           (codePoint < 0x80 && numBytes > 1) || 
-           (codePoint < 0x800 && numBytes > 2) || 
+         if(codePoint > 0x10FFFF || (codePoint >= 0xD800 && codePoint <= 0xDFFF) ||
+           (codePoint < 0x80 && numBytes > 1) ||
+           (codePoint < 0x800 && numBytes > 2) ||
            (codePoint < 0x10000 && numBytes > 3))
             error = true;
          if(error)
@@ -92,7 +92,7 @@ public uint16 * UTF8toUTF16Len(char * source, int byteCount, int * wordCount)
          if(codePoint > 0xFFFF)
          {
             uint16 lead = (uint16)(LEAD_OFFSET + (codePoint >> 10));
-            uint16 trail = 0xDC00 + (uint16)(codePoint & 0x3FF);
+            uint16 trail = (uint16)(0xDC00 | (codePoint & 0x3FF));
 
             dest[d++] = lead;
             dest[d++] = trail;
@@ -110,7 +110,7 @@ public uint16 * UTF8toUTF16Len(char * source, int byteCount, int * wordCount)
    return null;
 }
 
-public int UTF8toUTF16BufferLen(char * source, uint16 * dest, int max, int len)
+public int UTF8toUTF16BufferLen(const char * source, uint16 * dest, int max, int len)
 {
    if(source)
    {
@@ -148,7 +148,7 @@ public int UTF8toUTF16BufferLen(char * source, uint16 * dest, int max, int len)
          if(codePoint > 0xFFFF)
          {
             uint16 lead = (uint16)(LEAD_OFFSET + (codePoint >> 10));
-            uint16 trail = 0xDC00 + (uint16)(codePoint & 0x3FF);
+            uint16 trail = (uint16)(0xDC00 | (codePoint & 0x3FF));
             if(d >= max - 1) break;
             dest[d++] = lead;
             dest[d++] = trail;
@@ -162,10 +162,10 @@ public int UTF8toUTF16BufferLen(char * source, uint16 * dest, int max, int len)
       dest[d] = 0;
       return d;
    }
-   return 0;   
+   return 0;
 }
 
-public int UTF16BEtoUTF8Buffer(uint16 * source, byte * dest, int max)
+public int UTF16BEtoUTF8Buffer(const uint16 * source, byte * dest, int max)
 {
    int c;
    int d = 0;
@@ -176,7 +176,7 @@ public int UTF16BEtoUTF8Buffer(uint16 * source, byte * dest, int max)
       if(u16 < 0xD800 || u16 > 0xDBFF)
       {
          // TOFIX: PRECOMP ERROR IF NO BRACKETS
-         ch = (unichar)u16;         
+         ch = (unichar)u16;
       }
       else
       {
@@ -286,19 +286,19 @@ public enum PredefinedCharCategories : CharCategories
    separators = CharCategories { separatorSpace = true, separatorLine = true, separatorParagraph = true },
    others = CharCategories { otherControl = true, otherFormat = true, otherSurrogate = true, otherPrivateUse = true, otherNotAssigned = true },
    letters = CharCategories { letterUpperCase = true, letterLowerCase = true, letterTitleCase = true, letterModifier = true, letterOther = true },
-   punctuation = CharCategories { punctiationConnector = true, punctuationDash = true, punctuationOpen = true, punctuationClose = true, punctuationInitial = true, 
+   punctuation = CharCategories { punctuationConnector = true, punctuationDash = true, punctuationOpen = true, punctuationClose = true, punctuationInitial = true,
                      punctuationFinal = true, punctuationOther = true },
    symbols = CharCategories { symbolMath = true, symbolCurrency = true, symbolModifier = true, symbolOther = true },
-   connector = CharCategories { punctuationConnector = true },
+   connector = CharCategories { punctuationConnector = true }
 };
 
-public bool GetAlNum(char ** input, char * string, int max)
+public bool GetAlNum(const char ** input, char * string, int max)
 {
    int c = 0;
    unichar ch;
    int nb = 1;
    bool result = true;
-   char * buffer = *input;
+   const char * buffer = *input;
    if(!buffer[0]) { string[0]=0; return false; }
 
    // Eat all left spacing, leave last char in ch
@@ -372,21 +372,21 @@ static void FreeRange(Range range)
 
 static CharCategory asciiCategories[] =
 {
-   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc, 
-   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc, 
-   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc, 
-   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc, 
+   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc,
+   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc,
+   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc,
+   Cc, Cc, Cc, Cc, Cc, Cc, Cc, Cc,
    Zs, Po, Po, Po, Sc, Po, Po, Po,
    Ps, Pe, Po, Sm, Cs, Pd, Po, Po,
    Nd, Nd, Nd, Nd, Nd, Nd, Nd, Nd,
    Nd, Nd, Po, Po, Sm, Sm, Sm, Po,
-   Po, Lu, Lu, Lu, Lu, Lu, Lu, Lu, 
-   Lu, Lu, Lu, Lu, Lu, Lu, Lu, Lu, 
-   Lu, Lu, Lu, Lu, Lu, Lu, Lu, Lu, 
+   Po, Lu, Lu, Lu, Lu, Lu, Lu, Lu,
+   Lu, Lu, Lu, Lu, Lu, Lu, Lu, Lu,
+   Lu, Lu, Lu, Lu, Lu, Lu, Lu, Lu,
    Lu, Lu, Lu, Ps, Po, Pe, Sk, Pc,
-   Sk, Ll, Ll, Ll, Ll, Ll, Ll, Ll, 
-   Ll, Ll, Ll, Ll, Ll, Ll, Ll, Ll, 
-   Ll, Ll, Ll, Ll, Ll, Ll, Ll, Ll, 
+   Sk, Ll, Ll, Ll, Ll, Ll, Ll, Ll,
+   Ll, Ll, Ll, Ll, Ll, Ll, Ll, Ll,
+   Ll, Ll, Ll, Ll, Ll, Ll, Ll, Ll,
    Ll, Ll, Ll, Ps, Sm, Pe, Sm, Cc
 };
 
@@ -409,10 +409,10 @@ static class UnicodeDatabase
             if(line[0] && line[0] != '#')
             {
                char * endPtr;
-               uint start = strtoul(line, &endPtr, 16);
+               uint start = (uint)strtoul(line, &endPtr, 16);
                if(endPtr)
                {
-                  uint end = (endPtr && *endPtr == '.') ? strtoul(endPtr + 2, &endPtr, 16) : start;
+                  uint end = (endPtr && *endPtr == '.') ? (uint)strtoul(endPtr + 2, &endPtr, 16) : start;
                   if(endPtr)
                   {
                      endPtr = strchr(endPtr, ';');
@@ -491,12 +491,12 @@ static class UnicodeDatabase
                         if(category)
                         {
                            Range range { start, end, category };
-                           BTNode node { key = (uint) &range };
+                           BTNode node { key = (uintptr) &range };
                            if(categories.Add(node))
                            {
-                              node.key = (uint)new Range[1];
+                              node.key = (uintptr)new Range[1];
                               *(Range *)node.key = range;
-                           } 
+                           }
                            else
                               delete node;
                         }
@@ -527,7 +527,7 @@ static class UnicodeDatabase
                string[len++] = ';';
                string[len++] = ' ';
                range->category.OnGetString(string + len, null, null);
-               len += 2;                              
+               len += 2;
                string[len++] = '\n';
                string[len] = '\0';
                f.Puts(string);
@@ -535,7 +535,7 @@ static class UnicodeDatabase
             delete f;
          }
          */
-      }      
+      }
    }
    ~UnicodeDatabase()
    {
@@ -553,7 +553,7 @@ public CharCategory GetCharCategory(unichar ch)
    {
       CharCategory category = none;
       Range range { ch, ch };
-      BTNode node = dataBase.categories.Find((uint) &range);
+      BTNode node = dataBase.categories.Find((uintptr) &range);
       if(node)
          category = ((Range *)node.key)->category;
       return category;