19#ifndef NUSPELL_UTILS_HXX
20#define NUSPELL_UTILS_HXX
22#include "nuspell_export.h"
28#include <unicode/locid.h>
31#define likely(expr) __builtin_expect(!!(expr), 1)
32#define unlikely(expr) __builtin_expect(!!(expr), 0)
34#define likely(expr) (expr)
35#define unlikely(expr) (expr)
43NUSPELL_DEPRECATED_EXPORT
auto split_on_any_of(std::string_view s,
45 std::vector<std::string>& out)
46 -> std::vector<std::string>&;
48NUSPELL_EXPORT
auto utf32_to_utf8(std::u32string_view in, std::string& out)
50NUSPELL_EXPORT
auto utf32_to_utf8(std::u32string_view in) -> std::string;
52auto valid_utf8_to_32(std::string_view in, std::u32string& out) -> void;
53auto valid_utf8_to_32(std::string_view in) -> std::u32string;
55auto utf8_to_16(std::string_view in) -> std::u16string;
56auto utf8_to_16(std::string_view in, std::u16string& out) -> bool;
58auto validate_utf8(std::string_view s) -> bool;
60NUSPELL_EXPORT
auto is_all_ascii(std::string_view s) -> bool;
62NUSPELL_EXPORT
auto latin1_to_ucs2(std::string_view s) -> std::u16string;
63auto latin1_to_ucs2(std::string_view s, std::u16string& out) -> void;
65NUSPELL_EXPORT
auto is_all_bmp(std::u16string_view s) -> bool;
67auto to_upper_ascii(std::string& s) -> void;
69[[nodiscard]] NUSPELL_EXPORT
auto to_upper(std::string_view in,
70 const icu::Locale& loc)
72[[nodiscard]] NUSPELL_EXPORT
auto to_title(std::string_view in,
73 const icu::Locale& loc)
75[[nodiscard]] NUSPELL_EXPORT
auto to_lower(std::string_view in,
76 const icu::Locale& loc)
79auto to_upper(std::string_view in,
const icu::Locale& loc, std::string& out)
81auto to_title(std::string_view in,
const icu::Locale& loc, std::string& out)
83auto to_lower(std::u32string_view in,
const icu::Locale& loc,
84 std::u32string& out) -> void;
85auto to_lower(std::string_view in,
const icu::Locale& loc, std::string& out)
87auto to_lower_char_at(std::string& s,
size_t i,
const icu::Locale& loc) -> void;
88auto to_title_char_at(std::string& s,
size_t i,
const icu::Locale& loc) -> void;
97enum class Casing :
char {
105NUSPELL_EXPORT
auto classify_casing(std::string_view s) -> Casing;
107auto has_uppercase_at_compound_word_boundary(std::string_view word,
size_t i)
111 UConverter* cnv =
nullptr;
132 std::swap(cnv, other.cnv);
135 auto to_utf8(std::string_view in, std::string& out) -> bool;
136 auto valid() ->
bool {
return cnv !=
nullptr; }
139auto replace_ascii_char(std::string& s,
char from,
char to) -> void;
140auto erase_chars(std::string& s, std::string_view erase_chars) -> void;
141NUSPELL_EXPORT
auto is_number(std::string_view s) -> bool;
142auto count_appereances_of(std::string_view haystack, std::string_view needles)
145auto inline begins_with(std::string_view haystack, std::string_view needle)
148 return haystack.compare(0, needle.size(), needle) == 0;
151auto inline ends_with(std::string_view haystack, std::string_view needle)
154 return haystack.size() >= needle.size() &&
155 haystack.compare(haystack.size() - needle.size(), needle.size(),
167 return x.data() + x.size();
Library main namespace.
Definition aff_data.cxx:33