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.

WhitespaceSensitive = [bool]

Property

Product: 

Transformer Library

Class: 

Rule

Gets or sets whether pattern matching for this rule treats whitespace as a significant token, overriding the transformer's default setting.

Remarks

📏 Controlling Whitespace Significance

The WhitespaceSensitive property controls how a pattern rule interprets horizontal whitespace (spaces and tabs). By default, uCalc is whitespace-insensitive, offering flexibility. This property allows you to enforce strict whitespace matching for specific rules.

This per-rule setting overrides the global behavior defined on the parent Transformer's DefaultRuleSet.

⚙️ Behavior

SettingBehavior
false (Default)Insensitive. Whitespace is ignored. A space in a pattern can match any amount of horizontal whitespace in the source text, including none. The engine focuses on non-whitespace tokens.
trueSensitive. Whitespace becomes a significant token. A space in the pattern must match exactly one whitespace token in the source. This is crucial for formats where indentation or column alignment matters.

💡 Why uCalc? (Comparative Analysis)

This property provides a level of granular control not easily achieved with standard regular expressions.

  • vs. Regular Expressions: In regex, handling variable spacing requires littering patterns with \s+ or \s*. uCalc's default (false) behavior handles this automatically, making patterns cleaner and more readable. Enabling WhitespaceSensitive(true) is like making spaces in your pattern behave like \s+ in regex, but on a token level. This is a declarative switch rather than an imperative pattern change.

  • vs. Global Flags: Many regex engines apply case-sensitivity or multi-line options to the entire pattern. uCalc allows you to mix whitespace-sensitive and -insensitive rules within the same Transformer, letting them run concurrently. This is powerful for parsing hybrid documents that might have both structured (whitespace-sensitive) and unstructured (whitespace-insensitive) sections.

Examples

WhitespaceSensitive()
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var Text = "This is a test.";
var p = t.FromTo("This {words:3}", "[{words}]");

Console.WriteLine($"Input: {Text}");
Console.WriteLine($"Pattern: {p.Pattern}");
Console.WriteLine("");

Console.WriteLine("3 captured tokens are in brackets");
Console.WriteLine("");

Console.WriteLine($"WhitespaceSensitive = {t.DefaultRuleSet.WhitespaceSensitive}");
Console.WriteLine(t.Transform(Text));
Console.WriteLine("");

t.DefaultRuleSet.WhitespaceSensitive = true;
Console.WriteLine($"WhitespaceSensitive = {t.DefaultRuleSet.WhitespaceSensitive}");
Console.WriteLine(t.Transform(Text));

				
			
Input: This is a test.
Pattern: This {words:3}

3 captured tokens are in brackets

WhitespaceSensitive = False
[is a test].

WhitespaceSensitive = True
[ is ]a test.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto Text = "This is a test.";
   auto p = t.FromTo("This {words:3}", "[{words}]");

   cout << "Input: " << Text << endl;
   cout << "Pattern: " << p.Pattern() << endl;
   cout << "" << endl;

   cout << "3 captured tokens are in brackets" << endl;
   cout << "" << endl;

   cout << "WhitespaceSensitive = " << tf(t.DefaultRuleSet().WhitespaceSensitive()) << endl;
   cout << t.Transform(Text) << endl;
   cout << "" << endl;

   t.DefaultRuleSet().WhitespaceSensitive(true);
   cout << "WhitespaceSensitive = " << tf(t.DefaultRuleSet().WhitespaceSensitive()) << endl;
   cout << t.Transform(Text) << endl;

}
				
			
Input: This is a test.
Pattern: This {words:3}

3 captured tokens are in brackets

WhitespaceSensitive = False
[is a test].

WhitespaceSensitive = True
[ is ]a test.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim Text = "This is a test."
      Dim p = t.FromTo("This {words:3}", "[{words}]")
      
      Console.WriteLine($"Input: {Text}")
      Console.WriteLine($"Pattern: {p.Pattern}")
      Console.WriteLine("")
      
      Console.WriteLine("3 captured tokens are in brackets")
      Console.WriteLine("")
      
      Console.WriteLine($"WhitespaceSensitive = {t.DefaultRuleSet.WhitespaceSensitive}")
      Console.WriteLine(t.Transform(Text))
      Console.WriteLine("")
      
      t.DefaultRuleSet.WhitespaceSensitive = true
      Console.WriteLine($"WhitespaceSensitive = {t.DefaultRuleSet.WhitespaceSensitive}")
      Console.WriteLine(t.Transform(Text))
      
   End Sub
End Module
				
			
Input: This is a test.
Pattern: This {words:3}

3 captured tokens are in brackets

WhitespaceSensitive = False
[is a test].

WhitespaceSensitive = True
[ is ]a test.