1 /* src/native/vm/cldc1.1/java_lang_String.c
3 Copyright (C) 2006, 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
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.
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.
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
25 $Id: java_lang_VMRuntime.c 5900 2006-11-04 17:30:44Z michi $
37 #include "native/jni.h"
38 #include "native/native.h"
39 #include "native/include/java_lang_String.h"
40 #include "native/include/java_lang_Object.h"
41 #include "vm/stringlocal.h"
45 * Class: java/lang/String
49 JNIEXPORT s4 JNICALL Java_java_lang_String_hashCode(JNIEnv *env, java_lang_String *this)
51 java_chararray *value;
57 /* get values from Java object */
59 offset = this->offset;
65 for (i = 0; i < count; i++) {
66 hash = (31 * hash) + value->data[offset + i];
74 * Class: java/lang/String
78 JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__I(JNIEnv *env, java_lang_String *this, s4 ch)
80 java_chararray *value;
85 /* get values from Java object */
87 offset = this->offset;
91 for (i = 0; i < count; i++) {
92 if (value->data[offset + i] == ch) {
102 * Class: java/lang/String
106 JNIEXPORT s4 JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, java_lang_String *this, s4 ch, s4 fromIndex)
108 java_chararray *value;
113 /* get values from Java object */
115 offset = this->offset;
122 else if (fromIndex >= count) {
123 /* Note: fromIndex might be near -1>>>1. */
127 for (i = fromIndex ; i < count ; i++) {
128 if (value->data[offset + i] == ch) {
138 * Class: java/lang/String
139 * Method: lastIndexOf
142 JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__I(JNIEnv *env, java_lang_String *this, s4 ch)
144 return Java_java_lang_String_lastIndexOf__II(env, this, ch, this->count - 1);
149 * Class: java/lang/String
150 * Method: lastIndexOf
153 JNIEXPORT s4 JNICALL Java_java_lang_String_lastIndexOf__II(JNIEnv *env, java_lang_String *this, s4 ch, s4 fromIndex)
155 java_chararray *value;
161 /* get values from Java object */
163 offset = this->offset;
167 start = ((fromIndex >= count) ? count - 1 : fromIndex);
169 for (i = start; i >= 0; i--) {
170 if (value->data[offset + i] == ch) {
181 * Class: java/lang/String
183 * Signature: (Ljava/lang/Object;)Z;
185 JNIEXPORT s4 JNICALL Java_java_lang_String_equals(JNIEnv *env, java_lang_String* this, java_lang_Object *o)
189 /* TODO: is this the correct implementation for short-circuiting on object identity? */
190 if ((java_lang_Object*)this == o)
193 if (o->header.vftbl->class != class_java_lang_String)
196 s = (java_lang_String *) o;
198 if (this->count != s->count)
201 return ( 0 == memcmp((void*)(this->value->data + this->offset),
202 (void*)(s->value->data + s->offset),
209 * Class: java/lang/String
211 * Signature: ()Ljava/lang/String;
213 JNIEXPORT java_lang_String* JNICALL Java_java_lang_String_intern(JNIEnv *env, java_lang_String *this)
215 java_objectheader *o;
220 /* search table so identical strings will get identical pointers */
222 o = literalstring_u2(this->value, this->count, this->offset, true);
224 return (java_lang_String *) o;
229 * These are local overrides for various environment variables in Emacs.
230 * Please do not remove this and leave it at the end of the file, where
231 * Emacs will automagically detect them.
232 * ---------------------------------------------------------------------
235 * indent-tabs-mode: t