Home | History | Annotate | Download | only in native
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "common_throws.h"
     18 #include "jni_internal.h"
     19 #include "mirror/string.h"
     20 #include "scoped_thread_state_change.h"
     21 #include "ScopedLocalRef.h"
     22 
     23 namespace art {
     24 
     25 static jint String_compareTo(JNIEnv* env, jobject javaThis, jobject javaRhs) {
     26   ScopedObjectAccess soa(env);
     27   if (UNLIKELY(javaRhs == NULL)) {
     28     ThrowNullPointerException(NULL, "rhs == null");
     29     return -1;
     30   } else {
     31     return soa.Decode<mirror::String*>(javaThis)->CompareTo(soa.Decode<mirror::String*>(javaRhs));
     32   }
     33 }
     34 
     35 static jint String_fastIndexOf(JNIEnv* env, jobject java_this, jint ch, jint start) {
     36   ScopedObjectAccess soa(env);
     37   // This method does not handle supplementary characters. They're dealt with in managed code.
     38   DCHECK_LE(ch, 0xffff);
     39 
     40   mirror::String* s = soa.Decode<mirror::String*>(java_this);
     41   return s->FastIndexOf(ch, start);
     42 }
     43 
     44 static jstring String_intern(JNIEnv* env, jobject javaThis) {
     45   ScopedObjectAccess soa(env);
     46   mirror::String* s = soa.Decode<mirror::String*>(javaThis);
     47   mirror::String* result = s->Intern();
     48   return soa.AddLocalReference<jstring>(result);
     49 }
     50 
     51 static JNINativeMethod gMethods[] = {
     52   NATIVE_METHOD(String, compareTo, "(Ljava/lang/String;)I"),
     53   NATIVE_METHOD(String, fastIndexOf, "(II)I"),
     54   NATIVE_METHOD(String, intern, "()Ljava/lang/String;"),
     55 };
     56 
     57 void register_java_lang_String(JNIEnv* env) {
     58   REGISTER_NATIVE_METHODS("java/lang/String");
     59 }
     60 
     61 }  // namespace art
     62