@@ -41,6 +41,7 @@ impl StringBuffer {
4141 JavaMethodProto :: new( "append" , "(J)Ljava/lang/StringBuffer;" , Self :: append_long, Default :: default ( ) ) ,
4242 JavaMethodProto :: new( "append" , "(C)Ljava/lang/StringBuffer;" , Self :: append_character, Default :: default ( ) ) ,
4343 JavaMethodProto :: new( "append" , "([CII)Ljava/lang/StringBuffer;" , Self :: append_char_array, Default :: default ( ) ) ,
44+ JavaMethodProto :: new( "delete" , "(II)Ljava/lang/StringBuffer;" , Self :: delete, Default :: default ( ) ) ,
4445 JavaMethodProto :: new( "toString" , "()Ljava/lang/String;" , Self :: to_string, Default :: default ( ) ) ,
4546 JavaMethodProto :: new( "setLength" , "(I)V" , Self :: set_length, Default :: default ( ) ) ,
4647 JavaMethodProto :: new( "length" , "()I" , Self :: length, Default :: default ( ) ) ,
@@ -174,6 +175,28 @@ impl StringBuffer {
174175 Ok ( this)
175176 }
176177
178+ async fn delete ( jvm : & Jvm , _: & mut RuntimeContext , mut this : ClassInstanceRef < Self > , start : i32 , end : i32 ) -> Result < ClassInstanceRef < Self > > {
179+ tracing:: debug!( "java.lang.StringBuffer::delete({this:?}, {start}, {end})" ) ;
180+
181+ let count: i32 = jvm. get_field ( & this, "count" , "I" ) . await ?;
182+
183+ let mut java_value: ClassInstanceRef < Array < JavaChar > > = jvm. get_field ( & this, "value" , "[C" ) . await ?;
184+ let chars: Vec < JavaChar > = jvm. load_array ( & java_value, 0 , count as _ ) . await ?;
185+
186+ let new_chars = chars
187+ . iter ( )
188+ . take ( start as _ )
189+ . chain ( chars. iter ( ) . skip ( end as _ ) )
190+ . cloned ( )
191+ . collect :: < Vec < _ > > ( ) ;
192+ let new_count = new_chars. len ( ) as i32 ;
193+
194+ jvm. store_array ( & mut java_value, 0 , new_chars) . await ?;
195+ jvm. put_field ( & mut this, "count" , "I" , new_count as i32 ) . await ?;
196+
197+ Ok ( this)
198+ }
199+
177200 async fn to_string ( jvm : & Jvm , _: & mut RuntimeContext , this : ClassInstanceRef < Self > ) -> Result < ClassInstanceRef < String > > {
178201 tracing:: debug!( "java.lang.StringBuffer::toString({:?})" , & this) ;
179202
0 commit comments