@@ -85,6 +85,9 @@ public class CSharpToCppTransformer : TextTransformer
8585 // public abstract class
8686 // class
8787 ( new Regex ( @"((public|protected|private|internal|abstract|static) )*(?<category>interface|class|struct)" ) , "${category}" , 0 ) ,
88+ // public: static implicit operator TargetType(SourceType source) { ... }
89+ // public: explicit operator TargetType() const { ... }
90+ ( new Regex ( @"(?<access>(private|protected|public): )static implicit operator (?<targetType>[^\(\n]+)\((?<sourceType>[^\s\(\n]+) (?<variable>[a-zA-Z0-9]+)\)" ) , "${access}explicit operator ${targetType}() const" , 0 ) ,
8891 // class GenericCollectionMethodsBase<TElement> {
8992 // template <typename TElement> class GenericCollectionMethodsBase {
9093 ( new Regex ( @"(?<before>\r?\n)(?<indent>[ \t]*)(?<type>class|struct) (?<typeName>[a-zA-Z0-9]+)<(?<typeParameters>[a-zA-Z0-9 ,]+)>(?<typeDefinitionEnding>[^{]+){" ) , "${before}${indent}template <typename ...> ${type} ${typeName};" + Environment . NewLine + "${indent}template <typename ${typeParameters}> ${type} ${typeName}<${typeParameters}>${typeDefinitionEnding}{" , 0 ) ,
@@ -150,8 +153,8 @@ public class CSharpToCppTransformer : TextTransformer
150153 // static void NotImplementedException(ThrowExtensionRoot root) { return throw new NotImplementedException(); }
151154 ( new Regex ( @"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+throw([^;\r\n]+);" ) , "$1$2$3$4$5$6$7$8($9) { throw$10; }" , 0 ) ,
152155 // SizeBalancedTree(int capacity) => a = b;
153- // SizeBalancedTree(int capacity) { a = b; }
154- ( new Regex ( @"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?(void )?([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);" ) , "$1$2$3$4$5$6 $7$8($9) { $10; }" , 0 ) ,
156+ // explicit SizeBalancedTree(int capacity) noexcept { a = b; }
157+ ( new Regex ( @"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?(void )?([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);" ) , "$1$2$3$4$5$6explicit $7$8($9) noexcept { $10; }" , 0 ) ,
155158 // int SizeBalancedTree(int capacity) => a;
156159 // int SizeBalancedTree(int capacity) { return a; }
157160 ( new Regex ( @"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);" ) , "$1$2$3$4$5$6$7$8($9) { return $10; }" , 0 ) ,
@@ -554,12 +557,12 @@ public class CSharpToCppTransformer : TextTransformer
554557 ( new Regex ( @"(?<classDeclarationBegin>\r?\n(?<indent>[\t ]*)(template\s*<[^<>\n]*> )?(struct|class) (?<fullType>(?<typeName>[a-zA-Z0-9]+)(<[^:\n]*>)?)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)" ) , "${classDeclarationBegin}/*~type~${typeName}~${fullType}~*/" , 0 ) ,
555558 // Inside the scope of /*~type~Range<T>~*/ insert inner scope and replace:
556559 // public: static implicit operator std::tuple<T, T>(Range<T> range)
557- // public: operator std::tuple<T, T>() const {/*~variable~Range<T>~*/
558- ( new Regex ( @"(?<scope>/\*~type~(?<typeName>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<typeName>~\k<fullType>~\*/)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator (?<targetType>[^\(\n]+)\((?<argumentDeclaration>\k<fullType> (?<variable>[a-zA-Z0-9]+))\)(?<after>\s*\n?\s*{)" ) , "${scope}${separator}${before}${access}operator ${targetType}() const${after}/*~variable~${variable}~*/" , 10 ) ,
560+ // public: explicit operator std::tuple<T, T>() const {/*~variable~Range<T>~*/
561+ ( new Regex ( @"(?<scope>/\*~type~(?<typeName>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<typeName>~\k<fullType>~\*/)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator (?<targetType>[^\(\n]+)\((?<argumentDeclaration>\k<fullType> (?<variable>[a-zA-Z0-9]+))\)(?<after>\s*\n?\s*{)" ) , "${scope}${separator}${before}${access}explicit operator ${targetType}() const${after}/*~variable~${variable}~*/" , 10 ) ,
559562 // Inside the scope of /*~type~Range<T>~*/ replace:
560563 // public: static implicit operator Range<T>(std::tuple<T, T> tuple) { return new Range<T>(std::get<1-1>(tuple), std::get<2-1>(tuple)); }
561- // public: Range(std::tuple<T, T> tuple) : Range(std::get<1-1>(tuple), std::get<2-1>(tuple)) { }
562- ( new Regex ( @"(?<scope>/\*~type~(?<typeName>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<typeName>~\k<fullType>~\*/)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator (\k<fullType>|\k<typeName>)\((?<arguments>[^{}\n]+)\)(\s|\n)*{(\s|\n)*return (new )?(\k<fullType>|\k<typeName>)\((?<passedArguments>[^\n]+)\);(\s|\n)*}" ) , "${scope}${separator}${before}${access}${typeName}(${arguments}) : ${typeName}(${passedArguments}) { }" , 10 ) ,
564+ // public: explicit Range(std::tuple<T, T> tuple) : Range(std::get<1-1>(tuple), std::get<2-1>(tuple)) { }
565+ ( new Regex ( @"(?<scope>/\*~type~(?<typeName>[^~\n\*]+)~(?<fullType>[^~\n\*]+)~\*/)(?<separator>.|\n)(?<before>((?<!/\*~type~\k<typeName>~\k<fullType>~\*/)(.|\n))*?)(?<access>(private|protected|public): )static implicit operator (\k<fullType>|\k<typeName>)\((?<arguments>[^{}\n]+)\)(\s|\n)*{(\s|\n)*return (new )?(\k<fullType>|\k<typeName>)\((?<passedArguments>[^\n]+)\);(\s|\n)*}" ) , "${scope}${separator}${before}${access}explicit ${typeName}(${arguments}) : ${typeName}(${passedArguments}) { }" , 10 ) ,
563566 // Inside the scope of /*~variable~range~*/ replace:
564567 // range.Minimum
565568 // this->Minimum
0 commit comments