Rune Caster 1.0.0
Modern C++ Text Processing Framework
Loading...
Searching...
No Matches
unicode_normalizer.cpp
Go to the documentation of this file.
3#include <string>
4
5#ifdef RUNE_CASTER_HAS_UTFCPP
6 #include <utf8.h>
7#elif defined(RUNE_CASTER_HAS_ICU)
8 #include <unicode/normalizer2.h>
9 #include <unicode/unistr.h>
10#endif
11
12namespace rune_caster {
13namespace spell {
14namespace core {
15
18
20 if (input.empty()) {
21 return RuneSequence();
22 }
23
24 std::string utf8_text = input.to_utf8();
25 std::string normalized;
26
27 try {
28#ifdef RUNE_CASTER_HAS_UTFCPP
29 std::u32string utf32;
30 utf8::utf8to32(utf8_text.begin(), utf8_text.end(), std::back_inserter(utf32));
31 normalized.clear();
32 utf8::utf32to8(utf32.begin(), utf32.end(), std::back_inserter(normalized));
33#elif defined(RUNE_CASTER_HAS_ICU)
34 // Use ICU for normalization (placeholder implementation)
35 normalized = utf8_text;
36#else
37 normalized = utf8_text;
38#endif
39 } catch (...) {
40 normalized = utf8_text;
41 }
42
43 return RuneSequence::from_utf8(normalized);
44}
45
46std::string UnicodeNormalizer::description() const {
47 switch (form_) {
49 return "Unicode NFC Normalization";
51 return "Unicode NFD Normalization";
53 return "Unicode NFKC Normalization";
55 return "Unicode NFKD Normalization";
56 default:
57 return "Unicode Normalization";
58 }
59}
60
61} // namespace core
62} // namespace spell
63} // namespace rune_caster
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.
std::string description() const override
Get the spell's description.
RuneSequence operator()(const RuneSequence &input) const override
Apply the spell transformation.
UnicodeNormalizer(unicode::NormalizationForm form=unicode::NormalizationForm::NFC)
Construct a UnicodeNormalizer.
RuneString RuneSequence
Backward compatibility alias for RuneString.
Simple and unified spell system for text transformation.