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.

Reset

Method

Product: 

Transformer Library

Class: 

Transformer

Clears a transformer's state, such as its input text, rules, or match results, allowing for reuse without creating a new instance.

Syntax

Reset(TransformerResetOption)

Parameters

resetOption
TransformerResetOption
(Default = TransformerResetOption::All)
Specifies which components of the transformer to clear. Defaults to clearing everything.

Return

Transformer

Returns the current Transformer object, allowing for a fluent, chainable interface.

Remarks

🔄 Reusing Transformers with Reset

The Reset method clears some or all of a Transformer's state, allowing it to be reused for a new task without the performance overhead of creating a new object. This is essential for optimizing applications that perform many different transformation tasks.

By default, Reset performs a complete cleanup, but you can target specific components by providing a member of the TransformerResetOption enumeration.

⚙️ Reset Options

The resetOption parameter lets you choose what to clear:

OptionBehavior
All (Default)Complete Reset. Clears input text, all rules (FromTo, Pattern, SkipOver), custom Tokens, transformation Passes, and match results.
InputClears Text Only. Resets the internal text string to empty. All rules and token definitions are preserved.
RulesClears Rules Only. Deletes all defined rules. The input text and custom token definitions remain.
TokensClears Tokens Only. Removes all custom token definitions and restores the default uCalc token set. Text and rules are preserved.
ResultsClears Matches Only. Empties the internal list of matches from the last Find(), Filter(), or Transform() operation.
PassesClears Passes Only. Removes any additional transformation passes created with Pass(), leaving the main pass (pass 0).

💡 Why Reset? (Comparative Analysis)

In a loop or a high-frequency processing scenario, you have two choices for handling multiple, independent transformation tasks:

  1. Create a New Transformer: var t = new uCalc.Transformer();This is simple but has a performance cost. It involves allocating memory, copying default token sets, and other setup overhead for every new object.

  2. Reuse and Reset: t.Reset()This is the high-performance option. Reset() clears the state of an existing object but reuses its memory allocation. It avoids the construction/destruction overhead, making it significantly faster for repetitive tasks.

Best Practice: For performance-critical applications, create a pool of Transformer objects and use Reset() to prepare them for each new task rather than creating new instances repeatedly.

Examples

Shows how a full reset clears all rules and input, allowing a transformer object to be reconfigured from a clean slate.
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var txt = "a b c d e";

t.Text = txt;
t.FromTo("a", "aaa");
t.FromTo("c", "xyz");

Console.WriteLine($"Input: {t}");
Console.WriteLine($"Transformed: {t.Transform()}");

Console.WriteLine("");
Console.WriteLine("Resetting...");
t.Reset();

Console.WriteLine($"Input after reset: {t}(empty)");
t.Text = "a b c d e";
Console.WriteLine($"New input: {t.Text}");
Console.WriteLine($"Transform after reset: {t.Transform().Text} (no rules exist)");

Console.WriteLine("");
Console.WriteLine("Defining new rules...");
t.FromTo("b", "ABC");
t.FromTo("d", "DDD");
Console.WriteLine($"Final transformed: {t.Transform().Text}");
				
			
Input: a b c d e
Transformed: aaa b xyz d e

Resetting...
Input after reset: (empty)
New input: a b c d e
Transform after reset: a b c d e (no rules exist)

Defining new rules...
Final transformed: a ABC c DDD e
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto txt = "a b c d e";

   t.Text(txt);
   t.FromTo("a", "aaa");
   t.FromTo("c", "xyz");

   cout << "Input: " << t << endl;
   cout << "Transformed: " << t.Transform() << endl;

   cout << "" << endl;
   cout << "Resetting..." << endl;
   t.Reset();

   cout << "Input after reset: " << t << "(empty)" << endl;
   t.Text("a b c d e");
   cout << "New input: " << t.Text() << endl;
   cout << "Transform after reset: " << t.Transform().Text() << " (no rules exist)" << endl;

   cout << "" << endl;
   cout << "Defining new rules..." << endl;
   t.FromTo("b", "ABC");
   t.FromTo("d", "DDD");
   cout << "Final transformed: " << t.Transform().Text() << endl;
}
				
			
Input: a b c d e
Transformed: aaa b xyz d e

Resetting...
Input after reset: (empty)
New input: a b c d e
Transform after reset: a b c d e (no rules exist)

Defining new rules...
Final transformed: a ABC c DDD e
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim txt = "a b c d e"
      
      t.Text = txt
      t.FromTo("a", "aaa")
      t.FromTo("c", "xyz")
      
      Console.WriteLine($"Input: {t}")
      Console.WriteLine($"Transformed: {t.Transform()}")
      
      Console.WriteLine("")
      Console.WriteLine("Resetting...")
      t.Reset()
      
      Console.WriteLine($"Input after reset: {t}(empty)")
      t.Text = "a b c d e"
      Console.WriteLine($"New input: {t.Text}")
      Console.WriteLine($"Transform after reset: {t.Transform().Text} (no rules exist)")
      
      Console.WriteLine("")
      Console.WriteLine("Defining new rules...")
      t.FromTo("b", "ABC")
      t.FromTo("d", "DDD")
      Console.WriteLine($"Final transformed: {t.Transform().Text}")
   End Sub
End Module
				
			
Input: a b c d e
Transformed: aaa b xyz d e

Resetting...
Input after reset: (empty)
New input: a b c d e
Transform after reset: a b c d e (no rules exist)

Defining new rules...
Final transformed: a ABC c DDD e
Transformer Reset()
				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var txt = "a b c d e";

t.Text = txt;
t.FromTo("a", "aaa");
t.FromTo("c", "xyz");

Console.WriteLine($"Input: {t}");
Console.WriteLine($"Transformed: {t.Transform()}");

Console.WriteLine("Reset");
t.Reset();

Console.WriteLine($"Input: {t}(empty)");
t.Text = "a b c d e";
Console.WriteLine($"New input: {t.Text}");
Console.WriteLine($"Transformed: {t.Transform().Text} (no transform)");
Console.WriteLine("New rules");

t.FromTo("b", "ABC");
t.FromTo("d", "DDD");
Console.WriteLine($"Transformed: {t.Transform().Text}");

				
			
Input: a b c d e
Transformed: aaa b xyz d e
Reset
Input: (empty)
New input: a b c d e
Transformed: a b c d e (no transform)
New rules
Transformed: a ABC c DDD e
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto txt = "a b c d e";

   t.Text(txt);
   t.FromTo("a", "aaa");
   t.FromTo("c", "xyz");

   cout << "Input: " << t << endl;
   cout << "Transformed: " << t.Transform() << endl;

   cout << "Reset" << endl;
   t.Reset();

   cout << "Input: " << t << "(empty)" << endl;
   t.Text("a b c d e");
   cout << "New input: " << t.Text() << endl;
   cout << "Transformed: " << t.Transform().Text() << " (no transform)" << endl;
   cout << "New rules" << endl;

   t.FromTo("b", "ABC");
   t.FromTo("d", "DDD");
   cout << "Transformed: " << t.Transform().Text() << endl;

}
				
			
Input: a b c d e
Transformed: aaa b xyz d e
Reset
Input: (empty)
New input: a b c d e
Transformed: a b c d e (no transform)
New rules
Transformed: a ABC c DDD e
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim txt = "a b c d e"
      
      t.Text = txt
      t.FromTo("a", "aaa")
      t.FromTo("c", "xyz")
      
      Console.WriteLine($"Input: {t}")
      Console.WriteLine($"Transformed: {t.Transform()}")
      
      Console.WriteLine("Reset")
      t.Reset()
      
      Console.WriteLine($"Input: {t}(empty)")
      t.Text = "a b c d e"
      Console.WriteLine($"New input: {t.Text}")
      Console.WriteLine($"Transformed: {t.Transform().Text} (no transform)")
      Console.WriteLine("New rules")
      
      t.FromTo("b", "ABC")
      t.FromTo("d", "DDD")
      Console.WriteLine($"Transformed: {t.Transform().Text}")
      
   End Sub
End Module
				
			
Input: a b c d e
Transformed: aaa b xyz d e
Reset
Input: (empty)
New input: a b c d e
Transformed: a b c d e (no transform)
New rules
Transformed: a ABC c DDD e