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.

QuoteSensitive = [bool]

Property

Product: 

Transformer Library

Class: 

Rule

Controls whether a pattern rule respects quoted strings as atomic units, preventing matches from occurring inside them.

Remarks

🛡️ Structural Integrity: The QuoteSensitive Property

The QuoteSensitive property controls whether a pattern is aware of quoted strings, treating them as atomic, unbreakable units. When enabled (the default), it prevents a pattern from matching text that is inside a string literal, ensuring that transformations do not accidentally corrupt user data.

This is a fundamental feature for safely parsing structured text and a key advantage over traditional regular expressions, which are not context-aware.

⚙️ How It Works

This property acts as a switch for an individual rule's parsing logic, overriding the global setting inherited from the Transformer's DefaultRuleSet.

SettingBehavior
true (Default)Structurally Aware. The tokenizer identifies a quoted string (e.g., "Hello World") as a single, atomic Literal token. The pattern matching engine will not look "inside" this token, preventing partial matches.
falseStructurally Unaware. Quote characters (' and ") are treated like any other generic punctuation. The pattern matching engine will scan the text, allowing matches to occur inside string literals.

By default, uCalc recognizes single (') and double (") quotes. You can define your own custom quote tokens using uCalc.Tokens.Add.

While the default true behavior is a powerful safety feature, you must disable it when your pattern needs to capture a block of text that can contain its own quotes. This is common when defining custom delimited blocks, such as a [code]...[/code] tag, where the content between the tags must be captured literally, regardless of any quote characters it contains. The practical example below demonstrates this scenario.

💡 Why uCalc? (Comparative Analysis)

Matching around, but not inside, quoted strings is notoriously difficult with regular expressions. It requires complex negative lookbehind/lookahead assertions that are hard to write, read, and debug.

A Typical Regex Problem:Imagine you want to replace the variable x with y in the code var x = "The value of x is 10";. A simple regex \bx\b would incorrectly change both, resulting in var y = "The value of y is 10";.

uCalc's QuoteSensitive property solves this elegantly and by default:

  1. Tokenizer Awareness: The tokenizer runs first and identifies "The value of x is 10" as a single, opaque String token.
  2. Safe Matching: When the Transformer processes the token stream, a rule looking for the alphanumeric token x will match the first one but will skip over the String token entirely, leaving its contents untouched.

This "safe by default" behavior makes uCalc far more robust and reliable for code transformation and structured data parsing than pure regex solutions. You only disable QuoteSensitive when you explicitly need to operate on the content inside strings.

Examples

Succinct: Demonstrates the default `QuoteSensitive(true)` behavior, where a pattern match is ignored inside a string literal.
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.FromTo("fox", "CAT");

// The 'fox' inside the quotes is not replaced.
Console.WriteLine(t.Transform("The quick brown fox jumps over the 'lazy fox'."));
				
			
The quick brown CAT jumps over the 'lazy fox'.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.FromTo("fox", "CAT");

   // The 'fox' inside the quotes is not replaced.
   cout << t.Transform("The quick brown fox jumps over the 'lazy fox'.") << endl;
}
				
			
The quick brown CAT jumps over the 'lazy fox'.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.FromTo("fox", "CAT")
      
      '// The 'fox' inside the quotes is not replaced.
      Console.WriteLine(t.Transform("The quick brown fox jumps over the 'lazy fox'."))
   End Sub
End Module
				
			
The quick brown CAT jumps over the 'lazy fox'.
Practical: Creates a custom code block parser. `@QuoteSensitive(false)` is essential to allow the capture of content that contains its own quotes.
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var source = """
Some text... [code]print("Hello, World!") // Quoted with "
var x = 'test';[/code] ...more text.
""";

// This rule must disable QuoteSensitive and StatementSensitive to correctly
// capture the multi-line block containing single and double quotes.
var rule = t.FromTo("'['code']'{content}'['/code']'", """
```
{content}
```
""");
rule.QuoteSensitive = false;
rule.StatementSensitive = false;

Console.WriteLine(t.Transform(source));
				
			
Some text... ```
print("Hello, World!") // Quoted with "
var x = 'test';
``` ...more text.
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto source = R"(Some text... [code]print("Hello, World!") // Quoted with "
var x = 'test';[/code] ...more text.)";

   // This rule must disable QuoteSensitive and StatementSensitive to correctly
   // capture the multi-line block containing single and double quotes.
   auto rule = t.FromTo("'['code']'{content}'['/code']'", R"(```
{content}
```)");
   rule.QuoteSensitive(false);
   rule.StatementSensitive(false);

   cout << t.Transform(source) << endl;
}
				
			
Some text... ```
print("Hello, World!") // Quoted with "
var x = 'test';
``` ...more text.
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim source = "Some text... [code]print(""Hello, World!"") // Quoted with ""
var x = 'test';[/code] ...more text."
      
      '// This rule must disable QuoteSensitive and StatementSensitive to correctly
      '// capture the multi-line block containing single and double quotes.
      Dim rule = t.FromTo("'['code']'{content}'['/code']'", "```
{content}
```")
      rule.QuoteSensitive = false
      rule.StatementSensitive = false
      
      Console.WriteLine(t.Transform(source))
   End Sub
End Module
				
			
Some text... ```
print("Hello, World!") // Quoted with "
var x = 'test';
``` ...more text.
QuoteSensitive
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer().SetText("Test1 'a b c' a b c Test2 'a b c' a b c");

var Test1 = t.FromTo("Test1 {txt} b", "[{txt}]"); // defaults to QuoteSensitive = true
var Test2 = t.FromTo("Test2 {txt} b", "({txt})").SetQuoteSensitive(false);
t.Transform();

Console.WriteLine($"Test1 QuoteSensitive = {Test1.QuoteSensitive}");
Console.WriteLine($"Test2 QuoteSensitive = {Test2.QuoteSensitive}");

Console.WriteLine(t);
				
			
Test1 QuoteSensitive = True
Test2 QuoteSensitive = False
['a b c' a] c ('a) c' a b c
				
					#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().SetText("Test1 'a b c' a b c Test2 'a b c' a b c");

   auto Test1 = t.FromTo("Test1 {txt} b", "[{txt}]"); // defaults to QuoteSensitive = true
   auto Test2 = t.FromTo("Test2 {txt} b", "({txt})").SetQuoteSensitive(false);
   t.Transform();

   cout << "Test1 QuoteSensitive = " << tf(Test1.QuoteSensitive()) << endl;
   cout << "Test2 QuoteSensitive = " << tf(Test2.QuoteSensitive()) << endl;

   cout << t << endl;
}
				
			
Test1 QuoteSensitive = True
Test2 QuoteSensitive = False
['a b c' a] c ('a) c' a b c
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer().SetText("Test1 'a b c' a b c Test2 'a b c' a b c")
      
      Dim Test1 = t.FromTo("Test1 {txt} b", "[{txt}]") '// defaults to QuoteSensitive = true
      Dim Test2 = t.FromTo("Test2 {txt} b", "({txt})").SetQuoteSensitive(false)
      t.Transform()
      
      Console.WriteLine($"Test1 QuoteSensitive = {Test1.QuoteSensitive}")
      Console.WriteLine($"Test2 QuoteSensitive = {Test2.QuoteSensitive}")
      
      Console.WriteLine(t)
   End Sub
End Module
				
			
Test1 QuoteSensitive = True
Test2 QuoteSensitive = False
['a b c' a] c ('a) c' a b c