Rune Caster 1.0.0
Modern C++ Text Processing Framework
Loading...
Searching...
No Matches
spells.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "spell_unified.hpp"
4#include "unicode.hpp"
5#include "language.hpp"
6
7namespace rune_caster {
8
16namespace spells {
17
18// === Text normalization spells ===
19
26extern const Spell whitespace_normalizer;
27
31extern const Spell trim_whitespace;
32
36extern const Spell collapse_whitespace;
37
38// === Case conversion spells ===
39
43extern const Spell to_lowercase;
44
48extern const Spell to_uppercase;
49
53extern const Spell to_titlecase;
54
55// === Unicode normalization spells ===
56
60extern const Spell unicode_nfc;
61
65extern const Spell unicode_nfd;
66
70extern const Spell unicode_nfkc;
71
75extern const Spell unicode_nfkd;
76
77// === Filtering spells ===
78
82extern const Spell remove_punctuation;
83
87extern const Spell alphanumeric_only;
88
92extern const Spell remove_digits;
93
97extern const Spell ascii_only;
98
99// === Common combinations ===
100
104extern const Spell text_cleanup;
105
109extern const Spell search_preprocess;
110
114extern const Spell display_format;
115
116// === Factory functions for dynamic spell creation ===
117
124Spell whitespace(bool collapse_multiple = true, bool trim_edges = true);
125
132Spell replace_char(char32_t from, char32_t to);
133
140Spell replace_string(std::string_view from, std::string_view to);
141
147template<typename Predicate>
148Spell remove_if(Predicate&& predicate) {
150 [pred = std::forward<Predicate>(predicate)](const Rune& rune) {
151 return !pred(rune);
152 },
153 "RemoveIf",
154 "Remove characters matching predicate"
155 );
156}
157
163template<typename Predicate>
164Spell keep_if(Predicate&& predicate) {
166 std::forward<Predicate>(predicate),
167 "KeepIf",
168 "Keep only characters matching predicate"
169 );
170}
171
177template<typename Transform>
178Spell transform_chars(Transform&& transform) {
180 std::forward<Transform>(transform),
181 "TransformChars",
182 "Transform each character"
183 );
184}
185
186// === Language-specific spells ===
187
193
200Spell filter_by_script(unicode::Script script, bool keep = true);
201
208Spell filter_by_category(unicode::Category category, bool keep = true);
209
210} // namespace spells
211
212// === Usage examples and documentation ===
213
241
242} // namespace rune_caster
Represents a single textual unit with Unicode and linguistic properties.
Definition rune.hpp:23
Unified spell object for text transformation.
Language identification and localization support.
auto filter_spell(Predicate &&predicate, std::string name="FilterSpell", std::string description="Rune filtering")
Create a spell that filters runes based on a predicate.
auto per_rune_spell(RuneTransform &&rune_transform, std::string name="PerRuneSpell", std::string description="Per-rune transformation")
Create a spell that applies a transformation to each rune.
Pre-defined spells using the unified Spell interface.
Definition spells.hpp:16
const Spell text_cleanup
Standard text cleanup (whitespace + NFC + lowercase)
Spell keep_if(Predicate &&predicate)
Create a spell that keeps only characters matching a predicate.
Definition spells.hpp:164
Spell detect_language()
Create a language detection spell.
Spell filter_by_script(unicode::Script script, bool keep=true)
Create a script filtering spell.
const Spell to_uppercase
Convert text to uppercase.
const Spell unicode_nfkd
Apply Unicode NFKD normalization.
const Spell alphanumeric_only
Keep only letters and digits.
const Spell search_preprocess
Search-optimized preprocessing.
const Spell remove_digits
Remove digits.
const Spell remove_punctuation
Remove punctuation characters.
const Spell to_lowercase
Convert text to lowercase.
Spell whitespace(bool collapse_multiple=true, bool trim_edges=true)
Create a custom whitespace normalizer.
const Spell ascii_only
Keep only ASCII characters.
const Spell collapse_whitespace
Collapse multiple whitespace into single spaces.
Spell remove_if(Predicate &&predicate)
Create a spell that removes characters matching a predicate.
Definition spells.hpp:148
Spell replace_string(std::string_view from, std::string_view to)
Create a string replacement spell.
Spell replace_char(char32_t from, char32_t to)
Create a character replacement spell.
const Spell to_titlecase
Convert text to title case.
const Spell display_format
Display-optimized formatting.
const Spell whitespace_normalizer
Normalize whitespace characters.
const Spell unicode_nfkc
Apply Unicode NFKC normalization.
Spell filter_by_category(unicode::Category category, bool keep=true)
Create a category filtering spell.
const Spell unicode_nfd
Apply Unicode NFD normalization.
const Spell trim_whitespace
Trim leading and trailing whitespace.
const Spell unicode_nfc
Apply Unicode NFC normalization.
Spell transform_chars(Transform &&transform)
Create a spell that transforms each character.
Definition spells.hpp:178