* src/vm/string.c (native/jni.h): Added.
[cacao.git] / src / vmcore / utf8.h
1 /* src/vmcore/utf8.h - utf8 string functions
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: utf8.h 7257 2007-01-29 23:07:40Z twisti $
26
27 */
28
29
30 #ifndef _UTF_H
31 #define _UTF_H
32
33 /* forward typedefs ***********************************************************/
34
35 typedef struct utf utf;
36
37 #include "config.h"
38
39 #include <stdio.h>
40
41 #include "vm/types.h"
42
43 #include "vm/global.h"
44
45
46 /* data structure for utf8 symbols ********************************************/
47
48 struct utf {
49         utf  *hashlink;                     /* link for external hash chain       */
50         s4    blength;                      /* text length in bytes               */
51         char *text;                         /* pointer to text                    */
52 };
53
54 /* to determine the end of utf strings */
55
56 #define UTF_END(u)    ((char *) u->text + u->blength)
57
58
59 /* utf-symbols for pointer comparison of frequently used strings **************/
60
61 extern utf *utf_java_lang_Object;
62
63 extern utf *utf_java_lang_Class;
64 extern utf *utf_java_lang_ClassLoader;
65 extern utf *utf_java_lang_Cloneable;
66 extern utf *utf_java_lang_SecurityManager;
67 extern utf *utf_java_lang_String;
68 extern utf *utf_java_lang_System;
69 extern utf *utf_java_lang_ThreadGroup;
70 extern utf *utf_java_io_Serializable;
71
72 extern utf *utf_java_lang_Throwable;
73 extern utf *utf_java_lang_Error;
74
75 extern utf *utf_java_lang_AbstractMethodError;
76 extern utf *utf_java_lang_ClassCircularityError;
77 extern utf *utf_java_lang_ClassFormatError;
78 extern utf *utf_java_lang_ExceptionInInitializerError;
79 extern utf *utf_java_lang_IncompatibleClassChangeError;
80 extern utf *utf_java_lang_InstantiationError;
81 extern utf *utf_java_lang_InternalError;
82 extern utf *utf_java_lang_LinkageError;
83 extern utf *utf_java_lang_NoClassDefFoundError;
84 extern utf *utf_java_lang_NoSuchFieldError;
85 extern utf *utf_java_lang_NoSuchMethodError;
86 extern utf *utf_java_lang_OutOfMemoryError;
87 extern utf *utf_java_lang_UnsatisfiedLinkError;
88 extern utf *utf_java_lang_UnsupportedClassVersionError;
89 extern utf *utf_java_lang_VerifyError;
90 extern utf *utf_java_lang_VirtualMachineError;
91
92 #if defined(WITH_CLASSPATH_GNU)
93 extern utf *utf_java_lang_VMThrowable;
94 #endif
95
96 extern utf *utf_java_lang_Exception;
97 extern utf *utf_java_lang_ArithmeticException;
98 extern utf *utf_java_lang_ArrayIndexOutOfBoundsException;
99 extern utf *utf_java_lang_ArrayStoreException;
100 extern utf *utf_java_lang_ClassCastException;
101 extern utf *utf_java_lang_ClassNotFoundException;
102 extern utf *utf_java_lang_CloneNotSupportedException;
103 extern utf *utf_java_lang_IllegalAccessException;
104 extern utf *utf_java_lang_IllegalArgumentException;
105 extern utf *utf_java_lang_IllegalMonitorStateException;
106 extern utf *utf_java_lang_InstantiationException;
107 extern utf *utf_java_lang_InterruptedException;
108 extern utf *utf_java_lang_InvocationTargetException;
109 extern utf *utf_java_lang_NegativeArraySizeException;
110 extern utf *utf_java_lang_NullPointerException;
111 extern utf *utf_java_lang_StringIndexOutOfBoundsException;
112
113 #if defined(ENABLE_JAVASE)
114 extern utf* utf_java_lang_Void;
115 #endif
116
117 extern utf* utf_java_lang_Boolean;
118 extern utf* utf_java_lang_Byte;
119 extern utf* utf_java_lang_Character;
120 extern utf* utf_java_lang_Short;
121 extern utf* utf_java_lang_Integer;
122 extern utf* utf_java_lang_Long;
123 extern utf* utf_java_lang_Float;
124 extern utf* utf_java_lang_Double;
125
126 #if defined(ENABLE_JAVASE)
127 extern utf *utf_java_lang_StackTraceElement;
128 extern utf *utf_java_lang_reflect_Constructor;
129 extern utf *utf_java_lang_reflect_Field;
130 extern utf *utf_java_lang_reflect_Method;
131 extern utf *utf_java_util_Vector;
132 #endif
133
134 extern utf *utf_InnerClasses;
135 extern utf *utf_ConstantValue;
136 extern utf *utf_Code;
137 extern utf *utf_Exceptions;
138 extern utf *utf_LineNumberTable;
139 extern utf *utf_SourceFile;
140
141 #if defined(ENABLE_JAVASE)
142 extern utf *utf_EnclosingMethod;
143 extern utf *utf_Signature;
144 extern utf *utf_RuntimeVisibleAnnotations;
145 extern utf *utf_StackMapTable;
146 #endif
147
148 extern utf *utf_init;
149 extern utf *utf_clinit;
150 extern utf *utf_clone;
151 extern utf *utf_finalize;
152 extern utf *utf_run;
153
154 extern utf *utf_add;
155 extern utf *utf_remove;
156 extern utf *utf_addThread;
157 extern utf *utf_removeThread;
158 extern utf *utf_put;
159 extern utf *utf_get;
160 extern utf *utf_value;
161
162 extern utf *utf_fillInStackTrace;
163 extern utf *utf_getSystemClassLoader;
164 extern utf *utf_loadClass;
165 extern utf *utf_printStackTrace;
166
167 extern utf *utf_Z;
168 extern utf *utf_B;
169 extern utf *utf_C;
170 extern utf *utf_S;
171 extern utf *utf_I;
172 extern utf *utf_J;
173 extern utf *utf_F;
174 extern utf *utf_D;
175
176 extern utf *utf_void__void;
177 extern utf *utf_boolean__void;
178 extern utf *utf_byte__void;
179 extern utf *utf_char__void;
180 extern utf *utf_short__void;
181 extern utf *utf_int__void;
182 extern utf *utf_long__void;
183 extern utf *utf_float__void;
184 extern utf *utf_double__void;
185
186 extern utf *utf_void__java_lang_ClassLoader;
187 extern utf *utf_void__java_lang_Object;
188 extern utf *utf_void__java_lang_Throwable;
189 extern utf *utf_java_lang_Object__java_lang_Object;
190 extern utf *utf_java_lang_String__void;
191 extern utf *utf_java_lang_String__java_lang_Class;
192 extern utf *utf_java_lang_Thread__V;
193 extern utf *utf_java_lang_Throwable__void;
194
195 extern utf *utf_not_named_yet;
196 extern utf *utf_null;
197 extern utf *array_packagename;
198
199
200 /* function prototypes ********************************************************/
201
202 /* initialize the utf8 subsystem */
203 bool utf8_init(void);
204
205 u4 utf_hashkey(const char *text, u4 length);
206 u4 utf_full_hashkey(const char *text, u4 length);
207
208 /* determine hashkey of a unicode-symbol */
209 u4 unicode_hashkey(u2 *text, u2 length);
210
211 /* create new utf-symbol */
212 utf *utf_new(const char *text, u2 length);
213
214 /* make utf symbol from u2 array */
215 utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
216
217 utf *utf_new_char(const char *text);
218 utf *utf_new_char_classname(const char *text);
219
220 /* get number of bytes */
221 u4 utf_bytes(utf *u);
222
223 /* get next unicode character of a utf-string */
224 u2 utf_nextu2(char **utf);
225
226 /* get (number of) unicode characters of a utf string (safe) */
227 s4 utf8_safe_number_of_u2s(const char *text, s4 nbytes);
228 void utf8_safe_convert_to_u2s(const char *text, s4 nbytes, u2 *buffer);
229
230 /* get (number of) unicode characters of a utf string (UNSAFE!) */
231 u4 utf_get_number_of_u2s(utf *u);
232 u4 utf_get_number_of_u2s_for_buffer(const char *buffer, u4 blength);
233
234 /* determine utf length in bytes of a u2 array */
235 u4 u2_utflength(u2 *text, u4 u2_length);
236
237 void utf_copy(char *buffer, utf *u);
238 void utf_cat(char *buffer, utf *u);
239 void utf_copy_classname(char *buffer, utf *u);
240 void utf_cat_classname(char *buffer, utf *u);
241
242 /* write utf symbol to file/buffer */
243 void utf_display_printable_ascii(utf *u);
244 void utf_display_printable_ascii_classname(utf *u);
245
246 void utf_sprint_convert_to_latin1(char *buffer, utf *u);
247 void utf_sprint_convert_to_latin1_classname(char *buffer, utf *u);
248
249 void utf_strcat_convert_to_latin1(char *buffer, utf *u);
250 void utf_strcat_convert_to_latin1_classname(char *buffer, utf *u);
251
252 void utf_fprint_printable_ascii(FILE *file, utf *u);
253 void utf_fprint_printable_ascii_classname(FILE *file, utf *u);
254
255 /* check if a UTF-8 string is valid */
256 bool is_valid_utf(char *utf_ptr, char *end_pos);
257
258 /* check if a UTF-8 string may be used as a class/field/method name */
259 bool is_valid_name(char *utf_ptr, char *end_pos);
260 bool is_valid_name_utf(utf *u);
261
262 /* show utf-table */
263 void utf_show(void);
264
265 #endif /* _UTF_H */
266
267
268 /*
269  * These are local overrides for various environment variables in Emacs.
270  * Please do not remove this and leave it at the end of the file, where
271  * Emacs will automagically detect them.
272  * ---------------------------------------------------------------------
273  * Local variables:
274  * mode: c
275  * indent-tabs-mode: t
276  * c-basic-offset: 4
277  * tab-width: 4
278  * End:
279  * vim:noexpandtab:sw=4:ts=4:
280  */