* src/vm/utf8.h, src/vm/utf8.c (utf8_safe_number_of_u2s): Modified to
[cacao.git] / src / vm / utf8.h
1 /* src/vm/utf8.h - utf8 string functions
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    Changes: Edwin Steiner
30
31    $Id: utf8.h 5823 2006-10-24 23:24:19Z edwin $
32
33 */
34
35
36 #ifndef _UTF_H
37 #define _UTF_H
38
39 #include "config.h"
40
41 #include <stdio.h>
42
43 /* forward typedefs ***********************************************************/
44
45 typedef struct utf utf;
46
47 #include "vm/types.h"
48 #include "vm/global.h"
49
50
51 /* data structure for utf8 symbols ********************************************/
52
53 struct utf {
54         utf  *hashlink;                     /* link for external hash chain       */
55         s4    blength;                      /* text length in bytes               */
56         char *text;                         /* pointer to text                    */
57 };
58
59 /* to determine the end of utf strings */
60
61 #define UTF_END(u)    ((char *) u->text + u->blength)
62
63
64 /* utf-symbols for pointer comparison of frequently used strings **************/
65
66 extern utf *utf_java_lang_Object;
67
68 extern utf *utf_java_lang_Class;
69 extern utf *utf_java_lang_ClassLoader;
70 extern utf *utf_java_lang_Cloneable;
71 extern utf *utf_java_lang_SecurityManager;
72 extern utf *utf_java_lang_String;
73 extern utf *utf_java_lang_System;
74 extern utf *utf_java_lang_ThreadGroup;
75 extern utf *utf_java_io_Serializable;
76
77 extern utf *utf_java_lang_Throwable;
78 extern utf *utf_java_lang_VMThrowable;
79 extern utf *utf_java_lang_Error;
80 extern utf *utf_java_lang_AbstractMethodError;
81 extern utf *utf_java_lang_LinkageError;
82 extern utf *utf_java_lang_NoClassDefFoundError;
83 extern utf *utf_java_lang_NoSuchMethodError;
84 extern utf *utf_java_lang_OutOfMemoryError;
85
86 extern utf *utf_java_lang_Exception;
87 extern utf *utf_java_lang_ClassCastException;
88 extern utf *utf_java_lang_ClassNotFoundException;
89 extern utf *utf_java_lang_IllegalArgumentException;
90 extern utf *utf_java_lang_IllegalMonitorStateException;
91
92 extern utf *utf_java_lang_NullPointerException;
93
94 extern utf* utf_java_lang_Void;
95 extern utf* utf_java_lang_Boolean;
96 extern utf* utf_java_lang_Byte;
97 extern utf* utf_java_lang_Character;
98 extern utf* utf_java_lang_Short;
99 extern utf* utf_java_lang_Integer;
100 extern utf* utf_java_lang_Long;
101 extern utf* utf_java_lang_Float;
102 extern utf* utf_java_lang_Double;
103
104 extern utf *utf_java_lang_StackTraceElement;
105 extern utf *utf_java_lang_reflect_Constructor;
106 extern utf *utf_java_lang_reflect_Field;
107 extern utf *utf_java_lang_reflect_Method;
108 extern utf *utf_java_util_Vector;
109
110
111 extern utf *utf_InnerClasses;
112 extern utf *utf_ConstantValue;
113 extern utf *utf_Code;
114 extern utf *utf_Exceptions;
115 extern utf *utf_LineNumberTable;
116 extern utf *utf_SourceFile;
117
118 extern utf *utf_init;
119 extern utf *utf_clinit;
120 extern utf *utf_clone;
121 extern utf *utf_finalize;
122 extern utf *utf_run;
123
124 extern utf *utf_add;
125 extern utf *utf_remove;
126 extern utf *utf_removeThread;
127 extern utf *utf_put;
128 extern utf *utf_get;
129 extern utf *utf_value;
130
131 extern utf *utf_fillInStackTrace;
132 extern utf *utf_getSystemClassLoader;
133 extern utf *utf_loadClass;
134 extern utf *utf_printStackTrace;
135
136 extern utf *utf_Z;
137 extern utf *utf_B;
138 extern utf *utf_C;
139 extern utf *utf_S;
140 extern utf *utf_I;
141 extern utf *utf_J;
142 extern utf *utf_F;
143 extern utf *utf_D;
144
145 extern utf *utf_void__void;
146 extern utf *utf_boolean__void;
147 extern utf *utf_byte__void;
148 extern utf *utf_char__void;
149 extern utf *utf_short__void;
150 extern utf *utf_int__void;
151 extern utf *utf_long__void;
152 extern utf *utf_float__void;
153 extern utf *utf_double__void;
154
155 extern utf *utf_void__java_lang_ClassLoader;
156 extern utf *utf_void__java_lang_Object;
157 extern utf *utf_void__java_lang_Throwable;
158 extern utf *utf_java_lang_Object__java_lang_Object;
159 extern utf *utf_java_lang_String__void;
160 extern utf *utf_java_lang_String__java_lang_Class;
161 extern utf *utf_java_lang_Thread__V;
162 extern utf *utf_java_lang_Throwable__void;
163
164 extern utf *utf_not_named_yet;
165 extern utf *utf_null;
166 extern utf *array_packagename;
167
168
169 /* function prototypes ********************************************************/
170
171 /* initialize the utf8 subsystem */
172 bool utf8_init(void);
173
174 u4 utf_hashkey(const char *text, u4 length);
175 u4 utf_full_hashkey(const char *text, u4 length);
176
177 /* determine hashkey of a unicode-symbol */
178 u4 unicode_hashkey(u2 *text, u2 length);
179
180 /* create new utf-symbol */
181 utf *utf_new(const char *text, u2 length);
182
183 /* make utf symbol from u2 array */
184 utf *utf_new_u2(u2 *unicodedata, u4 unicodelength, bool isclassname);
185
186 utf *utf_new_char(const char *text);
187 utf *utf_new_char_classname(const char *text);
188
189 /* get number of bytes */
190 u4 utf_bytes(utf *u);
191
192 /* get next unicode character of a utf-string */
193 u2 utf_nextu2(char **utf);
194
195 /* get (number of) unicode characters of a utf string (safe) */
196 s4 utf8_safe_number_of_u2s(const char *text, s4 nbytes);
197 void utf8_safe_convert_to_u2s(const char *text, s4 nbytes, u2 *buffer);
198
199 /* get (number of) unicode characters of a utf string (UNSAFE!) */
200 u4 utf_get_number_of_u2s(utf *u);
201 u4 utf_get_number_of_u2s_for_buffer(const char *buffer, u4 blength);
202
203 /* determine utf length in bytes of a u2 array */
204 u4 u2_utflength(u2 *text, u4 u2_length);
205
206 void utf_copy(char *buffer, utf *u);
207 void utf_cat(char *buffer, utf *u);
208 void utf_copy_classname(char *buffer, utf *u);
209 void utf_cat_classname(char *buffer, utf *u);
210
211 /* write utf symbol to file/buffer */
212 void utf_display_printable_ascii(utf *u);
213 void utf_display_printable_ascii_classname(utf *u);
214
215 void utf_sprint_convert_to_latin1(char *buffer, utf *u);
216 void utf_sprint_convert_to_latin1_classname(char *buffer, utf *u);
217
218 void utf_strcat_convert_to_latin1(char *buffer, utf *u);
219 void utf_strcat_convert_to_latin1_classname(char *buffer, utf *u);
220
221 void utf_fprint_printable_ascii(FILE *file, utf *u);
222 void utf_fprint_printable_ascii_classname(FILE *file, utf *u);
223
224 /* check if a UTF-8 string is valid */
225 bool is_valid_utf(char *utf_ptr, char *end_pos);
226
227 /* check if a UTF-8 string may be used as a class/field/method name */
228 bool is_valid_name(char *utf_ptr, char *end_pos);
229 bool is_valid_name_utf(utf *u);
230
231 /* show utf-table */
232 void utf_show(void);
233
234 #endif /* _UTF_H */
235
236
237 /*
238  * These are local overrides for various environment variables in Emacs.
239  * Please do not remove this and leave it at the end of the file, where
240  * Emacs will automagically detect them.
241  * ---------------------------------------------------------------------
242  * Local variables:
243  * mode: c
244  * indent-tabs-mode: t
245  * c-basic-offset: 4
246  * tab-width: 4
247  * End:
248  * vim:noexpandtab:sw=4:ts=4:
249  */