uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
[Note: for now the $ character is what's implemented instead of _]
Shortcut: _ (underscore)Associated Method: uCalc.Rule.WhitespaceCounts(bool)
Description: A postfix modifier that determines whether leading and trailing whitespace surrounding a matched token is captured as part of the variable's value.
By default, uCalc is "Whitespace Aware" in a way that prioritizes data cleanliness. When a pattern variable (like {v}) captures a token, the engine automatically strips any horizontal whitespace (spaces or tabs) that immediately precedes or follows that token. This ensures that a capture like 123 results in the clean string 123.
The Whitespace Retention (_) modifier is used to override this stripping behavior.
{v_}): Every whitespace character encountered that belongs to the variable's capture zone is preserved. This is essential for formatting-sensitive transformations.WhitespaceCounts() MethodYou can toggle this behavior globally using the WhitespaceCounts() method on the uCalc object.
uc.WhitespaceCounts(false): (Default) Variables strip surrounding whitespace.uc.WhitespaceCounts(true): All variables behave as if they have the _ postfix, retaining whitespace by default.Comparing how the engine handles a word surrounded by spaces.
New(uCalc::Transformer, t)// Default: " Word " results in "[Word]"t.FromTo("find {v}", "GOT:[{v}]")// Retention: " Word " results in "[ Word ]"t.FromTo("keep {v_}", "GOT:[{v}]")wl(t.Transform("find Hello ")) // Output: GOT:[Hello]wl(t.Transform("keep Hello ")) // Output: GOT:[ Hello ]When moving or wrapping blocks of text where the original horizontal alignment or indentation is part of the data's meaning.
New(uCalc::Transformer, t)// Use '_' to ensure indentation is kept when wrapping lines in tagst.FromTo("{line_}", "<li>{line}</li>")wl(t.Transform(" Indented Line"))[Expected Output]<li> Indented Line</li>
Verifying that enabling global whitespace retention makes all variables include padding by default.
// Enable whitespace retention globallyuc.WhitespaceCounts(true)New(uCalc::Transformer, t)t.FromTo("id {v}", "ID:{v}")wl(t.Transform("id 101"))[Expected Output]ID: 101
{@Eval}).WhitespaceCounts() is the established method name, though Whitespace Retention is used here as the descriptive title to better contrast with the default "stripping" behavior.ID: 215
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("A {txtA}. B {txtB$}.", "<{txtA}> <{txtB}>");
Console.WriteLine(t.Transform("A x y z . B x y z ."));
<x y z> < x y z > using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.FromTo("A {txtA}. B {txtB$}.", "<{txtA}> <{txtB}>"); Console.WriteLine(t.Transform("A x y z . B x y z ."));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.FromTo("A {txtA}. B {txtB$}.", "<{txtA}> <{txtB}>");
cout << t.Transform("A x y z . B x y z .") << endl;
}
<x y z> < x y z > #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.FromTo("A {txtA}. B {txtB$}.", "<{txtA}> <{txtB}>"); cout << t.Transform("A x y z . B x y z .") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.FromTo("A {txtA}. B {txtB$}.", "<{txtA}> <{txtB}>")
Console.WriteLine(t.Transform("A x y z . B x y z ."))
End Sub
End Module
<x y z> < x y z > Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.FromTo("A {txtA}. B {txtB$}.", "<{txtA}> <{txtB}>") Console.WriteLine(t.Transform("A x y z . B x y z .")) End Sub End Module