* src/vmcore/linker.c (build_display): Removed superfluous recursion; return
[cacao.git] / src / native / vm / gnuclasspath / gnu_java_lang_VMCPStringBuilder.c
1 /* src/native/vm/gnu/java_lang_reflect_VMConstructor.c
2
3    Copyright (C) 1996-2005, 2006, 2007, 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 #include "native/include/gnu_java_lang_VMCPStringBuilder.h"
37
38 #include "vm/builtin.h"
39 #include "vm/exceptions.h"
40
41
42 /* native methods implemented by this file ************************************/
43
44 static JNINativeMethod methods[] = {
45         { "toString", "([CII)Ljava/lang/String;", (void *) (intptr_t) &Java_gnu_java_lang_VMCPStringBuilder_toString },
46 };
47
48
49 /* _Jv_gnu_java_lang_VMCPStringBuilder *****************************************
50
51    Register native functions.
52
53 *******************************************************************************/
54
55 void _Jv_gnu_java_lang_VMCPStringBuilder_init(void)
56 {
57         utf *u;
58
59         u = utf_new_char("gnu/java/lang/VMCPStringBuilder");
60
61         native_method_register(u, methods, NATIVE_METHODS_COUNT);
62 }
63
64
65 /*
66  * Class:     gnu/java/lang/VMCPStringBuilder
67  * Method:    toString
68  * Signature: ([CII)Ljava/lang/String;
69  */
70 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)
71 {
72         int32_t          length;
73         java_handle_t    *o;
74         java_lang_String *s;
75
76         /* This is a native version of
77            java.lang.String.<init>([CIIZ)Ljava/lang/String; */
78
79     if (startIndex < 0) {
80 /*              exceptions_throw_stringindexoutofboundsexception("offset: " + offset); */
81                 exceptions_throw_stringindexoutofboundsexception();
82                 return NULL;
83         }
84
85     if (count < 0) {
86 /*              exceptions_throw_stringindexoutofboundsexception("count: " + count); */
87                 exceptions_throw_stringindexoutofboundsexception();
88                 return NULL;
89         }
90
91     /* equivalent to: offset + count < 0 || offset + count > data.length */
92
93         LLNI_CRITICAL_START;
94         length = LLNI_array_size(value);
95         LLNI_CRITICAL_END;
96
97     if (length - startIndex < count) {
98 /*              exceptions_throw_stringindexoutofboundsexception("offset + count: " + (offset + count)); */
99                 exceptions_throw_stringindexoutofboundsexception();
100                 return NULL;
101         }
102
103         o = builtin_new(class_java_lang_String);
104
105         if (o == NULL)
106                 return NULL;
107
108         s = (java_lang_String *) o;
109
110         LLNI_field_set_ref(s, value,  value);
111         LLNI_field_set_val(s, count,  count);
112         LLNI_field_set_val(s, offset, startIndex);
113
114         return s;
115 }
116
117
118 /*
119  * These are local overrides for various environment variables in Emacs.
120  * Please do not remove this and leave it at the end of the file, where
121  * Emacs will automagically detect them.
122  * ---------------------------------------------------------------------
123  * Local variables:
124  * mode: c
125  * indent-tabs-mode: t
126  * c-basic-offset: 4
127  * tab-width: 4
128  * End:
129  */