]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/toolutil/ucm.c
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / ucm.c
index bb7c3bb0edd909346e99bf33efe7e1d7b259aee1..adb3ebd2d0a9e8b992849b9255711cc895f7a5f8 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2003-2007, International Business Machines
+*   Copyright (C) 2003-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -327,7 +327,7 @@ checkBaseExtUnicode(UCMStates *baseStates, UCMTable *base, UCMTable *ext,
                 return result;
             }
 
-            if(0<=mb->f && mb->f<=2) {
+            if((0<=mb->f && mb->f<=2) || mb->f==4) {
                 break;
             }
 
@@ -339,7 +339,7 @@ checkBaseExtUnicode(UCMStates *baseStates, UCMTable *base, UCMTable *ext,
                 return result;
             }
 
-            if(0<=me->f && me->f<=2) {
+            if((0<=me->f && me->f<=2) || me->f==4) {
                 break;
             }
 
@@ -857,8 +857,8 @@ ucm_parseMappingLine(UCMapping *m,
             break;
         } else if(*s=='|') {
             f=(int8_t)(s[1]-'0');
-            if((uint8_t)f>3) {
-                fprintf(stderr, "ucm error: fallback indicator must be |0..|3 - \"%s\"\n", line);
+            if((uint8_t)f>4) {
+                fprintf(stderr, "ucm error: fallback indicator must be |0..|4 - \"%s\"\n", line);
                 return FALSE;
             }
             break;
@@ -915,7 +915,7 @@ ucm_addMapping(UCMTable *table,
                uint8_t bytes[UCNV_EXT_MAX_BYTES]) {
     UCMapping *tm;
     UChar32 c;
-    int32_t index;
+    int32_t idx;
 
     if(table->mappingsLength>=table->mappingsCapacity) {
         /* make the mappings array larger */
@@ -960,32 +960,32 @@ ucm_addMapping(UCMTable *table,
     }
 
     if(m->uLen>1) {
-        index=table->codePointsLength;
+        idx=table->codePointsLength;
         table->codePointsLength+=m->uLen;
         if(table->codePointsLength>table->codePointsCapacity) {
             fprintf(stderr, "ucm error: too many code points in multiple-code point mappings\n");
             exit(U_MEMORY_ALLOCATION_ERROR);
         }
 
-        uprv_memcpy(table->codePoints+index, codePoints, m->uLen*4);
-        m->u=index;
+        uprv_memcpy(table->codePoints+idx, codePoints, m->uLen*4);
+        m->u=idx;
     }
 
     if(m->bLen>4) {
-        index=table->bytesLength;
+        idx=table->bytesLength;
         table->bytesLength+=m->bLen;
         if(table->bytesLength>table->bytesCapacity) {
             fprintf(stderr, "ucm error: too many bytes in mappings with >4 charset bytes\n");
             exit(U_MEMORY_ALLOCATION_ERROR);
         }
 
-        uprv_memcpy(table->bytes+index, bytes, m->bLen);
-        m->b.index=index;
+        uprv_memcpy(table->bytes+idx, bytes, m->bLen);
+        m->b.idx=idx;
     }
 
     /* set unicodeMask */
-    for(index=0; index<m->uLen; ++index) {
-        c=codePoints[index];
+    for(idx=0; idx<m->uLen; ++idx) {
+        c=codePoints[idx];
         if(c>=0x10000) {
             table->unicodeMask|=UCNV_HAS_SUPPLEMENTARY; /* there are supplementary code points */
         } else if(U_IS_SURROGATE(c)) {
@@ -1030,8 +1030,8 @@ ucm_open() {
 U_CAPI void U_EXPORT2
 ucm_close(UCMFile *ucm) {
     if(ucm!=NULL) {
-        uprv_free(ucm->base);
-        uprv_free(ucm->ext);
+        ucm_closeTable(ucm->base);
+        ucm_closeTable(ucm->ext);
         uprv_free(ucm);
     }
 }
@@ -1051,6 +1051,7 @@ ucm_mappingType(UCMStates *baseStates,
     /*
      * Suitable for an ICU conversion base table means:
      * - a 1:1 mapping (1 Unicode code point : 1 byte sequence)
+     * - precision flag 0..3
      * - SBCS: any 1:1 mapping
      *         (the table stores additional bits to distinguish mapping types)
      * - MBCS: not a |2 SUB mapping for <subchar1>
@@ -1070,7 +1071,7 @@ ucm_mappingType(UCMStates *baseStates,
      * makeconv uses a hack for moving mappings only for the fromUnicode table
      * that only works with non-negative values of f.
      */
-    if( m->uLen==1 && count==1 &&
+    if( m->uLen==1 && count==1 && m->f<=3 &&
         (baseStates->maxCharLength==1 ||
             !((m->f==2 && m->bLen==1) ||
               (m->f==1 && bytes[0]==0) ||
@@ -1146,7 +1147,7 @@ ucm_readTable(UCMFile *ucm, FileStream* convFile,
     char line[500];
     char *end;
     UBool isOK;
-    
+
     if(U_FAILURE(*pErrorCode)) {
         return;
     }