* src/vm/array.hpp: Implemented array access classes in C++.
[cacao.git] / src / native / vm / cldc1.1 / java_lang_String.cpp
index 921ae0d7086c3542c142a2f9a3c08667bf193d23..a1f72ae7448efcd67ebf7bdca976aa1afa410221 100644 (file)
@@ -30,8 +30,7 @@
 #include <string.h>
 
 #include "native/jni.hpp"
-#include "native/llni.h"
-#include "native/native.h"
+#include "native/native.hpp"
 
 #if defined(ENABLE_JNI_HEADERS)
 # include "native/include/java_lang_String.h"
@@ -53,14 +52,15 @@ JNIEXPORT jint JNICALL Java_java_lang_String_hashCode(JNIEnv *env, jstring _this
 {
        java_lang_String jls(_this);
 
-       java_handle_chararray_t* value = jls.get_value();
+       CharArray value(jls.get_value());
+
        int32_t offset = jls.get_offset();
        int32_t count  = jls.get_count();
 
        int32_t hash = 0;
 
        for (int32_t i = 0; i < count; i++) {
-               hash = (31 * hash) + LLNI_array_direct(value, offset + i);
+               hash = (31 * hash) + value.get_element(offset + i);
        }
 
        return hash;
@@ -76,12 +76,13 @@ JNIEXPORT jint JNICALL Java_java_lang_String_indexOf__I(JNIEnv *env, jstring _th
 {
        java_lang_String jls(_this);
 
-       java_handle_chararray_t* value = jls.get_value();
+       CharArray value(jls.get_value());
+
        int32_t offset = jls.get_offset();
        int32_t count  = jls.get_count();
 
        for (int32_t i = 0; i < count; i++) {
-               if (LLNI_array_direct(value, offset + i) == ch) {
+               if (value.get_element(offset + i) == ch) {
                        return i;
                }
        }
@@ -99,7 +100,8 @@ JNIEXPORT jint JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, jstring _t
 {
        java_lang_String jls(_this);
 
-       java_handle_chararray_t* value = jls.get_value();
+       CharArray value(jls.get_value());
+
        int32_t offset = jls.get_offset();
        int32_t count  = jls.get_count();
 
@@ -112,7 +114,7 @@ JNIEXPORT jint JNICALL Java_java_lang_String_indexOf__II(JNIEnv *env, jstring _t
        }
 
        for (int32_t i = fromIndex ; i < count ; i++) {
-               if (LLNI_array_direct(value, offset + i) == ch) {
+               if (value.get_element(offset + i) == ch) {
                        return i;
                }
        }
@@ -130,14 +132,15 @@ JNIEXPORT jint JNICALL Java_java_lang_String_lastIndexOf__II(JNIEnv *env, jstrin
 {
        java_lang_String jls(_this);
 
-       java_handle_chararray_t* value = jls.get_value();
+       CharArray value(jls.get_value());
+
        int32_t offset = jls.get_offset();
        int32_t count  = jls.get_count();
 
        int32_t start = ((fromIndex >= count) ? count - 1 : fromIndex);
 
        for (int32_t i = start; i >= 0; i--) {
-               if (LLNI_array_direct(value, offset + i) == ch) {
+               if (value.get_element(offset + i) == ch) {
                        return i;
                }
        }
@@ -198,16 +201,12 @@ static JNINativeMethod methods[] = {
  
 *******************************************************************************/
  
-// FIXME
-extern "C" {
 void _Jv_java_lang_String_init(void)
 {
-       utf *u;
-       u = utf_new_char("java/lang/String");
+       utf* u = utf_new_char("java/lang/String");
  
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }