@@ -273,6 +273,15 @@ fn string_upper(actor: &mut Actor, s: Value) -> Result<Value, String>
273273 Ok ( actor. alloc . str_val ( & s) . unwrap ( ) )
274274}
275275
276+ /// Lowercase a String
277+ fn string_lower ( actor : & mut Actor , s : Value ) -> Result < Value , String >
278+ {
279+ let s = unwrap_str ! ( s) ;
280+ let s = s. to_lowercase ( ) ;
281+ actor. gc_check ( size_of :: < Str > ( ) + s. len ( ) , & mut [ ] ) ;
282+ Ok ( actor. alloc . str_val ( & s) . unwrap ( ) )
283+ }
284+
276285/// Split a string by a separator and return an array of strings
277286fn string_split ( actor : & mut Actor , mut input : Value , sep : Value ) -> Result < Value , String >
278287{
@@ -396,6 +405,7 @@ pub fn get_method(val: Value, method_name: &str) -> Value
396405 static STRING_PARSE_INT : HostFn = HostFn { name : "parse_int" , f : Fn2 ( string_parse_int) } ;
397406 static STRING_TRIM : HostFn = HostFn { name : "trim" , f : Fn1 ( string_trim) } ;
398407 static STRING_UPPER : HostFn = HostFn { name : "upper" , f : Fn1 ( string_upper) } ;
408+ static STRING_LOWER : HostFn = HostFn { name : "lower" , f : Fn1 ( string_lower) } ;
399409 static STRING_SPLIT : HostFn = HostFn { name : "split" , f : Fn2 ( string_split) } ;
400410 static STRING_TO_S : HostFn = HostFn { name : "to_s" , f : Fn1 ( identity_method) } ;
401411
@@ -458,6 +468,7 @@ pub fn get_method(val: Value, method_name: &str) -> Value
458468 ( Value :: String ( _) , "parse_int" ) => & STRING_PARSE_INT ,
459469 ( Value :: String ( _) , "trim" ) => & STRING_TRIM ,
460470 ( Value :: String ( _) , "upper" ) => & STRING_UPPER ,
471+ ( Value :: String ( _) , "lower" ) => & STRING_LOWER ,
461472 ( Value :: String ( _) , "split" ) => & STRING_SPLIT ,
462473 ( Value :: String ( _) , "to_s" ) => & STRING_TO_S ,
463474
0 commit comments