Loading [MathJax]/extensions/tex2jax.js
cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
utf8_string.cpp
Go to the documentation of this file.
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 */
21
22#include <ostream>
23#include <utility>
24
25#include <fmt/format.h>
26#include <simdutf.h>
27
29
30namespace stat_bench {
31namespace util {
32
33Utf8String::Utf8String(std::string str) : str_(std::move(str)) {
34 if (!simdutf::validate_utf8(str_.data(), str_.size())) {
35 throw StatBenchException("Invalid UTF-8 string.");
36 }
37}
38
39auto Utf8String::str() const noexcept -> const std::string& { return str_; }
40
41auto operator==(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
42 return lhs.str() == rhs.str();
43}
44
45auto operator!=(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
46 return !(lhs == rhs);
47}
48
49auto operator<(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
50 return lhs.str() < rhs.str();
51}
52
53auto operator>(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
54 return rhs < lhs;
55}
56
57auto operator<=(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
58 return !(rhs < lhs);
59}
60
61auto operator>=(const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool {
62 return !(lhs < rhs);
63}
64
65} // namespace util
66} // namespace stat_bench
67
68namespace fmt {
69
70auto formatter<stat_bench::util::Utf8String>::format(
71 const stat_bench::util::Utf8String& val, format_context& context) const
72 -> format_context::iterator {
73 return formatter<string_view>::format(val.str(), context);
74}
75
76} // namespace fmt
77
78namespace stat_bench {
79namespace util {
80
81auto operator<<(std::ostream& stream, const Utf8String& val) -> std::ostream& {
82 return stream << val.str();
83}
84
85} // namespace util
86} // namespace stat_bench
Class of UTF-8 encoded string.
Definition utf8_string.h:35
auto str() const noexcept -> const std::string &
Get the string.
Utf8String()=default
Constructor. (Empty string.)
Namespace of fmt library.
Namespace of utility functions and classes.
auto operator!=(const Utf8String &lhs, const Utf8String &rhs) noexcept -> bool
Compare two Utf8String objects.
auto operator==(const Utf8String &lhs, const Utf8String &rhs) noexcept -> bool
Compare two Utf8String objects.
auto operator>=(const Utf8String &lhs, const Utf8String &rhs) noexcept -> bool
Compare two Utf8String objects.
auto operator<<(std::ostream &stream, const Utf8String &val) -> std::ostream &
Format to a stream.
auto operator>(const Utf8String &lhs, const Utf8String &rhs) noexcept -> bool
Compare two Utf8String objects.
auto operator<=(const Utf8String &lhs, const Utf8String &rhs) noexcept -> bool
Compare two Utf8String objects.
auto operator<(const Utf8String &lhs, const Utf8String &rhs) noexcept -> bool
Compare two Utf8String objects.
Namespace of stat_bench source codes.
STL namespace.
Definition of StatBenchException class.
Definition of Utf8String class.