@@ -60,6 +60,7 @@ impl String {
6060 JavaMethodProto :: new( "indexOf" , "(II)I" , Self :: index_of_from, Default :: default ( ) ) ,
6161 JavaMethodProto :: new( "indexOf" , "(Ljava/lang/String;)I" , Self :: index_of_string, Default :: default ( ) ) ,
6262 JavaMethodProto :: new( "indexOf" , "(Ljava/lang/String;I)I" , Self :: index_of_string_from, Default :: default ( ) ) ,
63+ JavaMethodProto :: new( "lastIndexOf" , "(I)I" , Self :: last_index_of, Default :: default ( ) ) ,
6364 JavaMethodProto :: new( "trim" , "()Ljava/lang/String;" , Self :: trim, Default :: default ( ) ) ,
6465 JavaMethodProto :: new( "startsWith" , "(Ljava/lang/String;)Z" , Self :: starts_with, Default :: default ( ) ) ,
6566 JavaMethodProto :: new( "startsWith" , "(Ljava/lang/String;I)Z" , Self :: starts_with_offset, Default :: default ( ) ) ,
@@ -373,6 +374,21 @@ impl String {
373374 Ok ( index. unwrap_or ( -1 ) )
374375 }
375376
377+ async fn last_index_of ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > , ch : i32 ) -> Result < i32 > {
378+ tracing:: debug!( "java.lang.String::lastIndexOf({:?}, {:?})" , & this, ch) ;
379+
380+ let this_string = JavaLangString :: to_rust_string ( jvm, & this. clone ( ) ) . await ?;
381+
382+ let index = this_string
383+ . chars ( )
384+ . collect :: < Vec < _ > > ( ) // TODO i think we don't need collect..
385+ . into_iter ( )
386+ . rposition ( |x| x as u32 == ch as u32 )
387+ . map ( |x| x as i32 ) ;
388+
389+ Ok ( index. unwrap_or ( -1 ) )
390+ }
391+
376392 async fn trim ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < ClassInstanceRef < Self > > {
377393 tracing:: debug!( "java.lang.String::trim({:?})" , & this) ;
378394
0 commit comments