Skip to content

Commit 1ea0a87

Browse files
committed
Added support for inline static string constants in classes.
Static fields with class initializations are now using inline static fields in C++.
1 parent 7455695 commit 1ea0a87

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public class CSharpToCppTransformer : Transformer
2626
// out TProduct
2727
// TProduct
2828
(new Regex(@"(?<before>(<|, ))(in|out) (?<typeParameter>[a-zA-Z0-9]+)(?<after>(>|,))"), "${before}${typeParameter}${after}", null, 10),
29-
// static class Ensure ... public static readonly EnsureAlwaysExtensionRoot Always = new EnsureAlwaysExtensionRoot(); ... } }
30-
// static class Ensure ... static EnsureAlwaysExtensionRoot Always; ... } EnsureAlwaysExtensionRoot Ensure::Always; }
31-
(new Regex(@"static class (?<class>[a-zA-Z0-9]+)(?<before>[\s\S\r\n]+)public static readonly (?<type>[a-zA-Z0-9]+) (?<name>[a-zA-Z0-9_]+) = new \k<type>\(\);(?<after>[\s\S]+[\r\n]+)(?<indent>[ ]+)}(?<ending>[a-zA-Z:; \r\n]+}[ \r\n]+$)"), "static class ${class}${before}static ${type} ${name};${after}${indent}}\r\n${indent}${type} ${class}::${name};${ending}", null, 10),
3229
// public abstract class
3330
// class
3431
(new Regex(@"(public abstract|static) class"), "class", null, 0),
@@ -59,6 +56,12 @@ public class CSharpToCppTransformer : Transformer
5956
// Predicate<TArgument> predicate
6057
// std::function<bool(TArgument)> predicate
6158
(new Regex(@"Predicate<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)"), "std::function<bool($1)> $2", null, 0),
59+
// public static readonly EnsureAlwaysExtensionRoot Always = new EnsureAlwaysExtensionRoot();
60+
// inline static EnsureAlwaysExtensionRoot Always;
61+
(new Regex(@"public static readonly (?<type>[a-zA-Z0-9]+) (?<name>[a-zA-Z0-9_]+) = new \k<type>\(\);"), "inline static ${type} ${name};", null, 0),
62+
// public static readonly string ExceptionContentsSeparator = "---";
63+
// inline static const char* ExceptionContentsSeparator = "---";
64+
(new Regex(@"public static readonly string (?<name>[a-zA-Z0-9_]+) = ""(?<string>(\""|[^""])+)"";"), "inline static const char* ${name} = \"${string}\";", null, 0),
6265
// private const int MaxPath = 92;
6366
// static const int MaxPath = 92;
6467
(new Regex(@"private (const|static readonly) ([a-zA-Z0-9]+) ([_a-zA-Z0-9]+) = ([^;]+);"), "static const $2 $3 = $4;", null, 0),

0 commit comments

Comments
 (0)