@@ -107,8 +107,8 @@ public class CSharpToCppTransformer : TextTransformer
107107 // public: inline static Range<int> SByte = Range<int>(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
108108 ( new Regex ( @"(?<access>(private|protected|public): )?static readonly (?<type>[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?<name>[a-zA-Z0-9_]+) = new \k<type>\((?<arguments>[^\n]+)\);" ) , "${access}inline static ${type} ${name} = ${type}(${arguments});" , 0 ) ,
109109 // public: static readonly string ExceptionContentsSeparator = "---";
110- // public: inline static const char* ExceptionContentsSeparator = "---";
111- ( new Regex ( @"(?<access>(private|protected|public): )?(const|static readonly) string (?<name>[a-zA-Z0-9_]+) = ""(?<string>(\""|[^""\r\n])+)"";" ) , "${access}inline static const char* ${name} = \" ${string}\" ;" , 0 ) ,
110+ // public: inline static std::string ExceptionContentsSeparator = "---";
111+ ( new Regex ( @"(?<access>(private|protected|public): )?(const|static readonly) string (?<name>[a-zA-Z0-9_]+) = ""(?<string>(\""|[^""\r\n])+)"";" ) , "${access}inline static std::string ${name} = \" ${string}\" ;" , 0 ) ,
112112 // private: const int MaxPath = 92;
113113 // private: inline static const int MaxPath = 92;
114114 ( new Regex ( @"(?<access>(private|protected|public): )?(const|static readonly) (?<type>[a-zA-Z0-9]+) (?<name>[_a-zA-Z0-9]+) = (?<value>[^;\r\n]+);" ) , "${access}inline static const ${type} ${name} = ${value};" , 0 ) ,
@@ -151,8 +151,8 @@ public class CSharpToCppTransformer : TextTransformer
151151 // Count => GetSizeOrZero(Root);
152152 // GetCount() { return GetSizeOrZero(Root); }
153153 ( new Regex ( @"(\W)([A-Z][a-zA-Z]+)\s+=>\s+([^;\r\n]+);" ) , "$1Get$2() { return $3; }" , 0 ) ,
154- // ArgumentInRange(const char* message) { const char* messageBuilder() { return message; }
155- // ArgumentInRange(const char* message) { auto messageBuilder = [&]() -> const char* { return message; };
154+ // ArgumentInRange(string message) { string messageBuilder() { return message; }
155+ // ArgumentInRange(string message) { auto messageBuilder = [&]() -> string { return message; };
156156 ( new Regex ( @"(?<before>\W[_a-zA-Z0-9]+\([^\)\n]*\)[\s\n]*{[\s\n]*([^{}]|\n)*?(\r?\n)?[ \t]*)(?<returnType>[_a-zA-Z0-9*:]+[_a-zA-Z0-9*: ]*) (?<methodName>[_a-zA-Z0-9]+)\((?<arguments>[^\)\n]*)\)\s*{(?<body>(""[^""\n]+""|[^}]|\n)+?)}" ) , "${before}auto ${methodName} = [&]() -> ${returnType} {${body}};" , 10 ) ,
157157 // Func<TElement> treeCount
158158 // std::function<TElement()> treeCount
@@ -185,8 +185,8 @@ public class CSharpToCppTransformer : TextTransformer
185185 // return {range.Minimum, range.Maximum}
186186 ( new Regex ( @"(?<before>return\s*)\((?<values>[^\)\n]+)\)(?!\()(?<after>\W)" ) , "${before}{${values}}${after}" , 0 ) ,
187187 // string
188- // const char*
189- ( new Regex ( @"(\W)string(\W)" ) , "$1const char* $2" , 0 ) ,
188+ // std::string
189+ ( new Regex ( @"(\W)(?<!::) string(\W)" ) , "$1std::string $2" , 0 ) ,
190190 // System.ValueTuple
191191 // std::tuple
192192 ( new Regex ( @"(?<before>\W)(System\.)?ValueTuple(?!\s*=|\()(?<after>\W)" ) , "${before}std::tuple${after}" , 0 ) ,
@@ -290,14 +290,14 @@ public class CSharpToCppTransformer : TextTransformer
290290 // Assert::IsTrue
291291 ( new Regex ( @"(Assert)\.(True|False)" ) , "$1::Is$2" , 0 ) ,
292292 // $"Argument {argumentName} is null."
293- // std::string("Argument ").append(Platform::Converters::To<std::string>(argumentName)).append(" is null.").data()
294- ( new Regex ( @"\$""(?<left>(\\""|[^""\r\n])*){(?<expression>[_a-zA-Z0-9]+)}(?<right>(\\""|[^""\r\n])*)""" ) , "std::string($\" ${left}\" ).append(Platform::Converters::To<std::string>(${expression})).append(\" ${right}\" ).data() " , 10 ) ,
293+ // std::string("Argument ").append(Platform::Converters::To<std::string>(argumentName)).append(" is null.")
294+ ( new Regex ( @"\$""(?<left>(\\""|[^""\r\n])*){(?<expression>[_a-zA-Z0-9]+)}(?<right>(\\""|[^""\r\n])*)""" ) , "std::string($\" ${left}\" ).append(Platform::Converters::To<std::string>(${expression})).append(\" ${right}\" )" , 10 ) ,
295295 // $"
296296 // "
297297 ( new Regex ( @"\$""" ) , "\" " , 0 ) ,
298- // std::string(std::string("[").append(Platform::Converters::To<std::string>(Minimum)).append(", ").data()) .append(Platform::Converters::To<std::string>(Maximum)).append("]").data( )
299- // std::string("[").append(Platform::Converters::To<std::string>(Minimum)).append(", ").append(Platform::Converters::To<std::string>(Maximum)).append("]").data()
300- ( new Regex ( @"std::string\((?<begin>std::string\(""(\\""|[^""])*""\)(\.append\((Platform::Converters::To<std::string>\([^)\n]+\)|[^)\n]+)\))+)\.data\(\)\ )\.append" ) , "${begin}.append" , 10 ) ,
298+ // std::string(std::string("[").append(Platform::Converters::To<std::string>(Minimum)).append(", ")) .append(Platform::Converters::To<std::string>(Maximum)).append("]")
299+ // std::string("[").append(Platform::Converters::To<std::string>(Minimum)).append(", ").append(Platform::Converters::To<std::string>(Maximum)).append("]")
300+ ( new Regex ( @"std::string\((?<begin>std::string\(""(\\""|[^""])*""\)(\.append\((Platform::Converters::To<std::string>\([^)\n]+\)|[^)\n]+)\))+)\)\.append" ) , "${begin}.append" , 10 ) ,
301301 // Console.WriteLine("...")
302302 // printf("...\n")
303303 ( new Regex ( @"Console\.WriteLine\(""([^""\r\n]+)""\)" ) , "printf(\" $1\\ n\" )" , 0 ) ,
@@ -314,13 +314,13 @@ public class CSharpToCppTransformer : TextTransformer
314314 // bool operator ==(const Key &other) const { ... }
315315 ( new Regex ( @"(?<before>\r?\n[^\n]+bool )Equals\((?<type>[^\n{]+) (?<variable>[a-zA-Z0-9]+)\)(?<after>(\s|\n)*{)" ) , "${before}operator ==(const ${type} &${variable}) const${after}" , 0 ) ,
316316 // Insert scope borders.
317- // class Range { ... public: override const char* ToString() { return ...; }
318- // class Range {/*~Range<T>~*/ ... public: override const char* ToString() { return ...; }
319- ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)template <typename (?<typeParameter>[^<>\n]+)> (struct|class) (?<type>[a-zA-Z0-9]+<\k<typeParameter>>)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?<middle>((?!class|struct).|\n)+?)(?<toStringDeclaration>(?<access>(private|protected|public): )override const char\* ToString\(\))" ) , "${classDeclarationBegin}/*~${type}~*/${middle}${toStringDeclaration}" , 0 ) ,
317+ // class Range { ... public: override std::string ToString() { return ...; }
318+ // class Range {/*~Range<T>~*/ ... public: override std::string ToString() { return ...; }
319+ ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)template <typename (?<typeParameter>[^<>\n]+)> (struct|class) (?<type>[a-zA-Z0-9]+<\k<typeParameter>>)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?<middle>((?!class|struct).|\n)+?)(?<toStringDeclaration>(?<access>(private|protected|public): )override std::string ToString\(\))" ) , "${classDeclarationBegin}/*~${type}~*/${middle}${toStringDeclaration}" , 0 ) ,
320320 // Inside the scope of ~!Range!~ replace:
321- // public: override const char* ToString() { return ...; }
321+ // public: override std::string ToString() { return ...; }
322322 // public: operator std::string() const { return ...; }\n\npublic: friend std::ostream & operator <<(std::ostream &out, const A &obj) { return out << (std::string)obj; }
323- ( new Regex ( @"(?<scope>/\*~(?<type>[_a-zA-Z0-9<>:]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<type>~\*/)(.|\n))*?)(?<toStringDeclaration>\r?\n(?<indent>[ \t]*)(?<access>(private|protected|public): )override const char\* ToString\(\) (?<toStringMethodBody>{[^}\n]+}))" ) , "${scope}${separator}${before}" + Environment . NewLine + "${indent}${access}operator std::string() const ${toStringMethodBody}" + Environment . NewLine + Environment . NewLine + "${indent}${access}friend std::ostream & operator <<(std::ostream &out, const ${type} &obj) { return out << (std::string)obj; }" , 0 ) ,
323+ ( new Regex ( @"(?<scope>/\*~(?<type>[_a-zA-Z0-9<>:]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<type>~\*/)(.|\n))*?)(?<toStringDeclaration>\r?\n(?<indent>[ \t]*)(?<access>(private|protected|public): )override std::string ToString\(\) (?<toStringMethodBody>{[^}\n]+}))" ) , "${scope}${separator}${before}" + Environment . NewLine + "${indent}${access}operator std::string() const ${toStringMethodBody}" + Environment . NewLine + Environment . NewLine + "${indent}${access}friend std::ostream & operator <<(std::ostream &out, const ${type} &obj) { return out << (std::string)obj; }" , 0 ) ,
324324 // Remove scope borders.
325325 // /*~Range~*/
326326 //
@@ -383,8 +383,8 @@ public class CSharpToCppTransformer : TextTransformer
383383 ( new Regex ( @"(?<start>, |\()(System\.Text\.)?StringBuilder (?<variable>[a-zA-Z0-9]+)(?<end>,|\))" ) , "${start}/*~${variable}~*/std::string& ${variable}${end}" , 0 ) ,
384384 // Inside the scope of ~!added!~ replace:
385385 // sb.ToString()
386- // sb.data()
387- ( new Regex ( @"(?<scope>/\*~(?<variable>[a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<variable>~\*/)(.|\n))*?)\k<variable>\.ToString\(\)" ) , "${scope}${separator}${before}${variable}.data() " , 10 ) ,
386+ // sb
387+ ( new Regex ( @"(?<scope>/\*~(?<variable>[a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<variable>~\*/)(.|\n))*?)\k<variable>\.ToString\(\)" ) , "${scope}${separator}${before}${variable}" , 10 ) ,
388388 // sb.AppendLine(argument)
389389 // sb.append(Platform::Converters::To<std::string>(argument)).append(1, '\n')
390390 ( new Regex ( @"(?<scope>/\*~(?<variable>[a-zA-Z0-9]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~\k<variable>~\*/)(.|\n))*?)\k<variable>\.AppendLine\((?<argument>[^\),\r\n]+)\)" ) , "${scope}${separator}${before}${variable}.append(Platform::Converters::To<std::string>(${argument})).append(1, '\\ n')" , 10 ) ,
@@ -545,9 +545,12 @@ public class CSharpToCppTransformer : TextTransformer
545545 // new
546546 //
547547 ( new Regex ( @"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)new\s+" ) , "${before}" , 10 ) ,
548+ // x == null
549+ // x == nullptr
550+ ( new Regex ( @"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)(?<variable>[_a-zA-Z][_a-zA-Z0-9]+)(?<operator>\s*(==|!=)\s*)null(?<after>\W)" ) , "${before}${variable}${operator}nullptr${after}" , 10 ) ,
548551 // null
549- // nullptr
550- ( new Regex ( @"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)null(?<after>\W)" ) , "${before}nullptr ${after}" , 10 ) ,
552+ // {}
553+ ( new Regex ( @"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)null(?<after>\W)" ) , "${before}{} ${after}" , 10 ) ,
551554 // default
552555 // 0
553556 ( new Regex ( @"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)default(?<after>\W)" ) , "${before}0${after}" , 10 ) ,
0 commit comments