From 0b94203a79d3261d4cc3bbcdb3438a5a45c8c572 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Thu, 18 Jul 2019 04:08:24 +0200 Subject: 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. --- .../GodotTools.IdeConnection/MessageComposer.cs | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs (limited to 'modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs') 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(); + } + } +} -- cgit v1.2.3