49 std::
string name =
"CustomSpell",
58 template<typename Func>
62 std::
string name =
"LambdaSpell",
64 : transform_(
std::forward<Func>(func))
67 , id_(generate_id()) {}
90 std::
string operator()(
std::string_view utf8_input) const;
109 [[nodiscard]] const
std::
string&
name() const noexcept {
return name_; }
115 [[nodiscard]]
const std::string&
description() const noexcept {
return description_; }
121 [[nodiscard]] uint64_t
id() const noexcept {
return id_; }
149 [[nodiscard]] std::string
to_string()
const;
181 const Spell& if_true,
182 const Spell& if_false);
187 std::string description_;
189 bool is_composition_;
190 size_t composition_depth_;
196 static uint64_t generate_id();
210template<
typename Lambda>
212 std::string name =
"CustomSpell",
213 std::string description =
"Custom transformation") {
214 return Spell{std::forward<Lambda>(lambda), std::move(name), std::move(description)};
224template<
typename RuneTransform>
226 std::string name =
"PerRuneSpell",
227 std::string description =
"Per-rune transformation") {
228 return make_spell([transform = std::forward<RuneTransform>(rune_transform)]
231 for (
const auto& rune : input) {
232 result.
append(transform(rune));
235 }, std::move(name), std::move(description));
245template<
typename Predicate>
247 std::string name =
"FilterSpell",
248 std::string description =
"Rune filtering") {
249 return make_spell([pred = std::forward<Predicate>(predicate)]
252 for (
const auto& rune : input) {
258 }, std::move(name), std::move(description));
276Spell operator""_spell(
const char* replacement_rule,
size_t len);
RuneString & append(const RuneString &other)
Append another RuneString.
Unified spell object for text transformation.
Spell(const Spell &)=default
Spell(Spell &&) noexcept=default
RuneSequence test(const RuneSequence &test_input) const
Test the spell with sample input.
uint64_t id() const noexcept
Get the spell unique ID.
std::function< RuneSequence(const RuneSequence &)> transform_function
bool is_identity() const noexcept
Check if this spell is the identity transformation.
std::string to_string() const
Get a detailed string representation.
static Spell constant(RuneSequence constant_result)
Create a spell that always returns the same result.
const std::string & description() const noexcept
Get the spell description.
std::function< bool(const RuneSequence &)> validation_function
bool is_composition() const noexcept
Check if this spell is a composition of multiple spells.
static Spell identity()
Create an identity spell (no transformation)
const std::string & name() const noexcept
Get the spell name.
Spell() noexcept
Default constructor (identity spell)
static Spell conditional(validation_function condition, const Spell &if_true, const Spell &if_false)
Create a conditional spell.
size_t composition_depth() const noexcept
Get the number of composed spells (1 for simple spells)
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.
auto make_spell(Lambda &&lambda, std::string name="CustomSpell", std::string description="Custom transformation")
Create a spell from a lambda.
RuneString RuneSequence
Backward compatibility alias for RuneString.