@@ -23,6 +23,9 @@ public class CSharpToCppTransformer : TextTransformer
23
23
// Platform.Collections.Methods.Lists
24
24
// Platform::Collections::Methods::Lists
25
25
( 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 ) ,
26
29
// Insert markers
27
30
// EqualityComparer<T> _equalityComparer = EqualityComparer<T>.Default;
28
31
// EqualityComparer<T> _equalityComparer = EqualityComparer<T>.Default;/*~_comparer~*/
@@ -33,7 +36,7 @@ public class CSharpToCppTransformer : TextTransformer
33
36
// Remove markers
34
37
// /*~_equalityComparer~*/
35
38
//
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 ) ,
37
40
// Insert markers
38
41
// Comparer<T> _comparer = Comparer<T>.Default;
39
42
// Comparer<T> _comparer = Comparer<T>.Default;/*~_comparer~*/
@@ -44,10 +47,19 @@ public class CSharpToCppTransformer : TextTransformer
44
47
// Remove markers
45
48
// private static readonly Comparer<T> _comparer = Comparer<T>.Default;/*~_comparer~*/
46
49
//
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 ) ,
48
51
// Comparer<TArgument>.Default.Compare(maximumArgument, minimumArgument) < 0
49
52
// maximumArgument < minimumArgument
50
53
( 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 ) ,
51
63
// out TProduct
52
64
// TProduct
53
65
( new Regex ( @"(?<before>(<|, ))(in|out) (?<typeParameter>[a-zA-Z0-9]+)(?<after>(>|,))" ) , "${before}${typeParameter}${after}" , 10 ) ,
@@ -289,6 +301,9 @@ public class CSharpToCppTransformer : TextTransformer
289
301
// auto path = new TElement[MaxPath];
290
302
// TElement path[MaxPath] = { {0} };
291
303
( 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 ) ,
292
307
// private: static readonly ConcurrentBag<std::exception> _exceptionsBag = new ConcurrentBag<std::exception>();
293
308
// private: inline static std::mutex _exceptionsBag_mutex; \n\n private: inline static std::vector<std::exception> _exceptionsBag;
294
309
( 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
468
483
// ArgumentNullException
469
484
// std::invalid_argument
470
485
( 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 ) ,
471
489
// #region Always
472
490
//
473
491
( new Regex ( @"(^|\r?\n)[ \t]*\#(region|endregion)[^\r\n]*(\r?\n|$)" ) , "" , 0 ) ,
@@ -486,6 +504,9 @@ public class CSharpToCppTransformer : TextTransformer
486
504
// \n ... class
487
505
// class
488
506
( 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 ) ,
489
510
} . Cast < ISubstitutionRule > ( ) . ToList ( ) ;
490
511
491
512
public CSharpToCppTransformer ( IList < ISubstitutionRule > extraRules ) : base ( FirstStage . Concat ( extraRules ) . Concat ( LastStage ) . ToList ( ) ) { }
0 commit comments