Coverage Report

Created: 2025-07-06 13:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/builds/MusicScience37Projects/utility-libraries/cpp-stat-bench/src/stat_bench/util/utf8_string.cpp
Line
Count
Source
1
/*
2
 * Copyright 2024 MusicScience37 (Kenta Kabashima)
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
/*!
17
 * \file
18
 * \brief Implementation of Utf8String class.
19
 */
20
#include "stat_bench/util/utf8_string.h"
21
22
#include <ostream>
23
#include <utility>
24
25
#include <fmt/format.h>
26
#include <simdutf.h>
27
28
#include "stat_bench/stat_bench_exception.h"
29
30
namespace stat_bench {
31
namespace util {
32
33
14.2k
Utf8String::Utf8String(std::string str) : str_(std::move(str)) {
34
14.2k
    if (!simdutf::validate_utf8(str_.data(), str_.size())) {
35
6
        throw StatBenchException("Invalid UTF-8 string.");
36
6
    }
37
14.2k
}
38
39
89.6k
auto Utf8String::str() const noexcept -> const std::string& { return str_; }
40
41
18.5k
auto operator==(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
42
18.5k
    return lhs.str() == rhs.str();
43
18.5k
}
44
45
2
auto operator!=(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
46
2
    return !(lhs == rhs);
47
2
}
48
49
24
auto operator<(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
50
24
    return lhs.str() < rhs.str();
51
24
}
52
53
3
auto operator>(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
54
3
    return rhs < lhs;
55
3
}
56
57
3
auto operator<=(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
58
3
    return !(rhs < lhs);
59
3
}
60
61
3
auto operator>=(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
62
3
    return !(lhs < rhs);
63
3
}
64
65
}  // namespace util
66
}  // namespace stat_bench
67
68
namespace fmt {
69
70
auto formatter<stat_bench::util::Utf8String>::format(
71
    const stat_bench::util::Utf8String& val, format_context& context) const
72
9.63k
    -> format_context::iterator {
73
9.63k
    return formatter<string_view>::format(val.str(), context);
74
9.63k
}
75
76
}  // namespace fmt
77
78
namespace stat_bench {
79
namespace util {
80
81
6
auto operator<<(std::ostream& stream, const Utf8String& val) -> std::ostream& {
82
6
    return stream << val.str();
83
6
}
84
85
}  // namespace util
86
}  // namespace stat_bench