19 #ifndef NUSPELL_UTILS_HXX
20 #define NUSPELL_UTILS_HXX
22 #include "defines.hxx"
23 #include "nuspell_export.h"
26 #include <string_view>
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)
42 NUSPELL_BEGIN_INLINE_NAMESPACE
44 NUSPELL_DEPRECATED_EXPORT
auto split_on_any_of(std::string_view s,
46 std::vector<std::string>& out)
47 -> std::vector<std::string>&;
49 NUSPELL_EXPORT
auto utf32_to_utf8(std::u32string_view in, std::string& out)
51 NUSPELL_EXPORT
auto utf32_to_utf8(std::u32string_view in) -> std::string;
53 auto valid_utf8_to_32(std::string_view in, std::u32string& out) -> void;
54 auto valid_utf8_to_32(std::string_view in) -> std::u32string;
56 auto utf8_to_16(std::string_view in) -> std::u16string;
57 auto utf8_to_16(std::string_view in, std::u16string& out) -> bool;
59 auto validate_utf8(std::string_view s) -> bool;
61 NUSPELL_EXPORT
auto is_all_ascii(std::string_view s) -> bool;
63 NUSPELL_EXPORT
auto latin1_to_ucs2(std::string_view s) -> std::u16string;
64 auto latin1_to_ucs2(std::string_view s, std::u16string& out) -> void;
66 NUSPELL_EXPORT
auto is_all_bmp(std::u16string_view s) -> bool;
68 auto 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)
80 auto to_upper(std::string_view in,
const icu::Locale& loc, std::string& out)
82 auto to_title(std::string_view in,
const icu::Locale& loc, std::string& out)
84 auto to_lower(std::u32string_view in,
const icu::Locale& loc,
85 std::u32string& out) -> void;
86 auto to_lower(std::string_view in,
const icu::Locale& loc, std::string& out)
88 auto to_lower_char_at(std::string& s,
size_t i,
const icu::Locale& loc) -> void;
89 auto to_title_char_at(std::string& s,
size_t i,
const icu::Locale& loc) -> void;
98 enum class Casing : char {
106 NUSPELL_EXPORT
auto classify_casing(std::string_view s) -> Casing;
108 auto has_uppercase_at_compound_word_boundary(std::string_view word,
size_t i)
112 UConverter* cnv =
nullptr;
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; }
140 auto replace_ascii_char(std::string& s,
char from,
char to) -> void;
141 auto erase_chars(std::string& s, std::string_view erase_chars) -> void;
142 NUSPELL_EXPORT
auto is_number(std::string_view s) -> bool;
143 auto count_appereances_of(std::string_view haystack, std::string_view needles)
146 auto inline begins_with(std::string_view haystack, std::string_view needle)
149 return haystack.compare(0, needle.size(), needle) == 0;
152 auto 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();
170 NUSPELL_END_INLINE_NAMESPACE
Definition: utils.hxx:111
Library main namespace.
Definition: aff_data.cxx:33