-/*
- * 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"
* 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)
* 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;
* 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;
}
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;
}
/*
- * 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]) &&
}
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;
}
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));
* 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--;
}
/*
* 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--;
}
}
void
-#ifdef __STDC__
ucstring_free(ucstring_t *s)
-#else
-ucstring_free(s)
-ucstring_t *s;
-#endif
{
ucrun_t *l, *r;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;