mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-05 09:52:54 +00:00
AK: Add case insensitive version of starts_with
This commit is contained in:
parent
ccc929dcf9
commit
a5ecb9bd6b
Notes:
sideshowbarker
2024-07-19 04:42:15 +09:00
Author: https://github.com/Lubrsi
Commit: a5ecb9bd6b
Pull-request: https://github.com/SerenityOS/serenity/pull/2842
11 changed files with 53 additions and 20 deletions
|
@ -202,6 +202,31 @@ bool ends_with(const StringView& str, const StringView& end, CaseSensitivity cas
|
|||
return true;
|
||||
}
|
||||
|
||||
bool starts_with(const StringView& str, const StringView& start, CaseSensitivity case_sensitivity)
|
||||
{
|
||||
if (start.is_empty())
|
||||
return true;
|
||||
if (str.is_empty())
|
||||
return false;
|
||||
if (start.length() > str.length())
|
||||
return false;
|
||||
if (str.characters_without_null_termination() == start.characters_without_null_termination())
|
||||
return true;
|
||||
|
||||
if (case_sensitivity == CaseSensitivity::CaseSensitive)
|
||||
return !memcmp(str.characters_without_null_termination(), start.characters_without_null_termination(), start.length());
|
||||
|
||||
auto str_chars = str.characters_without_null_termination();
|
||||
auto start_chars = start.characters_without_null_termination();
|
||||
|
||||
size_t si = 0;
|
||||
for (size_t starti = 0; starti < start.length(); ++si, ++starti) {
|
||||
if (to_lowercase(str_chars[si]) != to_lowercase(start_chars[starti]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue