OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [java/] [lang/] [natCharacter.cc] - Blame information for rev 848

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 758 jeremybenn
/* java.lang.Character -- Wrapper class for char, and Unicode subsets
2
   Copyright (C) 1998, 1999, 2001, 2002, 2007 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
#include <config.h>
39
 
40
#include <gcj/cni.h>
41
#include <jvm.h>
42
#include <java/lang/Character.h>
43
 
44
#include <java-chartables.h>
45
 
46
 
47
 
48
// These constants define the return values for characters that are unassigned
49
// or reserved for private use.
50
#define UNASSIGNED_TYPE 0
51
#define UNASSIGNED_DIGIT -1
52
#define UNASSIGNED_DIRECTION -1
53
#define UNASSIGNED_NUMERIC_VALUE -1
54
 
55
#define PRIVATE_TYPE 18
56
#define PRIVATE_DIRECTION 0
57
 
58
// The methods that take a char as an argument all have counterparts that 
59
// take ints.  The ones that take chars only work for the BMP or plane 0 of the
60
// Unicode standard but the ones that take ints work for all Unicode code
61
// points.  However, the ones that take chars don't simply redirect the calls
62
// because the BMP is by far the most used plane so saving a little time on
63
// each call makes sense.
64
 
65
jchar
66
java::lang::Character::readChar(jchar ch)
67
{
68
  // Perform 16-bit addition to find the correct entry in data.
69
  return data[0][(jchar) (blocks[0][ch >> shift[0]] + ch)];
70
}
71
 
72
jchar
73
java::lang::Character::readCodePoint(jint codePoint)
74
{
75
  jint plane = codePoint >> 16;
76
  jchar offset = (jchar)(codePoint & 0xffff);
77
  // Be careful not to call this method with an unassigned character.  The only
78
  // characters assigned as of Unicode 4.0.0 belong to planes 0, 1, 2, and 14.
79
  return data[plane][(jchar) (blocks[plane][offset >> shift[plane]] + offset)];
80
}
81
 
82
jint
83
java::lang::Character::getType(jchar ch)
84
{
85
  // Perform 16-bit addition to find the correct entry in data.
86
  return (jint) (data[0][(jchar) (blocks[0][ch >> shift[0]] + ch)] & TYPE_MASK);
87
}
88
 
89
jint
90
java::lang::Character::getType(jint codePoint)
91
{
92
  jint plane = codePoint >> 16;
93
  if (plane < 0 || (plane > 2 && plane != 14))
94
    {
95
      if (plane > 14 && ((codePoint & 0xffff) < 0xfffe))
96
        return (jint) PRIVATE_TYPE;
97
      return (jint) UNASSIGNED_TYPE;
98
    }
99
  jint offset = codePoint & 0xffff;
100
  return (jint)
101
    (data[plane]
102
     [(jchar) (blocks[plane][offset >> shift[plane]] + offset)] & TYPE_MASK);
103
}
104
 
105
jchar
106
java::lang::Character::toLowerCase(jchar ch)
107
{
108
  return (jchar) (ch + lower[0][readChar(ch) >> 7]);
109
}
110
 
111
jint
112
java::lang::Character::toLowerCase(jint codePoint)
113
{
114
  jint plane = codePoint >> 16;
115
  if (plane < 0 || (plane > 2 && plane != 14))
116
    return codePoint;
117
  return (lower[plane][readCodePoint(codePoint) >> 7]) + codePoint;
118
}
119
 
120
jchar
121
java::lang::Character::toUpperCase(jchar ch)
122
{
123
  return (jchar) (ch + upper[0][readChar(ch) >> 7]);
124
}
125
 
126
jint
127
java::lang::Character::toUpperCase(jint codePoint)
128
{
129
  jint plane = codePoint >> 16;
130
  if (plane < 0 || (plane > 2 && plane != 14))
131
    return codePoint;
132
  return (upper[plane][readCodePoint(codePoint) >> 7]) + codePoint;
133
}
134
 
135
jchar
136
java::lang::Character::toTitleCase(jchar ch)
137
{
138
  // As title is short, it doesn't hurt to exhaustively iterate over it.
139
  for (int i = title_length - 2; i >= 0; i -= 2)
140
    if (title[i] == ch)
141
      return title[i + 1];
142
  return toUpperCase(ch);
143
}
144
 
145
jint
146
java::lang::Character::toTitleCase(jint codePoint)
147
{
148
  // As of Unicode 4.0.0 no characters outside of plane 0 have titlecase
149
  // mappings that are different from their uppercase mapping.
150
  if (codePoint >= 0 && codePoint < 0x10000)
151
    return toTitleCase((jchar)codePoint);
152
  return toUpperCase(codePoint);
153
}
154
 
155
jint
156
java::lang::Character::digit(jchar ch, jint radix)
157
{
158
  if (radix < MIN_RADIX || radix > MAX_RADIX)
159
    return (jint) -1;
160
  jchar attr = readChar(ch);
161
  if (((1 << (attr & TYPE_MASK))
162
       & ((1 << UPPERCASE_LETTER)
163
          | (1 << LOWERCASE_LETTER)
164
          | (1 << DECIMAL_DIGIT_NUMBER))))
165
    {
166
      // Signedness doesn't matter; 0xffff vs. -1 are both rejected.
167
      jint digit = (jint) numValue[0][attr >> 7];
168
      return (digit >= 0 && digit < radix) ? digit : (jint) -1;
169
    }
170
  return (jint) -1;
171
}
172
 
173
jint
174
java::lang::Character::digit(jint codePoint, jint radix)
175
{
176
  if (radix < MIN_RADIX || radix > MAX_RADIX)
177
    return (jint) -1;
178
 
179
  jint plane = codePoint >> 16;
180
  if (plane < 0 || (plane > 2 && plane != 14))
181
    return UNASSIGNED_DIGIT;
182
 
183
  jchar attr = readCodePoint(codePoint);
184
  if (((1 << (attr & TYPE_MASK))
185
       & ((1 << UPPERCASE_LETTER)
186
          | (1 << LOWERCASE_LETTER)
187
          | (1 << DECIMAL_DIGIT_NUMBER))))
188
    {
189
      // Signedness doesn't matter; 0xffff vs. -1 are both rejected.
190
      jint digit = (jint) numValue[plane][attr >> 7];
191
      if (digit <= -3)
192
        digit = largenums[-digit -3];
193
      return (digit >= 0 && digit < radix) ? digit : (jint) -1;
194
    }
195
  return (jint) -1;
196
 
197
}
198
 
199
jint
200
java::lang::Character::getNumericValue(jchar ch)
201
{
202
  // numValue is stored as an array of jshort, since 10000 is the maximum.
203
  return (jint) numValue[0][readChar(ch) >> 7];
204
}
205
 
206
jint
207
java::lang::Character::getNumericValue(jint codePoint)
208
{
209
  jint plane = codePoint >> 16;
210
  if (plane < 0 || (plane > 2 && plane != 14))
211
    return UNASSIGNED_NUMERIC_VALUE;
212
  jshort num = numValue[plane][readCodePoint(codePoint) >> 7];
213
  if (num <= -3)
214
    return largenums[-num - 3];
215
  return num;
216
}
217
 
218
jbyte
219
java::lang::Character::getDirectionality(jchar ch)
220
{
221
  return direction[0][readChar(ch) >> 7];
222
}
223
 
224
jbyte
225
java::lang::Character::getDirectionality(jint codePoint)
226
{
227
  jint plane = codePoint >> 16;
228
  if (plane < 0 || (plane > 2 && plane != 14))
229
    {
230
      if (plane > 14 && ((codePoint & 0xffff) < 0xfffe))
231
        return (jint) PRIVATE_DIRECTION;
232
      return (jint) UNASSIGNED_DIRECTION;
233
    }
234
  return direction[plane][readCodePoint(codePoint) >> 7];
235
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.