diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-24 11:50:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-24 11:59:18 +0200 |
commit | de395a3df236eb653db78b5b88a0178036f99ba0 (patch) | |
tree | 2a6bd2f6126aa62650fc92092eaa4d88ebebc19e /Userland/Libraries/LibJS | |
parent | 875a2cbb7150b036af343364a8bf2d07a97dd03d (diff) | |
download | serenity-de395a3df236eb653db78b5b88a0178036f99ba0.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 284a3027cc..826206d041 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -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); |