uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
HasLocalTransformer = [bool]
Property
Product:
Class:
Checks if a rule has an associated local transformer without creating one if it doesn't exist.
Remarks
🧐 A Non-Destructive Check: HasLocalTransformer
The HasLocalTransformer property is a read-only check to determine if a Rule has an associated local transformer without the side effect of creating one.
The Critical Distinction: HasLocalTransformer vs. LocalTransformer
This property's primary purpose is to provide a safe way to query the state of a rule, which is crucial for performance and predictable behavior. Understanding the difference between these two methods is essential:
HasLocalTransformer(This Property): This is a query. It simply returnstrueorfalse. It does not allocate memory or change the state of the rule.LocalTransformer(): This is a get-or-create operation. If a local transformer already exists, it returns it. If one does not exist, it creates a new one on the fly. This has a performance cost and modifies the rule object.
Therefore, you should always use HasLocalTransformer when you only need to check for the existence of nested logic, as it avoids the unnecessary overhead of creating a new Transformer instance.
💡 Why uCalc? (Comparative Analysis)
This design pattern, separating a 'has' check from a 'get-or-create' method, is a best practice in API design that promotes clarity and avoids hidden side effects. It is similar to patterns seen in other frameworks:
- vs. C#
Dictionary.TryGetValue: In C#, callingmyDict[key]will throw an exception if the key doesn't exist. TheTryGetValuepattern provides a safe way to check for and retrieve a value without exceptions. Similarly,HasLocalTransformerallows you to check for a local transformer without the side effect of creating one.
By providing both HasLocalTransformer and LocalTransformer, uCalc gives developers explicit control. You can safely inspect a rule's structure without accidentally altering it, which is crucial for building robust and performant introspection tools or debuggers.
Examples
LocalTransformer, HasLocalTransformer, IsChildRule
using uCalcSoftware;
var uc = new uCalc();
// Note the change in section/div/h2
var t = uc.NewTransformer();
var rule = t.Pattern("{body} ").SetStatementSensitive(false);
var section = rule.LocalTransformer;
section.FromTo("{text}
", "====> {@Eval: UCase(text)} <====
");
section.SkipOver("&{entity};");
var ch = section.FromTo("{text}
", "SELECTED: {text}
");
Console.WriteLine($"Has a local transformer: {rule.HasLocalTransformer}");
Console.WriteLine($"rule is a child rule: {rule.IsChildRule}");
Console.WriteLine($"ch is a child rule: {ch.IsChildRule}");
var HtmlText =
"""
Article One
This is the first article.
Article Two
This is the second article.
Article Three
This one is inside a <section>.
Article Four
This is the fourth article.
""";
t.Text = HtmlText;
t.Transform();
Console.WriteLine(t.Text);
Has a local transformer: True
rule is a child rule: False
ch is a child rule: True
<div class="article" data-id="1">
<h2>Article One</h2>
<p>This is the first article.</p>
</div>
<div class="article" data-id="2">
<h2>Article Two</h2>
<p>This is the second article.</p>
</div>
<section>
<div class="article" data-id="3">
<h1>====> ARTICLE THREE <====</h1>
<p>SELECTED: This one is inside a <section>.</p>
</div>
</section>
<div class="article" data-id="4">
<h2>Article Four</h2>
<p>This is the fourth article.</p>
</div> using uCalcSoftware; var uc = new uCalc(); // Note the change in section/div/h2 var t = uc.NewTransformer(); var rule = t.Pattern("<section>{body}</section>").SetStatementSensitive(false); var section = rule.LocalTransformer; section.FromTo("<h2>{text}</h2>", "<h1>====> {@Eval: UCase(text)} <====</h1>"); section.SkipOver("&{entity};"); var ch = section.FromTo("<p>{text}</p>", "<p>SELECTED: {text}</p>"); Console.WriteLine($"Has a local transformer: {rule.HasLocalTransformer}"); Console.WriteLine($"rule is a child rule: {rule.IsChildRule}"); Console.WriteLine($"ch is a child rule: {ch.IsChildRule}"); var HtmlText = """ <div class="article" data-id="1"> <h2>Article One</h2> <p>This is the first article.</p> </div> <div class="article" data-id="2"> <h2>Article Two</h2> <p>This is the second article.</p> </div> <section> <div class="article" data-id="3"> <h2>Article Three</h2> <p>This one is inside a <section>.</p> </div> </section> <div class="article" data-id="4"> <h2>Article Four</h2> <p>This is the fourth article.</p> </div> """; t.Text = HtmlText; t.Transform(); Console.WriteLine(t.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
// Note the change in section/div/h2
auto t = uc.NewTransformer();
auto rule = t.Pattern("{body} ").SetStatementSensitive(false);
auto section = rule.LocalTransformer();
section.FromTo("{text}
", "====> {@Eval: UCase(text)} <====
");
section.SkipOver("&{entity};");
auto ch = section.FromTo("{text}
", "SELECTED: {text}
");
cout << "Has a local transformer: " << tf(rule.HasLocalTransformer()) << endl;
cout << "rule is a child rule: " << tf(rule.IsChildRule()) << endl;
cout << "ch is a child rule: " << tf(ch.IsChildRule()) << endl;
auto HtmlText =
R"(
Article One
This is the first article.
Article Two
This is the second article.
Article Three
This one is inside a <section>.
Article Four
This is the fourth article.
)";
t.Text(HtmlText);
t.Transform();
cout << t.Text() << endl;
}
Has a local transformer: True
rule is a child rule: False
ch is a child rule: True
<div class="article" data-id="1">
<h2>Article One</h2>
<p>This is the first article.</p>
</div>
<div class="article" data-id="2">
<h2>Article Two</h2>
<p>This is the second article.</p>
</div>
<section>
<div class="article" data-id="3">
<h1>====> ARTICLE THREE <====</h1>
<p>SELECTED: This one is inside a <section>.</p>
</div>
</section>
<div class="article" data-id="4">
<h2>Article Four</h2>
<p>This is the fourth article.</p>
</div> #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; // Note the change in section/div/h2 auto t = uc.NewTransformer(); auto rule = t.Pattern("<section>{body}</section>").SetStatementSensitive(false); auto section = rule.LocalTransformer(); section.FromTo("<h2>{text}</h2>", "<h1>====> {@Eval: UCase(text)} <====</h1>"); section.SkipOver("&{entity};"); auto ch = section.FromTo("<p>{text}</p>", "<p>SELECTED: {text}</p>"); cout << "Has a local transformer: " << tf(rule.HasLocalTransformer()) << endl; cout << "rule is a child rule: " << tf(rule.IsChildRule()) << endl; cout << "ch is a child rule: " << tf(ch.IsChildRule()) << endl; auto HtmlText = R"( <div class="article" data-id="1"> <h2>Article One</h2> <p>This is the first article.</p> </div> <div class="article" data-id="2"> <h2>Article Two</h2> <p>This is the second article.</p> </div> <section> <div class="article" data-id="3"> <h2>Article Three</h2> <p>This one is inside a <section>.</p> </div> </section> <div class="article" data-id="4"> <h2>Article Four</h2> <p>This is the fourth article.</p> </div> )"; t.Text(HtmlText); t.Transform(); cout << t.Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Note the change in section/div/h2
Dim t = uc.NewTransformer()
Dim rule = t.Pattern("{body} ").SetStatementSensitive(false)
Dim section = rule.LocalTransformer
section.FromTo("{text}
", "====> {@Eval: UCase(text)} <====
")
section.SkipOver("&{entity};")
Dim ch = section.FromTo("{text}
", "SELECTED: {text}
")
Console.WriteLine($"Has a local transformer: {rule.HasLocalTransformer}")
Console.WriteLine($"rule is a child rule: {rule.IsChildRule}")
Console.WriteLine($"ch is a child rule: {ch.IsChildRule}")
Dim HtmlText =
"
Article One
This is the first article.
Article Two
This is the second article.
Article Three
This one is inside a <section>.
Article Four
This is the fourth article.
"
t.Text = HtmlText
t.Transform()
Console.WriteLine(t.Text)
End Sub
End Module
Has a local transformer: True
rule is a child rule: False
ch is a child rule: True
<div class="article" data-id="1">
<h2>Article One</h2>
<p>This is the first article.</p>
</div>
<div class="article" data-id="2">
<h2>Article Two</h2>
<p>This is the second article.</p>
</div>
<section>
<div class="article" data-id="3">
<h1>====> ARTICLE THREE <====</h1>
<p>SELECTED: This one is inside a <section>.</p>
</div>
</section>
<div class="article" data-id="4">
<h2>Article Four</h2>
<p>This is the fourth article.</p>
</div> Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Note the change in section/div/h2 Dim t = uc.NewTransformer() Dim rule = t.Pattern("<section>{body}</section>").SetStatementSensitive(false) Dim section = rule.LocalTransformer section.FromTo("<h2>{text}</h2>", "<h1>====> {@Eval: UCase(text)} <====</h1>") section.SkipOver("&{entity};") Dim ch = section.FromTo("<p>{text}</p>", "<p>SELECTED: {text}</p>") Console.WriteLine($"Has a local transformer: {rule.HasLocalTransformer}") Console.WriteLine($"rule is a child rule: {rule.IsChildRule}") Console.WriteLine($"ch is a child rule: {ch.IsChildRule}") Dim HtmlText = " <div class=""article"" data-id=""1""> <h2>Article One</h2> <p>This is the first article.</p> </div> <div class=""article"" data-id=""2""> <h2>Article Two</h2> <p>This is the second article.</p> </div> <section> <div class=""article"" data-id=""3""> <h2>Article Three</h2> <p>This one is inside a <section>.</p> </div> </section> <div class=""article"" data-id=""4""> <h2>Article Four</h2> <p>This is the fourth article.</p> </div> " t.Text = HtmlText t.Transform() Console.WriteLine(t.Text) End Sub End Module