5#ifdef RUNE_CASTER_HAS_UTFCPP
8#elif defined(RUNE_CASTER_HAS_ICU)
9 #include <unicode/uchar.h>
10 #include <unicode/unistr.h>
25 std::string utf8_text = input.
to_utf8();
26 std::string converted;
29#ifdef RUNE_CASTER_HAS_UTFCPP
31 utf8::utf8to32(utf8_text.begin(), utf8_text.end(), std::back_inserter(utf32));
32 bool at_word_start =
true;
33 for (
char32_t cp : utf32) {
37 out =
static_cast<char32_t>(std::towlower(
static_cast<wint_t
>(cp)));
40 out =
static_cast<char32_t>(std::towupper(
static_cast<wint_t
>(cp)));
44 out =
static_cast<char32_t>(std::towupper(
static_cast<wint_t
>(cp)));
46 out =
static_cast<char32_t>(std::towlower(
static_cast<wint_t
>(cp)));
52 utf8::append(out, std::back_inserter(converted));
54#elif defined(RUNE_CASTER_HAS_ICU)
56 converted = utf8_text;
58 converted.reserve(utf8_text.size());
59 bool at_word_start =
true;
61 for (
char ch : utf8_text) {
64 if (ch >=
'A' && ch <=
'Z') {
65 converted.push_back(ch + 32);
67 converted.push_back(ch);
71 if (ch >=
'a' && ch <=
'z') {
72 converted.push_back(ch - 32);
74 converted.push_back(ch);
78 if (ch ==
' ' || ch ==
'\t' || ch ==
'\n') {
80 converted.push_back(ch);
81 }
else if (at_word_start && ch >=
'a' && ch <=
'z') {
82 converted.push_back(ch - 32);
83 at_word_start =
false;
85 if (ch >=
'A' && ch <=
'Z' && !at_word_start) {
86 converted.push_back(ch + 32);
88 converted.push_back(ch);
90 if ((ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z')) {
91 at_word_start =
false;
99 converted = utf8_text;
106 switch (case_type_) {
108 return "Lowercase Conversion";
110 return "Uppercase Conversion";
112 return "Titlecase Conversion";
114 return "Case Conversion";
bool empty() const noexcept
static RuneString from_utf8(std::string_view utf8_text)
Create a RuneString from UTF-8 text.
std::string to_utf8() const
Convert the sequence to UTF-8 string.
@ Upper
Convert to uppercase.
@ Lower
Convert to lowercase.
@ Title
Convert to titlecase (first letter of each word)
std::string description() const override
Get the spell's description.
CaseType case_type() const noexcept
Get the case type of this converter.
CaseConverter(CaseType case_type)
Construct a CaseConverter.
RuneSequence operator()(const RuneSequence &input) const override
Apply the spell transformation.
constexpr bool is_whitespace(char32_t cp) noexcept
RuneString RuneSequence
Backward compatibility alias for RuneString.
Simple and unified spell system for text transformation.