LibRegex: Implement line splitting for Utf32View
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
This commit is contained in:
parent
0060fa48d4
commit
da1fda73a7
Notes:
sideshowbarker
2024-07-18 08:47:53 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/da1fda73a79 Pull-request: https://github.com/SerenityOS/serenity/pull/8847 Reviewed-by: https://github.com/MaxWipfli Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/trflynn89
1 changed files with 13 additions and 2 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "AK/FlyString.h"
|
||||
#include "AK/HashMap.h"
|
||||
#include "AK/MemMem.h"
|
||||
#include "AK/String.h"
|
||||
#include "AK/StringBuilder.h"
|
||||
#include "AK/StringView.h"
|
||||
|
@ -88,9 +89,19 @@ public:
|
|||
return new_views;
|
||||
}
|
||||
|
||||
// FIXME: line splitting for Utf32View needed
|
||||
Vector<RegexStringView> views;
|
||||
views.append(m_u32view.value());
|
||||
auto view = u32view();
|
||||
u32 newline = '\n';
|
||||
while (!view.is_empty()) {
|
||||
auto position = AK::memmem_optional(view.code_points(), view.length() * sizeof(u32), &newline, sizeof(u32));
|
||||
if (!position.has_value())
|
||||
break;
|
||||
auto offset = position.value() / sizeof(u32);
|
||||
views.append(view.substring_view(0, offset));
|
||||
view = view.substring_view(offset + 1, view.length() - offset - 1);
|
||||
}
|
||||
if (!view.is_empty())
|
||||
views.append(view);
|
||||
return views;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue