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.

WasModified = [bool]

Property

Product: 

Transformer Library

Class: 

Transformer

Checks if the most recent transformation operation resulted in any changes to the text.

Remarks

⚡️ Performance Optimization: The WasModified Property

The @WasModified property is a boolean flag that indicates whether the most recent transformation operation resulted in any changes to the source text. It is a crucial tool for optimizing applications by avoiding unnecessary work when no modifications have occurred.

⚙️ How It Works

After calling Transform(), Filter(), or even Find(), this property will be true if any rule successfully replaced or altered the text. If no rules matched, or if all matching rules were find-only (Pattern()), the property will be false.

The state of this flag is reset with each new transformation call.

🎯 Primary Use Case: Avoiding Unnecessary Operations

Retrieving a large string from the transformer (e.g., via @Text()) involves a data copy. For multi-megabyte documents, this can be an expensive operation. @WasModified allows you to skip this copy, as well as any subsequent processing (like writing to a file, updating a UI, or logging), if the content is unchanged.

// Perform the transformationt.Transform();// Only proceed if the text was actually changedif (t.WasModified) {    // Perform expensive operations here    var newText = t.Text;    // SaveToFile(newText);}

💡 Why uCalc? (Comparative Analysis)

Without this built-in property, a developer would have to implement this check manually, which is inefficient and verbose.

Typical Manual Approach:

// Store the original textvar originalText = t.Text;// Perform the transformationt.Transform();// Manually compare the strings to see if a change occurredif (t.Text != originalText) {    Console.WriteLine("Text was modified.");}

This manual comparison is very inefficient, especially for large strings, as it requires the entire string to be scanned character by character.

@WasModified is superior because it relies on a simple internal flag that the transformer engine sets during its processing. Checking this boolean flag is an O(1) operation, providing an instantaneous result regardless of the text size. This makes it the ideal, high-performance solution for change detection in transformation pipelines.

Examples

Demonstrates the basic true/false state of the WasModified flag.
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.FromTo("a", "*a good*");

// Case 1: A match occurs, text is modified.
t.Text = "This is a test";
t.Transform();
Console.WriteLine($"Modified: {t.WasModified}");

// Case 2: No match occurs, text is unchanged.
t.Text = "This is another test";
t.Transform();
Console.WriteLine($"Modified: {t.WasModified}");
				
			
Modified: True
Modified: False
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

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

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.FromTo("a", "*a good*");

   // Case 1: A match occurs, text is modified.
   t.Text("This is a test");
   t.Transform();
   cout << "Modified: " << tf(t.WasModified()) << endl;

   // Case 2: No match occurs, text is unchanged.
   t.Text("This is another test");
   t.Transform();
   cout << "Modified: " << tf(t.WasModified()) << endl;
}
				
			
Modified: True
Modified: False
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.FromTo("a", "*a good*")
      
      '// Case 1: A match occurs, text is modified.
      t.Text = "This is a test"
      t.Transform()
      Console.WriteLine($"Modified: {t.WasModified}")
      
      '// Case 2: No match occurs, text is unchanged.
      t.Text = "This is another test"
      t.Transform()
      Console.WriteLine($"Modified: {t.WasModified}")
   End Sub
End Module
				
			
Modified: True
Modified: False
Shows how to use WasModified to avoid an expensive operation, like saving to a file, if no changes were made during a data sanitization process.
				
					using uCalcSoftware;

var uc = new uCalc();
var sanitizer = new uCalc.Transformer();
sanitizer.FromTo("error", "ERROR");

// Simulate processing multiple logs
string log1 = "status: ok";
string log2 = "status: error";

Console.WriteLine("--- Processing Log 1 ---");
sanitizer.Text = log1;
sanitizer.Transform();
if (sanitizer.WasModified) {
   Console.WriteLine("Change detected. Saving updated log...");
   // SaveToFile(sanitizer.GetText());
} else {
   Console.WriteLine("No changes. Skipping save.");
}

Console.WriteLine("");
Console.WriteLine("--- Processing Log 2 ---");
sanitizer.Text = log2;
sanitizer.Transform();
if (sanitizer.WasModified) {
   Console.WriteLine("Change detected. Saving updated log...");
   // SaveToFile(sanitizer.GetText());
   Console.WriteLine($"Updated log: {sanitizer.Text}");
} else {
   Console.WriteLine("No changes. Skipping save.");
}
				
			
--- Processing Log 1 ---
No changes. Skipping save.

--- Processing Log 2 ---
Change detected. Saving updated log...
Updated log: status: ERROR
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer sanitizer;
   sanitizer.FromTo("error", "ERROR");

   // Simulate processing multiple logs
   string log1 = "status: ok";
   string log2 = "status: error";

   cout << "--- Processing Log 1 ---" << endl;
   sanitizer.Text(log1);
   sanitizer.Transform();
   if (sanitizer.WasModified()) {
      cout << "Change detected. Saving updated log..." << endl;
      // SaveToFile(sanitizer.GetText());
   } else {
      cout << "No changes. Skipping save." << endl;
   }

   cout << "" << endl;
   cout << "--- Processing Log 2 ---" << endl;
   sanitizer.Text(log2);
   sanitizer.Transform();
   if (sanitizer.WasModified()) {
      cout << "Change detected. Saving updated log..." << endl;
      // SaveToFile(sanitizer.GetText());
      cout << "Updated log: " << sanitizer.Text() << endl;
   } else {
      cout << "No changes. Skipping save." << endl;
   }
}
				
			
--- Processing Log 1 ---
No changes. Skipping save.

--- Processing Log 2 ---
Change detected. Saving updated log...
Updated log: status: ERROR
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim sanitizer As New uCalc.Transformer()
      sanitizer.FromTo("error", "ERROR")
      
      '// Simulate processing multiple logs
      Dim log1 As String = "status: ok"
      Dim log2 As String = "status: error"
      
      Console.WriteLine("--- Processing Log 1 ---")
      sanitizer.Text = log1
      sanitizer.Transform()
      If sanitizer.WasModified Then
         Console.WriteLine("Change detected. Saving updated log...")
         '// SaveToFile(sanitizer.GetText());
      Else
         Console.WriteLine("No changes. Skipping save.")
      End If
      
      Console.WriteLine("")
      Console.WriteLine("--- Processing Log 2 ---")
      sanitizer.Text = log2
      sanitizer.Transform()
      If sanitizer.WasModified Then
         Console.WriteLine("Change detected. Saving updated log...")
         '// SaveToFile(sanitizer.GetText());
         Console.WriteLine($"Updated log: {sanitizer.Text}")
      Else
         Console.WriteLine("No changes. Skipping save.")
      End If
   End Sub
End Module
				
			
--- Processing Log 1 ---
No changes. Skipping save.

--- Processing Log 2 ---
Change detected. Saving updated log...
Updated log: status: ERROR
WasModified
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("a", "*a good*");

t.Text = "This is a test";
Console.WriteLine(t.Transform());
Console.WriteLine($"Modified: {t.WasModified}");
Console.WriteLine("");

t.Text = "This is another test";
Console.WriteLine(t.Transform());
Console.WriteLine($"Modified: {t.WasModified}");
				
			
This is *a good* test
Modified: True

This is another test
Modified: False
				
					#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();
   t.FromTo("a", "*a good*");

   t.Text("This is a test");
   cout << t.Transform() << endl;
   cout << "Modified: " << tf(t.WasModified()) << endl;
   cout << "" << endl;

   t.Text("This is another test");
   cout << t.Transform() << endl;
   cout << "Modified: " << tf(t.WasModified()) << endl;
}
				
			
This is *a good* test
Modified: True

This is another test
Modified: False
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.FromTo("a", "*a good*")
      
      t.Text = "This is a test"
      Console.WriteLine(t.Transform())
      Console.WriteLine($"Modified: {t.WasModified}")
      Console.WriteLine("")
      
      t.Text = "This is another test"
      Console.WriteLine(t.Transform())
      Console.WriteLine($"Modified: {t.WasModified}")
   End Sub
End Module
				
			
This is *a good* test
Modified: True

This is another test
Modified: False