Coverage Report

Created: 2025-12-18 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibUnicode/String.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <AK/String.h>
8
#include <AK/StringBuilder.h>
9
#include <AK/Utf8View.h>
10
#include <LibUnicode/CharacterTypes.h>
11
#include <LibUnicode/UnicodeUtils.h>
12
13
// This file contains definitions of AK::String methods which require UCD data.
14
15
namespace AK {
16
17
ErrorOr<String> String::to_lowercase(Optional<StringView> const& locale) const
18
0
{
19
0
    StringBuilder builder;
20
0
    TRY(Unicode::Detail::build_lowercase_string(code_points(), builder, locale));
21
0
    return builder.to_string_without_validation();
22
0
}
23
24
ErrorOr<String> String::to_uppercase(Optional<StringView> const& locale) const
25
3.20k
{
26
3.20k
    StringBuilder builder;
27
3.20k
    TRY(Unicode::Detail::build_uppercase_string(code_points(), builder, locale));
28
3.20k
    return builder.to_string_without_validation();
29
3.20k
}
30
31
ErrorOr<String> String::to_titlecase(Optional<StringView> const& locale, TrailingCodePointTransformation trailing_code_point_transformation) const
32
0
{
33
0
    StringBuilder builder;
34
0
    TRY(Unicode::Detail::build_titlecase_string(code_points(), builder, locale, trailing_code_point_transformation));
35
0
    return builder.to_string_without_validation();
36
0
}
37
38
ErrorOr<String> String::to_casefold() const
39
0
{
40
0
    StringBuilder builder;
41
0
    TRY(Unicode::Detail::build_casefold_string(code_points(), builder));
42
0
    return builder.to_string_without_validation();
43
0
}
44
45
bool String::equals_ignoring_case(String const& other) const
46
0
{
47
0
    return Unicode::equals_ignoring_case(code_points(), other.code_points());
48
0
}
49
50
Optional<size_t> String::find_byte_offset_ignoring_case(StringView needle, size_t from_byte_offset) const
51
0
{
52
0
    auto haystack = code_points().substring_view(from_byte_offset);
53
54
0
    if (auto index = Unicode::find_ignoring_case(haystack, Utf8View { needle }); index.has_value())
55
0
        return *index + from_byte_offset;
56
57
0
    return {};
58
0
}
59
60
}