Rune Caster 1.0.0
Modern C++ Text Processing Framework
Loading...
Searching...
No Matches
spell.hpp
Go to the documentation of this file.
1#pragma once
2
26
27// Internal headers (users don't need to know about these)
28#include "spell_base.hpp"
29#include "spell_extensible.hpp"
30#include "rune_sequence.hpp"
31#include "caster.hpp"
32
33// Implementation headers
34#include "spell_core.hpp"
35#include "spell_filter.hpp"
36#include "spell_language.hpp"
37#include "spell_token.hpp"
38
39namespace rune_caster {
40namespace spell {
41
42// === Simple factory functions for common spells ===
43
50
57
64
68inline auto trim() {
69 return core::TrimEdges{};
70}
71
75inline auto normalize_whitespace(bool collapse_multiple = true, bool trim_edges = true) {
76 return core::WhitespaceNormalizer{collapse_multiple, trim_edges};
77}
78
85
92
99
106
110inline auto tokenize() {
112}
113
117inline auto remove_punctuation() {
119}
120
124inline auto detect_language() {
126}
127
128// === Common spell combinations ===
129
134public:
135 TextCleanup() : spell_extensible{"TextCleanup", "Standard text cleanup"} {}
136
137private:
138 RuneSequence process(const RuneSequence& input) const override {
139 return make_caster(input)
141 .cast(spell::trim())
142 .cast(spell::lowercase())
143 .result();
144 }
145};
146
150inline auto cleanup() {
151 return TextCleanup{};
152}
153
158public:
159 SearchPreprocess() : spell_extensible{"SearchPreprocess", "Search preprocessing"} {}
160
161private:
162 RuneSequence process(const RuneSequence& input) const override {
163 return make_caster(input)
164 .cast(spell::unicode_nfc())
166 .cast(spell::trim())
167 .cast(spell::lowercase())
169 .result();
170 }
171};
172
176inline auto search_preprocess() {
177 return SearchPreprocess{};
178}
179
180// === Advanced: Custom spell creation ===
181
192template<typename Func>
194private:
195 Func func_;
196
197public:
198 CustomSpell(std::string name, std::string desc, Func func)
199 : spell_extensible{std::move(name), std::move(desc)}, func_{std::move(func)} {}
200
201private:
202 RuneSequence process(const RuneSequence& input) const override {
203 return func_(input);
204 }
205};
206
210template<typename Func>
211auto custom(std::string name, std::string description, Func&& func) {
213 std::move(name),
214 std::move(description),
215 std::forward<Func>(func)
216 };
217}
218
219} // namespace spell
220} // namespace rune_caster
221
Create a custom spell from a lambda function.
Definition spell.hpp:193
CustomSpell(std::string name, std::string desc, Func func)
Definition spell.hpp:198
Search preprocessing: cleanup + remove punctuation + unicode NFC.
Definition spell.hpp:157
Standard text cleanup: normalize whitespace + trim + lowercase.
Definition spell.hpp:133
Case conversion spell using C++20 concepts.
@ Title
Convert to titlecase (first letter of each word)
Trim leading and trailing whitespace.
Unicode normalization spell using C++20 concepts.
Normalize whitespace characters using C++20 concepts.
Simple whitespace tokenizer Splits input RuneSequence into tokens separated by Unicode whitespace.
Remove punctuation characters using C++20 concepts.
Language detection spell using C++20 concepts.
std::string name() const override
Get the spell's name.
spell_extensible(std::string name, std::string desc)
auto unicode_nfkd()
Apply Unicode NFKD normalization.
Definition spell.hpp:103
auto tokenize()
Tokenize text by whitespace.
Definition spell.hpp:110
auto cleanup()
Create a standard text cleanup spell.
Definition spell.hpp:150
auto titlecase()
Convert text to title case.
Definition spell.hpp:61
auto uppercase()
Convert text to uppercase.
Definition spell.hpp:54
auto search_preprocess()
Create a search preprocessing spell.
Definition spell.hpp:176
auto remove_punctuation()
Remove punctuation characters.
Definition spell.hpp:117
auto custom(std::string name, std::string description, Func &&func)
Create a custom spell from a function.
Definition spell.hpp:211
auto unicode_nfc()
Apply Unicode NFC normalization.
Definition spell.hpp:82
auto unicode_nfd()
Apply Unicode NFD normalization.
Definition spell.hpp:89
auto detect_language()
Detect language of text.
Definition spell.hpp:124
auto unicode_nfkc()
Apply Unicode NFKC normalization.
Definition spell.hpp:96
auto normalize_whitespace(bool collapse_multiple=true, bool trim_edges=true)
Normalize whitespace (collapse multiple spaces, optionally trim)
Definition spell.hpp:75
auto trim()
Trim leading and trailing whitespace.
Definition spell.hpp:68
auto lowercase()
Convert text to lowercase.
Definition spell.hpp:47
RuneString RuneSequence
Backward compatibility alias for RuneString.
constexpr auto make_caster(T &&data) noexcept -> caster< std::decay_t< T > >
Factory function to create a caster (C++20 template argument deduction)
Definition caster.hpp:124