diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-30 05:02:29 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-30 05:02:29 +0300 |
| commit | 48714bde6a80565a44499eccc58e1ac667e52435 (patch) | |
| tree | a402c042cc8cc7ac426bf827bfab735a69565ec9 /Software/Visual_Studio/Tango.Protobuf/Compilers | |
| parent | db8dcffe2f434d97d57ea1a104fa683bf2735835 (diff) | |
| download | Tango-48714bde6a80565a44499eccc58e1ac667e52435.tar.gz Tango-48714bde6a80565a44499eccc58e1ac667e52435.zip | |
Implemented protobuf C compiler minified!
Diffstat (limited to 'Software/Visual_Studio/Tango.Protobuf/Compilers')
| -rw-r--r-- | Software/Visual_Studio/Tango.Protobuf/Compilers/CCompiler.cs | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Protobuf/Compilers/CCompiler.cs b/Software/Visual_Studio/Tango.Protobuf/Compilers/CCompiler.cs index 91f8d1502..707466857 100644 --- a/Software/Visual_Studio/Tango.Protobuf/Compilers/CCompiler.cs +++ b/Software/Visual_Studio/Tango.Protobuf/Compilers/CCompiler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Tango.Core.Helpers; using Tango.Core.IO; @@ -16,6 +17,11 @@ namespace Tango.Protobuf.Compilers public class CCompiler : ProtoCompiler { /// <summary> + /// Gets or sets a value indicating whether this <see cref="CCompiler"/> will minimize the code by omitting hard coded strings. + /// </summary> + public bool Minimize { get; set; } + + /// <summary> /// Gets the compiler language. /// </summary> public override CompilerLanguage Language => CompilerLanguage.C; @@ -94,7 +100,38 @@ namespace Tango.Protobuf.Compilers File.WriteAllText(file, str); } - return base.CompileFolder(temp.Path); + var result = base.CompileFolder(temp.Path); + + if (Minimize) + { + MinimizeFolder(result); + } + + return result; + } + + private void MinimizeFolder(CompilerFolderResult folder) + { + foreach (var childFolder in folder.Results.OfType<CompilerFolderResult>()) + { + MinimizeFolder(childFolder); + } + + foreach (var childFile in folder.Results.OfType<CompilerFileResult>()) + { + MinimizeFile(childFile); + } + } + + private void MinimizeFile(CompilerFileResult file) + { + file.Content = MinimizeCode(file.Content); + } + + private String MinimizeCode(String code) + { + Regex reg = new Regex("(?<=\")(\\w{1,})(?=\")"); + return reg.Replace(code, ""); } } } |
