A real-world refactoring task to rename a function, showing how uCalc correctly ignores matches inside comments and strings by default.

ID: 1227

				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
// This rule replaces the ALPHANUMERIC token 'get_data', not just the text.
t.FromTo("get_data", "fetch_records");

var code = """

// Note: 'get_data' is the old function name.
results = get_data(source);
print("The 'get_data' function was called.");

""";

// The default tokenizer recognizes the comment and string literal as separate tokens,
// so the rule to replace the function name doesn't affect them.
Console.WriteLine(t.Transform(code));
				
			
// Note: 'get_data' is the old function name.
results = fetch_records(source);
print("The 'get_data' function was called.");
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   // This rule replaces the ALPHANUMERIC token 'get_data', not just the text.
   t.FromTo("get_data", "fetch_records");

   auto code = R"(
// Note: 'get_data' is the old function name.
results = get_data(source);
print("The 'get_data' function was called.");
)";

   // The default tokenizer recognizes the comment and string literal as separate tokens,
   // so the rule to replace the function name doesn't affect them.
   cout << t.Transform(code) << endl;
}
				
			
// Note: 'get_data' is the old function name.
results = fetch_records(source);
print("The 'get_data' function was called.");
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      '// This rule replaces the ALPHANUMERIC token 'get_data', not just the text.
      t.FromTo("get_data", "fetch_records")
      
      Dim code = "
// Note: 'get_data' is the old function name.
results = get_data(source);
print(""The 'get_data' function was called."");
"
      
      '// The default tokenizer recognizes the comment and string literal as separate tokens,
      '// so the rule to replace the function name doesn't affect them.
      Console.WriteLine(t.Transform(code))
   End Sub
End Module
				
			
// Note: 'get_data' is the old function name.
results = fetch_records(source);
print("The 'get_data' function was called.");