* src/vm/array.hpp: Implemented array access classes in C++.
[cacao.git] / src / native / vm / cldc1.1 / java_lang_String.cpp
index 54b3f7e50cc8857e83ffa025527f9ec2f33cdbd9..a1f72ae7448efcd67ebf7bdca976aa1afa410221 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
+#include "native/jni.hpp"
+#include "native/native.hpp"
 
 #if defined(ENABLE_JNI_HEADERS)
 # include "native/include/java_lang_String.h"
 #endif
 
+#include "vm/javaobjects.hpp"
 #include "vm/string.hpp"
 
-#include "vmcore/javaobjects.hpp"
-
 
 // Native functions are exported as C functions.
 extern "C" {
@@ -54,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;
@@ -77,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;
                }
        }
@@ -100,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();
 
@@ -113,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;
                }
        }
@@ -131,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;
                }
        }
@@ -199,16 +201,12 @@ static JNINativeMethod methods[] = {
  
 *******************************************************************************/
  
-// FIXME
-extern "C" {
 void _Jv_java_lang_String_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/String");
  
-       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);
 }