2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / text / natCollator.cc
blob676a4a41a23b57c7d1710854723c7023781c6757
1 // natCollator.cc - Native code for collation.
3 /* Copyright (C) 1999 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 // Written by Tom Tromey <tromey@cygnus.com>.
13 #include <config.h>
15 #include <gcj/cni.h>
16 #include <jvm.h>
18 #include <java/text/Collator.h>
19 #include <java/lang/StringBuffer.h>
21 #include <java-chardecomp.h>
23 void
24 java::text::Collator::decomposeCharacter (jchar c,
25 java::lang::StringBuffer *buf)
27 if (decmp == NO_DECOMPOSITION)
29 buf->append(c);
30 return;
33 const struct decomp_entry *base;
34 int high;
36 if (decmp == FULL_DECOMPOSITION)
38 base = full_decomposition;
39 high = sizeof (full_decomposition) / sizeof (struct decomp_entry);
41 else
43 base = canonical_decomposition;
44 high = sizeof (canonical_decomposition) / sizeof (struct decomp_entry);
47 // FIXME: this is probably a bit slow for the task at hand.
48 int i = high / 2;
49 int low = 0;
50 while (true)
52 if (c < base[i].key)
53 high = i;
54 else if (c > base[i].key)
55 low = i;
56 else
57 break;
59 int old = i;
60 i = (high + low) / 2;
61 if (i == old)
63 // Not in table, so it expands to itself.
64 buf->append(c);
65 return;
69 for (int j = 0; base[i].value[j] != '\0'; j += 2)
71 jchar x = (base[i].value[j] << 8) | (base[i].value[j + 1]);
72 buf->append (x);