Line data Source code
1 : /* src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp
2 :
3 : Copyright (C) 2008-2013
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.hpp"
31 : #include "native/llni.hpp"
32 : #include "native/native.hpp"
33 :
34 : #if defined(ENABLE_JNI_HEADERS)
35 : # include "native/vm/include/gnu_java_lang_VMCPStringBuilder.h"
36 : #endif
37 :
38 : #include "vm/array.hpp"
39 : #include "vm/jit/builtin.hpp"
40 : #include "vm/exceptions.hpp"
41 : #include "vm/globals.hpp"
42 : #include "vm/javaobjects.hpp"
43 : #include "vm/vm.hpp"
44 :
45 : /*
46 : * Class: gnu/java/lang/VMCPStringBuilder
47 : * Method: toString
48 : * Signature: ([CII)Ljava/lang/String;
49 : */
50 499 : JNIEXPORT jstring JNICALL Java_gnu_java_lang_VMCPStringBuilder_toString(JNIEnv *env, jclass clazz, jcharArray value, jint startIndex, jint count)
51 : {
52 : /* This is a native version of
53 : java.lang.String.<init>([CIIZ)Ljava/lang/String; */
54 :
55 499 : if (startIndex < 0) {
56 : /* exceptions_throw_stringindexoutofboundsexception("offset: " + offset); */
57 0 : exceptions_throw_stringindexoutofboundsexception();
58 0 : return NULL;
59 : }
60 :
61 499 : if (count < 0) {
62 : /* exceptions_throw_stringindexoutofboundsexception("count: " + count); */
63 0 : exceptions_throw_stringindexoutofboundsexception();
64 0 : return NULL;
65 : }
66 :
67 : /* equivalent to: offset + count < 0 || offset + count > data.length */
68 :
69 499 : CharArray ca(value);
70 :
71 499 : if (ca.get_length() - startIndex < count) {
72 : /* exceptions_throw_stringindexoutofboundsexception("offset + count: " + (offset + count)); */
73 0 : exceptions_throw_stringindexoutofboundsexception();
74 0 : return NULL;
75 : }
76 :
77 499 : return (jstring) (java_handle_t*) JavaString::from_array(ca.get_handle(), count, startIndex);
78 : }
79 :
80 :
81 : /* native methods implemented by this file ************************************/
82 :
83 : static JNINativeMethod methods[] = {
84 : { (char*) "toString", (char*) "([CII)Ljava/lang/String;", (void*) (uintptr_t) &Java_gnu_java_lang_VMCPStringBuilder_toString },
85 : };
86 :
87 :
88 : /* _Jv_gnu_java_lang_VMCPStringBuilder *****************************************
89 :
90 : Register native functions.
91 :
92 : *******************************************************************************/
93 :
94 163 : void _Jv_gnu_java_lang_VMCPStringBuilder_init(void)
95 : {
96 163 : Utf8String u = Utf8String::from_utf8("gnu/java/lang/VMCPStringBuilder");
97 :
98 163 : NativeMethods& nm = VM::get_current()->get_nativemethods();
99 163 : nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
100 163 : }
101 :
102 :
103 : /*
104 : * These are local overrides for various environment variables in Emacs.
105 : * Please do not remove this and leave it at the end of the file, where
106 : * Emacs will automagically detect them.
107 : * ---------------------------------------------------------------------
108 : * Local variables:
109 : * mode: c++
110 : * indent-tabs-mode: t
111 : * c-basic-offset: 4
112 : * tab-width: 4
113 : * End:
114 : */
|