godot/modules/mono/editor/GodotTools/GodotTools.IdeConnection/MessageComposer.cs
Aaron Franke 5771f9959c
Mono formatting
No space for casting, add spaces inside braces, 4 space indentation, remove trailing indentation, remove BOM.
2019-12-11 16:32:47 -05:00

47 lines
1.1 KiB
C#

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();
}
}
}