19#ifndef NUSPELL_UTILS_HXX
20#define NUSPELL_UTILS_HXX
23#include "nuspell_export.h"
29#include <unicode/locid.h>
32#define likely(expr) __builtin_expect(!!(expr), 1)
33#define unlikely(expr) __builtin_expect(!!(expr), 0)
35#define likely(expr) (expr)
36#define unlikely(expr) (expr)
42NUSPELL_BEGIN_INLINE_NAMESPACE
44NUSPELL_DEPRECATED_EXPORT
auto split_on_any_of(std::string_view s,
46 std::vector<std::string>& out)
47 -> std::vector<std::string>&;
49NUSPELL_EXPORT
auto utf32_to_utf8(std::u32string_view in, std::string& out)
51NUSPELL_EXPORT
auto utf32_to_utf8(std::u32string_view in) -> std::string;
53auto valid_utf8_to_32(std::string_view in, std::u32string& out) -> void;
54auto valid_utf8_to_32(std::string_view in) -> std::u32string;
56auto utf8_to_16(std::string_view in) -> std::u16string;
57auto utf8_to_16(std::string_view in, std::u16string& out) -> bool;
59auto validate_utf8(std::string_view s) -> bool;
61NUSPELL_EXPORT
auto is_all_ascii(std::string_view s) -> bool;
63NUSPELL_EXPORT
auto latin1_to_ucs2(std::string_view s) -> std::u16string;
64auto latin1_to_ucs2(std::string_view s, std::u16string& out) -> void;
66NUSPELL_EXPORT
auto is_all_bmp(std::u16string_view s) -> bool;
68auto to_upper_ascii(std::string& s) -> void;
70[[nodiscard]] NUSPELL_EXPORT
auto to_upper(std::string_view in,
71 const icu::Locale& loc)
73[[nodiscard]] NUSPELL_EXPORT
auto to_title(std::string_view in,
74 const icu::Locale& loc)
76[[nodiscard]] NUSPELL_EXPORT
auto to_lower(std::string_view in,
77 const icu::Locale& loc)
80auto to_upper(std::string_view in,
const icu::Locale& loc, std::string& out)
82auto to_title(std::string_view in,
const icu::Locale& loc, std::string& out)
84auto to_lower(std::u32string_view in,
const icu::Locale& loc,
85 std::u32string& out) -> void;
86auto to_lower(std::string_view in,
const icu::Locale& loc, std::string& out)
88auto to_lower_char_at(std::string& s,
size_t i,
const icu::Locale& loc) -> void;
89auto to_title_char_at(std::string& s,
size_t i,
const icu::Locale& loc) -> void;
98enum class Casing :
char {
106NUSPELL_EXPORT
auto classify_casing(std::string_view s) -> Casing;
108auto has_uppercase_at_compound_word_boundary(std::string_view word,
size_t i)
111class Encoding_Converter {
112 UConverter* cnv =
nullptr;
115 Encoding_Converter() =
default;
116 explicit Encoding_Converter(
const char* enc);
117 explicit Encoding_Converter(
const std::string& enc)
118 : Encoding_Converter(enc.c_str())
121 ~Encoding_Converter();
122 Encoding_Converter(
const Encoding_Converter& other) =
delete;
123 Encoding_Converter(Encoding_Converter&& other)
noexcept
128 auto operator=(
const Encoding_Converter& other)
129 -> Encoding_Converter& =
delete;
130 auto operator=(Encoding_Converter&& other)
noexcept
131 -> Encoding_Converter&
133 std::swap(cnv, other.cnv);
136 auto to_utf8(std::string_view in, std::string& out) -> bool;
137 auto valid() ->
bool {
return cnv !=
nullptr; }
140auto replace_ascii_char(std::string& s,
char from,
char to) -> void;
141auto erase_chars(std::string& s, std::string_view erase_chars) -> void;
142NUSPELL_EXPORT
auto is_number(std::string_view s) -> bool;
143auto count_appereances_of(std::string_view haystack, std::string_view needles)
146auto inline begins_with(std::string_view haystack, std::string_view needle)
149 return haystack.compare(0, needle.size(), needle) == 0;
152auto inline ends_with(std::string_view haystack, std::string_view needle)
155 return haystack.size() >= needle.size() &&
156 haystack.compare(haystack.size() - needle.size(), needle.size(),
168 return x.data() + x.size();
170NUSPELL_END_INLINE_NAMESPACE
Library main namespace.
Definition aff_data.cxx:33