]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/ubidi_props.c
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / common / ubidi_props.c
index 6fca5a3407427978472e2f3c9cc4a9b10144bd8c..42d05f1e2600058eb7fa4ec4d77db6414162de2c 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2004-2011, International Business Machines
+*   Copyright (C) 2004-2014, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -21,7 +21,6 @@
 #include "unicode/udata.h" /* UDataInfo */
 #include "ucmndata.h" /* DataHeader */
 #include "udatamem.h"
-#include "umutex.h"
 #include "uassert.h"
 #include "cmemory.h"
 #include "utrie2.h"
@@ -33,6 +32,7 @@ struct UBiDiProps {
     const int32_t *indexes;
     const uint32_t *mirrors;
     const uint8_t *jgArray;
+    const uint8_t *jgArray2;
 
     UTrie2 trie;
     uint8_t formatVersion[4];
@@ -85,18 +85,28 @@ ubidi_addPropertyStarts(const UBiDiProps *bdp, const USetAdder *sa, UErrorCode *
     start=bdp->indexes[UBIDI_IX_JG_START];
     limit=bdp->indexes[UBIDI_IX_JG_LIMIT];
     jgArray=bdp->jgArray;
-    prev=0;
-    while(start<limit) {
-        jg=*jgArray++;
-        if(jg!=prev) {
-            sa->add(sa->set, start);
-            prev=jg;
+    for(;;) {
+        prev=0;
+        while(start<limit) {
+            jg=*jgArray++;
+            if(jg!=prev) {
+                sa->add(sa->set, start);
+                prev=jg;
+            }
+            ++start;
+        }
+        if(prev!=0) {
+            /* add the limit code point if the last value was not 0 (it is now start==limit) */
+            sa->add(sa->set, limit);
+        }
+        if(limit==bdp->indexes[UBIDI_IX_JG_LIMIT]) {
+            /* switch to the second Joining_Group range */
+            start=bdp->indexes[UBIDI_IX_JG_START2];
+            limit=bdp->indexes[UBIDI_IX_JG_LIMIT2];
+            jgArray=bdp->jgArray2;
+        } else {
+            break;
         }
-        ++start;
-    }
-    if(prev!=0) {
-        /* add the limit code point if the last value was not 0 (it is now start==limit) */
-        sa->add(sa->set, limit);
     }
 
     /* add code points with hardcoded properties, plus the ones following them */
@@ -122,6 +132,8 @@ ubidi_getMaxValue(const UBiDiProps *bdp, UProperty which) {
         return (max&UBIDI_MAX_JG_MASK)>>UBIDI_MAX_JG_SHIFT;
     case UCHAR_JOINING_TYPE:
         return (max&UBIDI_JT_MASK)>>UBIDI_JT_SHIFT;
+    case UCHAR_BIDI_PAIRED_BRACKET_TYPE:
+        return (max&UBIDI_BPT_MASK)>>UBIDI_BPT_SHIFT;
     default:
         return -1; /* undefined */
     }
@@ -139,10 +151,9 @@ ubidi_isMirrored(const UBiDiProps *bdp, UChar32 c) {
     return (UBool)UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT);
 }
 
-U_CFUNC UChar32
-ubidi_getMirror(const UBiDiProps *bdp, UChar32 c) {
-    uint16_t props=UTRIE2_GET16(&bdp->trie, c);
-    int32_t delta=((int16_t)props)>>UBIDI_MIRROR_DELTA_SHIFT;
+static UChar32
+getMirror(const UBiDiProps *bdp, UChar32 c, uint16_t props) {
+    int32_t delta=UBIDI_GET_MIRROR_DELTA(props);
     if(delta!=UBIDI_ESC_MIRROR_DELTA) {
         return c+delta;
     } else {
@@ -172,6 +183,12 @@ ubidi_getMirror(const UBiDiProps *bdp, UChar32 c) {
     }
 }
 
+U_CFUNC UChar32
+ubidi_getMirror(const UBiDiProps *bdp, UChar32 c) {
+    uint16_t props=UTRIE2_GET16(&bdp->trie, c);
+    return getMirror(bdp, c, props);
+}
+
 U_CFUNC UBool
 ubidi_isBidiControl(const UBiDiProps *bdp, UChar32 c) {
     uint16_t props=UTRIE2_GET16(&bdp->trie, c);
@@ -198,8 +215,28 @@ ubidi_getJoiningGroup(const UBiDiProps *bdp, UChar32 c) {
     limit=bdp->indexes[UBIDI_IX_JG_LIMIT];
     if(start<=c && c<limit) {
         return (UJoiningGroup)bdp->jgArray[c-start];
+    }
+    start=bdp->indexes[UBIDI_IX_JG_START2];
+    limit=bdp->indexes[UBIDI_IX_JG_LIMIT2];
+    if(start<=c && c<limit) {
+        return (UJoiningGroup)bdp->jgArray2[c-start];
+    }
+    return U_JG_NO_JOINING_GROUP;
+}
+
+U_CFUNC UBidiPairedBracketType
+ubidi_getPairedBracketType(const UBiDiProps *bdp, UChar32 c) {
+    uint16_t props=UTRIE2_GET16(&bdp->trie, c);
+    return (UBidiPairedBracketType)((props&UBIDI_BPT_MASK)>>UBIDI_BPT_SHIFT);
+}
+
+U_CFUNC UChar32
+ubidi_getPairedBracket(const UBiDiProps *bdp, UChar32 c) {
+    uint16_t props=UTRIE2_GET16(&bdp->trie, c);
+    if((props&UBIDI_BPT_MASK)==0) {
+        return c;
     } else {
-        return U_JG_NO_JOINING_GROUP;
+        return getMirror(bdp, c, props);
     }
 }
 
@@ -219,3 +256,8 @@ U_CFUNC UChar32
 u_charMirror(UChar32 c) {
     return ubidi_getMirror(&ubidi_props_singleton, c);
 }
+
+U_STABLE UChar32 U_EXPORT2
+u_getBidiPairedBracket(UChar32 c) {
+    return ubidi_getPairedBracket(&ubidi_props_singleton, c);
+}