From 48714bde6a80565a44499eccc58e1ac667e52435 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 30 Mar 2020 05:02:29 +0300 Subject: Implemented protobuf C compiler minified! --- .../Tango.Protobuf/Compilers/CCompiler.cs | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/Tango.Protobuf/Compilers') 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; @@ -15,6 +16,11 @@ namespace Tango.Protobuf.Compilers /// public class CCompiler : ProtoCompiler { + /// + /// Gets or sets a value indicating whether this will minimize the code by omitting hard coded strings. + /// + public bool Minimize { get; set; } + /// /// Gets the compiler language. /// @@ -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()) + { + MinimizeFolder(childFolder); + } + + foreach (var childFile in folder.Results.OfType()) + { + 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, ""); } } } -- cgit v1.3.1