Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ public class CSharpToCppTransformer : TextTransformer
// string
// std::string
(new Regex(@"(?<before>\W)(?<!::)string(?<after>\W)"), "${before}std::string${after}", 0),
// Constructor(std::string param) { field = param; }
// Constructor(std::string param) : field(std::move(param)) { }
(new Regex(@"(?<access>(private|protected|public): )?(?<constructor>[a-zA-Z0-9_]+\((?<params>[^)]*std::string [a-zA-Z0-9_]+[^)]*)\))\s*{\s*(?<field>[a-zA-Z0-9_]+) = (?<param>[a-zA-Z0-9_]+);\s*}"), "${access}${constructor} : ${field}(std::move(${param})) { }", 0),
// System.ValueTuple
// std::tuple
(new Regex(@"(?<before>\W)(System\.)?ValueTuple(?!\s*=|\()(?<after>\W)"), "${before}std::tuple${after}", 0),
Expand Down
11 changes: 11 additions & 0 deletions examples/test_constructor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

class TestClass
{
private string field;

public TestClass(string stringParam)
{
field = stringParam;
}
}
18 changes: 18 additions & 0 deletions examples/test_transform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Platform.RegularExpressions.Transformer.CSharpToCpp;

var transformer = new CSharpToCppTransformer();
var input = @"class TestClass
{
private string field;

public TestClass(string stringParam)
{
field = stringParam;
}
}";

Console.WriteLine("Input:");
Console.WriteLine(input);
Console.WriteLine("\nOutput:");
var result = transformer.Transform(input);
Console.WriteLine(result);
Loading