diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2019-07-18 04:08:24 +0200 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2019-08-04 01:57:53 +0200 |
commit | 0b94203a79d3261d4cc3bbcdb3438a5a45c8c572 (patch) | |
tree | d36bb081a3bda748a55a996578efb650d78a06b2 /modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs | |
parent | 4b7b1b0d4acf8d49505a839a0aa745ce60641545 (diff) |
C#: Add Ide Connection library and server for the editor
This will be used for communicating between the Godot editor and external IDEs/editors, for things like opening files, triggering hot-reload and running the game with a debugger attached.
Diffstat (limited to 'modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs')
-rw-r--r-- | modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs b/modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs new file mode 100644 index 0000000000..9e4cd6ec1a --- /dev/null +++ b/modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs @@ -0,0 +1,46 @@ +using System.Linq; +using System.Text; + +namespace GodotTools.IdeConnection +{ + public class MessageComposer + { + private readonly StringBuilder stringBuilder = new StringBuilder(); + + private static readonly char[] CharsToEscape = { '\\', '"' }; + + public void AddArgument(string argument) + { + AddArgument(argument, quoted: argument.Contains(",")); + } + + public void AddArgument(string argument, bool quoted) + { + if (stringBuilder.Length > 0) + stringBuilder.Append(','); + + if (quoted) + { + stringBuilder.Append('"'); + + foreach (char @char in argument) + { + if (CharsToEscape.Contains(@char)) + stringBuilder.Append('\\'); + stringBuilder.Append(@char); + } + + stringBuilder.Append('"'); + } + else + { + stringBuilder.Append(argument); + } + } + + public override string ToString() + { + return stringBuilder.ToString(); + } + } +} |