uCalc API Version: 2.1.3-preview.2 Released: 6/16/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.
Escapes
Product:
Class:
Remarks
uCalc patterns reserve certain characters for syntax ({, }, [, ], |). To match these characters literally in your text, you use the Escape Token mechanism.
User-Defined Escape System:Unlike Regex which forces \ as the escape character, uCalc allows you to define any token pattern as an escape mechanism by assigning it the TokenType.Escape category.
How it Works:
- Define: Register a token definition (e.g.,
\or'...') withTokenType.Escape. - Match: When the parser encounters this token, it "neutralizes" the special meaning of the text immediately following it (or captured within it).
- Output: The neutralized text is treated as a literal token.
Configuration Strategies:
- Backslash Style: Define
\\(matches\) as an escape.\{becomes literal{. - Smart Quote Style (Recommended): Define a pattern like
'([\{\}\[\]\|])'to only escape specific characters inside quotes.- Advantage: This solves the "Apostrophe Conflict." Since the pattern only matches specific symbols inside quotes, natural language like
User'sis ignored by the escape token and treated as a standard word, while'{'is treated as an escape.
- Advantage: This solves the "Apostrophe Conflict." Since the pattern only matches specific symbols inside quotes, natural language like
Capture Group Logic:If your escape token definition contains a capture group (parentheses in Regex), uCalc uses the content of the first group ($1) as the unescaped literal. If there are no groups, it uses the whole matched string.
Comparative Analysis: Why uCalc?
- vs. Regex: Regex imposes
\as the escape. uCalc lets you adapt. If you are parsing file paths (lots of\), you can switch your escape char to^or%to keep patterns readable. - vs. SQL/Legacy: Traditional SQL uses double-quotes (
'') for everything, which breaks natural language. uCalc's granular configuration allows precise targeting of reserved chars only.
Examples
{@Eval}, {@@Eval}, and escaping special characters in a pattern
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("'['{word}']'", "{@Eval: UCase(word)}");
t.FromTo("'{'{expr}'}'", "{@@Eval: expr}");
Console.WriteLine(t.Transform("Words like [this] and [that]."));
Console.WriteLine(t.Transform("Is {5*3} bigger than {5^3}?"));
Words like THIS and THAT.
Is 15 bigger than 125? using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.FromTo("'['{word}']'", "{@Eval: UCase(word)}"); t.FromTo("'{'{expr}'}'", "{@@Eval: expr}"); Console.WriteLine(t.Transform("Words like [this] and [that].")); Console.WriteLine(t.Transform("Is {5*3} bigger than {5^3}?"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.FromTo("'['{word}']'", "{@Eval: UCase(word)}");
t.FromTo("'{'{expr}'}'", "{@@Eval: expr}");
cout << t.Transform("Words like [this] and [that].") << endl;
cout << t.Transform("Is {5*3} bigger than {5^3}?") << endl;
}
Words like THIS and THAT.
Is 15 bigger than 125? #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.FromTo("'['{word}']'", "{@Eval: UCase(word)}"); t.FromTo("'{'{expr}'}'", "{@@Eval: expr}"); cout << t.Transform("Words like [this] and [that].") << endl; cout << t.Transform("Is {5*3} bigger than {5^3}?") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.FromTo("'['{word}']'", "{@Eval: UCase(word)}")
t.FromTo("'{'{expr}'}'", "{@@Eval: expr}")
Console.WriteLine(t.Transform("Words like [this] and [that]."))
Console.WriteLine(t.Transform("Is {5*3} bigger than {5^3}?"))
End Sub
End Module
Words like THIS and THAT.
Is 15 bigger than 125? Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.FromTo("'['{word}']'", "{@Eval: UCase(word)}") t.FromTo("'{'{expr}'}'", "{@@Eval: expr}") Console.WriteLine(t.Transform("Words like [this] and [that].")) Console.WriteLine(t.Transform("Is {5*3} bigger than {5^3}?")) End Sub End Module