* Merged with de18881369d4.
[cacao.git] / src / native / vm / gnuclasspath / gnu_java_lang_VMCPStringBuilder.cpp
1 /* src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp
2
3    Copyright (C) 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdint.h>
29
30 #include "native/jni.h"
31 #include "native/llni.h"
32 #include "native/native.h"
33
34 #include "native/include/java_lang_String.h"
35
36 // FIXME
37 extern "C" {
38 #include "native/include/gnu_java_lang_VMCPStringBuilder.h"
39 }
40
41 #include "vm/builtin.h"
42 #include "vm/exceptions.h"
43
44
45 /*
46  * Class:     gnu/java/lang/VMCPStringBuilder
47  * Method:    toString
48  * Signature: ([CII)Ljava/lang/String;
49  */
50 JNIEXPORT java_lang_String* JNICALL Java_gnu_java_lang_VMCPStringBuilder_toString(JNIEnv *env, jclass clazz, java_handle_chararray_t *value, int32_t startIndex, int32_t count)
51 {
52         int32_t          length;
53         java_handle_t    *o;
54         java_lang_String *s;
55
56         /* This is a native version of
57            java.lang.String.<init>([CIIZ)Ljava/lang/String; */
58
59     if (startIndex < 0) {
60 /*              exceptions_throw_stringindexoutofboundsexception("offset: " + offset); */
61                 exceptions_throw_stringindexoutofboundsexception();
62                 return NULL;
63         }
64
65     if (count < 0) {
66 /*              exceptions_throw_stringindexoutofboundsexception("count: " + count); */
67                 exceptions_throw_stringindexoutofboundsexception();
68                 return NULL;
69         }
70
71     /* equivalent to: offset + count < 0 || offset + count > data.length */
72
73         LLNI_CRITICAL_START;
74         length = LLNI_array_size(value);
75         LLNI_CRITICAL_END;
76
77     if (length - startIndex < count) {
78 /*              exceptions_throw_stringindexoutofboundsexception("offset + count: " + (offset + count)); */
79                 exceptions_throw_stringindexoutofboundsexception();
80                 return NULL;
81         }
82
83         o = builtin_new(class_java_lang_String);
84
85         if (o == NULL)
86                 return NULL;
87
88         s = (java_lang_String *) o;
89
90         LLNI_field_set_ref(s, value,  value);
91         LLNI_field_set_val(s, count,  count);
92         LLNI_field_set_val(s, offset, startIndex);
93
94         return s;
95 }
96
97
98 /* native methods implemented by this file ************************************/
99
100 static JNINativeMethod methods[] = {
101         { (char*) "toString", (char*) "([CII)Ljava/lang/String;", (void*) (uintptr_t) &Java_gnu_java_lang_VMCPStringBuilder_toString },
102 };
103
104
105 /* _Jv_gnu_java_lang_VMCPStringBuilder *****************************************
106
107    Register native functions.
108
109 *******************************************************************************/
110
111 // FIXME
112 extern "C" {
113 void _Jv_gnu_java_lang_VMCPStringBuilder_init(void)
114 {
115         utf *u;
116
117         u = utf_new_char("gnu/java/lang/VMCPStringBuilder");
118
119         native_method_register(u, methods, NATIVE_METHODS_COUNT);
120 }
121 }
122
123
124 /*
125  * These are local overrides for various environment variables in Emacs.
126  * Please do not remove this and leave it at the end of the file, where
127  * Emacs will automagically detect them.
128  * ---------------------------------------------------------------------
129  * Local variables:
130  * mode: c++
131  * indent-tabs-mode: t
132  * c-basic-offset: 4
133  * tab-width: 4
134  * End:
135  */