mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:07:34 +00:00
AK+Everywhere: Consolidate String::index_of() and String::find()
We had two functions for doing mostly the same thing. Combine both of them into String::find() and use that everywhere. Also add some tests to cover basic behavior.
This commit is contained in:
parent
875a2cbb71
commit
de395a3df2
12 changed files with 36 additions and 30 deletions
|
@ -240,7 +240,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of)
|
|||
auto needle = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
return Value((i32)string.index_of(needle).value_or(-1));
|
||||
return Value((i32)string.find(needle).value_or(-1));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
|
||||
|
@ -692,7 +692,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
|
|||
auto search_string = search_value.to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
Optional<size_t> position = string.index_of(search_string);
|
||||
Optional<size_t> position = string.find(search_string);
|
||||
if (!position.has_value())
|
||||
return js_string(vm, string);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue