]> git.sur5r.net Git - openldap/blobdiff - libraries/liblunicode/ucdata/ucpgba.c
ITS#4707 added new ldap_init_fd() API
[openldap] / libraries / liblunicode / ucdata / ucpgba.c
index d63526db4ffb12fa1fe8a2940fc66d21be6523bc..cd1f08246f1babef2ad2d759e7fde7fbac179e29 100644 (file)
@@ -1,5 +1,18 @@
-/*
- * Copyright 1999 Computing Research Labs, New Mexico State University
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2007 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Copyright 2001 Computing Research Labs, New Mexico State University
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-#ifndef lint
-#ifdef __GNUC__
-static char rcsid[] __attribute__ ((unused)) = "$Id: ucpgba.c,v 1.4 1999/11/29 16:41:06 mleisher Exp $";
-#else
-static char rcsid[] = "$Id: ucpgba.c,v 1.4 1999/11/29 16:41:06 mleisher Exp $";
-#endif
-#endif
+/* $Id: ucpgba.c,v 1.5 2001/01/02 18:46:20 mleisher Exp $ */
 
 #include "portable.h"
 
@@ -61,7 +68,7 @@ static char rcsid[] = "$Id: ucpgba.c,v 1.4 1999/11/29 16:41:06 mleisher Exp $";
  * ISWEAK_NEUTRAL - Test for weak or neutral characters.
  */
 #define ISLTR_LTR(cc) ucisprop(cc, UC_L|UC_MN|UC_EN|UC_ES,\
-                               UC_ET|UC_AN|UC_CS|UC_B|UC_S|UC_WS|UC_ON)
+                               UC_ET|UC_CS|UC_B|UC_S|UC_WS|UC_ON)
 
 #define ISRTL_RTL(cc) ucisprop(cc, UC_R|UC_MN|UC_EN|UC_ES,\
                                UC_ET|UC_AN|UC_CS|UC_B|UC_S|UC_WS|UC_ON)
@@ -211,8 +218,9 @@ _ucadd_rtl_segment(ucstring_t *str, unsigned long *source, unsigned long start,
         }
 
         /*
-         * Now handle the weak sequences such that multiple non-digit groups
-         * are kept together appropriately and added as RTL sequences.
+         * Handle digits in a special way.  This makes sure the weakly
+         * directional characters appear on the expected sides of a number
+         * depending on whether that number is Arabic or not.
          */
         for (s = e; e < end && ISWEAKSPECIAL(source[e]); e++) {
             if (!ISDIGITSPECIAL(source[e]) &&
@@ -312,7 +320,7 @@ ucstring_create(unsigned long *source, unsigned long start, unsigned long end,
                 int default_direction, int cursor_motion)
 {
     int rtl_first;
-    unsigned long s, e;
+    unsigned long s, e, ld;
     ucstring_t *str;
 
     str = (ucstring_t *) malloc(sizeof(ucstring_t));
@@ -369,10 +377,15 @@ ucstring_create(unsigned long *source, unsigned long start, unsigned long end,
              * Determine the next run of LTR text.
              */
 
-            while (e < end && ISLTR_LTR(source[e]))
-              e++;
+            ld = s;
+            while (e < end && ISLTR_LTR(source[e])) {
+                if (ucisdigit(source[e]) &&
+                    !(0x660 <= source[e] && source[e] <= 0x669))
+                  ld = e;
+                e++;
+            }
             if (str->direction != UCPGBA_LTR) {
-                while (e > s && ISWEAK_NEUTRAL(source[e - 1]))
+                while (e > ld && ISWEAK_NEUTRAL(source[e - 1]))
                   e--;
             }
 
@@ -386,11 +399,15 @@ ucstring_create(unsigned long *source, unsigned long start, unsigned long end,
         /*
          * Determine the next run of RTL text.
          */
-        s = e;
-        while (e < end && ISRTL_RTL(source[e]))
-          e++;
+        ld = s = e;
+        while (e < end && ISRTL_RTL(source[e])) {
+            if (ucisdigit(source[e]) &&
+                !(0x660 <= source[e] && source[e] <= 0x669))
+              ld = e;
+            e++;
+        }
         if (str->direction != UCPGBA_RTL) {
-            while (e > s && ISWEAK_NEUTRAL(source[e - 1]))
+            while (e > ld && ISWEAK_NEUTRAL(source[e - 1]))
               e--;
         }