mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:37:35 +00:00
LibJS: Use AK::String::index_of() for StringPrototype::index_of()
This commit is contained in:
parent
bf5b251684
commit
71d6459b7f
1 changed files with 1 additions and 6 deletions
|
@ -138,12 +138,7 @@ Value StringPrototype::index_of(Interpreter& interpreter)
|
|||
needle_value = interpreter.argument(0);
|
||||
auto needle = needle_value.to_string();
|
||||
auto haystack = static_cast<const StringObject*>(this_object)->primitive_string()->string();
|
||||
|
||||
// FIXME: We should have a helper in AK::String for this.
|
||||
auto* ptr = strstr(haystack.characters(), needle.characters());
|
||||
if (!ptr)
|
||||
return Value(-1);
|
||||
return Value((i32)(ptr - haystack.characters()));
|
||||
return Value((i32)haystack.index_of(needle).value_or(-1));
|
||||
}
|
||||
|
||||
static StringObject* string_object_from(Interpreter& interpreter)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue