mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
AK: Add String{View,}::find(StringView)
I personally mistook `find_first_of(StringView)` to be analogous to this so let's add a `find()` method that actually searches the string.
This commit is contained in:
parent
4fa8435310
commit
39442e6d4f
8 changed files with 70 additions and 11 deletions
|
@ -25,6 +25,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/MemMem.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
|
@ -342,6 +343,13 @@ StringView trim_whitespace(const StringView& str, TrimMode mode)
|
|||
|
||||
return str.substring_view(substring_start, substring_length);
|
||||
}
|
||||
|
||||
Optional<size_t> find(const StringView& haystack, const StringView& needle)
|
||||
{
|
||||
return AK::memmem_optional(
|
||||
haystack.characters_without_null_termination(), haystack.length(),
|
||||
needle.characters_without_null_termination(), needle.length());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue