@@ -23,6 +23,9 @@ public class CSharpToCppTransformer : TextTransformer
2323 // Platform.Collections.Methods.Lists
2424 // Platform::Collections::Methods::Lists
2525 ( new Regex ( @"(namespace[^\r\n]+?)\.([^\r\n]+?)" ) , "$1::$2" , 20 ) ,
26+ // nameof(numbers)
27+ // "numbers"
28+ ( new Regex ( @"(?<before>\W)nameof\(([^)\n]+\.)?(?<name>[a-zA-Z0-9_]+)(<[^)\n]+>)?\)" ) , "${before}\" ${name}\" " , 0 ) ,
2629 // Insert markers
2730 // EqualityComparer<T> _equalityComparer = EqualityComparer<T>.Default;
2831 // EqualityComparer<T> _equalityComparer = EqualityComparer<T>.Default;/*~_comparer~*/
@@ -33,7 +36,7 @@ public class CSharpToCppTransformer : TextTransformer
3336 // Remove markers
3437 // /*~_equalityComparer~*/
3538 //
36- ( new Regex ( @"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/\r\n([ \t]*\r\n)? " ) , Environment . NewLine , 10 ) ,
39+ ( new Regex ( @"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/" ) , "" , 10 ) ,
3740 // Insert markers
3841 // Comparer<T> _comparer = Comparer<T>.Default;
3942 // Comparer<T> _comparer = Comparer<T>.Default;/*~_comparer~*/
@@ -44,10 +47,19 @@ public class CSharpToCppTransformer : TextTransformer
4447 // Remove markers
4548 // private static readonly Comparer<T> _comparer = Comparer<T>.Default;/*~_comparer~*/
4649 //
47- ( new Regex ( @"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/\r\n([ \t]*\r\n)? " ) , Environment . NewLine , 10 ) ,
50+ ( new Regex ( @"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/" ) , "" , 10 ) ,
4851 // Comparer<TArgument>.Default.Compare(maximumArgument, minimumArgument) < 0
4952 // maximumArgument < minimumArgument
5053 ( new Regex ( @"Comparer<[^>\n]+>\.Default\.Compare\(\s*(?<first>[^,)\n]+),\s*(?<second>[^\)\n]+)\s*\)\s*(?<comparison>[<>=]=?)\s*0(?<after>\D)" ) , "${first} ${comparison} ${second}${after}" , 0 ) ,
54+ // public static bool operator ==(Range<T> left, Range<T> right) => left.Equals(right);
55+ //
56+ ( new Regex ( @"\r?\n[^\n]+bool operator ==\((?<type>[^\n]+) (?<left>[a-zA-Z0-9]+), \k<type> (?<right>[a-zA-Z0-9]+)\) => (\k<left>|\k<right>)\.Equals\((\k<left>|\k<right>)\);" ) , "" , 10 ) ,
57+ // public static bool operator !=(Range<T> left, Range<T> right) => !(left == right);
58+ //
59+ ( new Regex ( @"\r?\n[^\n]+bool operator !=\((?<type>[^\n]+) (?<left>[a-zA-Z0-9]+), \k<type> (?<right>[a-zA-Z0-9]+)\) => !\((\k<left>|\k<right>) == (\k<left>|\k<right>)\);" ) , "" , 10 ) ,
60+ // public override bool Equals(object obj) => obj is Range<T> range ? Equals(range) : false;
61+ //
62+ ( new Regex ( @"\r?\n[^\n]+override bool Equals\((System\.)?[Oo]bject (?<this>[a-zA-Z0-9]+)\) => \k<this> is [^\n]+ (?<other>[a-zA-Z0-9]+) \? Equals\(\k<other>\) : false;" ) , "" , 10 ) ,
5163 // out TProduct
5264 // TProduct
5365 ( new Regex ( @"(?<before>(<|, ))(in|out) (?<typeParameter>[a-zA-Z0-9]+)(?<after>(>|,))" ) , "${before}${typeParameter}${after}" , 10 ) ,
@@ -289,6 +301,9 @@ public class CSharpToCppTransformer : TextTransformer
289301 // auto path = new TElement[MaxPath];
290302 // TElement path[MaxPath] = { {0} };
291303 ( new Regex ( @"(\r?\n[\t ]+)[a-zA-Z0-9]+ ([a-zA-Z0-9]+) = new ([a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];" ) , "$1$3 $2[$4] = { {0} };" , 0 ) ,
304+ // bool Equals(Range<T> other) { ... }
305+ // bool operator ==(const Key &other) const { ... }
306+ ( 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 ) ,
292307 // private: static readonly ConcurrentBag<std::exception> _exceptionsBag = new ConcurrentBag<std::exception>();
293308 // private: inline static std::mutex _exceptionsBag_mutex; \n\n private: inline static std::vector<std::exception> _exceptionsBag;
294309 ( new Regex ( @"(?<begin>\r?\n?(?<indent>[ \t]+))(?<access>(private|protected|public): )?static readonly ConcurrentBag<(?<argumentType>[^;\r\n]+)> (?<name>[_a-zA-Z0-9]+) = new ConcurrentBag<\k<argumentType>>\(\);" ) , "${begin}private: inline static std::mutex ${name}_mutex;" + Environment . NewLine + Environment . NewLine + "${indent}${access}inline static std::vector<${argumentType}> ${name};" , 0 ) ,
@@ -468,6 +483,9 @@ public class CSharpToCppTransformer : TextTransformer
468483 // ArgumentNullException
469484 // std::invalid_argument
470485 ( new Regex ( @"(?<before>\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)(System\.)?ArgumentNullException(?<after>\W)" ) , "${before}std::invalid_argument${after}" , 10 ) ,
486+ // struct Range<T> : IEquatable<Range<T>> {
487+ // struct Range<T> {
488+ ( new Regex ( @"(?<before>(struct|class) (?<type>[a-zA-Z0-9]+(<[^\n]+>)?)) : IEquatable<\k<type>>(?<after>(\s|\n)*{)" ) , "${before}${after}" , 0 ) ,
471489 // #region Always
472490 //
473491 ( new Regex ( @"(^|\r?\n)[ \t]*\#(region|endregion)[^\r\n]*(\r?\n|$)" ) , "" , 0 ) ,
@@ -486,6 +504,9 @@ public class CSharpToCppTransformer : TextTransformer
486504 // \n ... class
487505 // class
488506 ( new Regex ( @"(\S[\r\n]{1,2})?[\r\n]+class" ) , "$1class" , 0 ) ,
507+ // \n\n
508+ // \n
509+ ( new Regex ( @"\r?\n[ \t]*\r?\n" ) , Environment . NewLine , 50 ) ,
489510 } . Cast < ISubstitutionRule > ( ) . ToList ( ) ;
490511
491512 public CSharpToCppTransformer ( IList < ISubstitutionRule > extraRules ) : base ( FirstStage . Concat ( extraRules ) . Concat ( LastStage ) . ToList ( ) ) { }
0 commit comments