]> 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 6c4d767cea53f4d54c90218b4bd65bd9b4b1eef8..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"
 
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "ucdata.h"
 #include "ucpgba.h"
 
@@ -58,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)
@@ -93,12 +103,7 @@ sizeof(_symmetric_pairs)/sizeof(_symmetric_pairs[0]);
  * This routine looks up the other form of a symmetric pair.
  */
 static unsigned long
-#ifdef __STDC__
 _ucsymmetric_pair(unsigned long c)
-#else
-_ucsymmetric_pair(c)
-unsigned long c;
-#endif
 {
     int i;
 
@@ -115,15 +120,8 @@ unsigned long c;
  * the visual text order chain.
  */
 static ucrun_t *
-#ifdef __STDC__
 _add_run(ucstring_t *str, unsigned long *src,
          unsigned long start, unsigned long end, int direction)
-#else
-_add_run(str, src, start, end, direction)
-ucstring_t *str;
-unsigned long *src, start, end;
-int direction;
-#endif
 {
     long i, t;
     ucrun_t *run;
@@ -179,14 +177,8 @@ int direction;
 }
 
 static void
-#ifdef __STDC__
 _ucadd_rtl_segment(ucstring_t *str, unsigned long *source, unsigned long start,
                    unsigned long end)
-#else
-_ucadd_rtl_segment(str, source, start, end)
-ucstring_t *str;
-unsigned long *source, start, end;
-#endif
 {
     unsigned long s, e;
     ucrun_t *run, *lrun;
@@ -226,8 +218,9 @@ unsigned long *source, start, end;
         }
 
         /*
-         * 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]) &&
@@ -298,14 +291,8 @@ unsigned long *source, start, end;
 }
 
 static void
-#ifdef __STDC__
 _ucadd_ltr_segment(ucstring_t *str, unsigned long *source, unsigned long start,
                    unsigned long end)
-#else
-_ucadd_ltr_segment(str, source, start, end)
-ucstring_t *str;
-unsigned long *source, start, end;
-#endif
 {
     ucrun_t *run;
 
@@ -329,17 +316,11 @@ unsigned long *source, start, end;
 }
 
 ucstring_t *
-#ifdef __STDC__
 ucstring_create(unsigned long *source, unsigned long start, unsigned long end,
                 int default_direction, int cursor_motion)
-#else
-ucstring_create(source, start, end, default_direction, cursor_motion)
-unsigned long *source, start, end;
-int default_direction, cursor_motion;
-#endif
 {
     int rtl_first;
-    unsigned long s, e;
+    unsigned long s, e, ld;
     ucstring_t *str;
 
     str = (ucstring_t *) malloc(sizeof(ucstring_t));
@@ -396,10 +377,15 @@ int default_direction, cursor_motion;
              * 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--;
             }
 
@@ -413,11 +399,15 @@ int default_direction, cursor_motion;
         /*
          * 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--;
         }
 
@@ -446,12 +436,7 @@ int default_direction, cursor_motion;
 }
 
 void
-#ifdef __STDC__
 ucstring_free(ucstring_t *s)
-#else
-ucstring_free(s)
-ucstring_t *s;
-#endif
 {
     ucrun_t *l, *r;
 
@@ -472,13 +457,7 @@ ucstring_t *s;
 }
 
 int
-#ifdef __STDC__
 ucstring_set_cursor_motion(ucstring_t *str, int cursor_motion)
-#else
-ucstring_set_cursor_motion(s, cursor_motion)
-ucstring_t *str;
-int cursor_motion;
-#endif
 {
     int n;
 
@@ -491,13 +470,7 @@ int cursor_motion;
 }
 
 static int
-#ifdef __STDC__
 _ucstring_visual_cursor_right(ucstring_t *str, int count)
-#else
-_ucstring_visual_cursor_right(str, count)
-ucstring_t *str;
-int count;
-#endif
 {
     int cnt = count;
     unsigned long size;
@@ -535,13 +508,7 @@ int count;
 }
 
 static int
-#ifdef __STDC__
 _ucstring_logical_cursor_right(ucstring_t *str, int count)
-#else
-_ucstring_logical_cursor_right(str, count)
-ucstring_t *str;
-int count;
-#endif
 {
     int cnt = count;
     unsigned long size;
@@ -619,13 +586,7 @@ int count;
 }
 
 int
-#ifdef __STDC__
 ucstring_cursor_right(ucstring_t *str, int count)
-#else
-ucstring_cursor_right(str, count)
-ucstring_t *str;
-int count;
-#endif
 {
     if (str == 0)
       return 0;
@@ -635,13 +596,7 @@ int count;
 }
 
 static int
-#ifdef __STDC__
 _ucstring_visual_cursor_left(ucstring_t *str, int count)
-#else
-_ucstring_visual_cursor_left(str, count)
-ucstring_t *str;
-int count;
-#endif
 {
     int cnt = count;
     unsigned long size;
@@ -680,13 +635,7 @@ int count;
 }
 
 static int
-#ifdef __STDC__
 _ucstring_logical_cursor_left(ucstring_t *str, int count)
-#else
-_ucstring_logical_cursor_left(str, count)
-ucstring_t *str;
-int count;
-#endif
 {
     int cnt = count;
     unsigned long size;
@@ -764,13 +713,7 @@ int count;
 }
 
 int
-#ifdef __STDC__
 ucstring_cursor_left(ucstring_t *str, int count)
-#else
-ucstring_cursor_left(str, count)
-ucstring_t *str;
-int count;
-#endif
 {
     if (str == 0)
       return 0;
@@ -780,13 +723,7 @@ int count;
 }
 
 void
-#ifdef __STDC__
 ucstring_cursor_info(ucstring_t *str, int *direction, unsigned long *position)
-#else
-ucstring_cursor_info(str, direction, position)
-ucstring_t *str, int *direction;
-unsigned long *position;
-#endif
 {
     long c;
     unsigned long size;