Here are the examples of the csharp api System.Text.StringBuilder.AppendEscaped(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : Serialization.Generate.cs
with MIT License
from outerminds
with MIT License
from outerminds
static void GenerateCompact(Node node, StringBuilder builder)
{
switch (node.Kind)
{
case Node.Kinds.Null: builder.Append("null"); break;
case Node.Kinds.Boolean: builder.Append((bool)node.Value ? "true" : "false"); break;
case Node.Kinds.Number: builder.Append(NumberToString(node)); break;
case Node.Kinds.String:
var value = (string)node.Value;
if (value.Length == 0) builder.Append(@"""""");
else
{
builder.Append('"');
if (node.HasPlain()) builder.Append(value);
else builder.AppendEscaped(value);
builder.Append('"');
}
break;
case Node.Kinds.Array:
if (node.Children.Length == 0) builder.Append("[]");
else
{
builder.Append('[');
GenerateCompact(node.Children[0], builder);
for (int i = 1; i < node.Children.Length; i++)
{
builder.Append(',');
GenerateCompact(node.Children[i], builder);
}
builder.Append(']');
}
break;
case Node.Kinds.Object:
if (node.Children.Length == 0) builder.Append("{}");
else
{
builder.Append('{');
GenerateCompact(node.Children[0], builder);
builder.Append(':');
GenerateCompact(node.Children[1], builder);
for (int i = 2; i < node.Children.Length; i += 2)
{
builder.Append(',');
GenerateCompact(node.Children[i], builder);
builder.Append(':');
GenerateCompact(node.Children[i + 1], builder);
}
builder.Append('}');
}
break;
}
}
19
Source : Serialization.Generate.cs
with MIT License
from outerminds
with MIT License
from outerminds
static void GenerateIndented(Node node, StringBuilder builder, int indent)
{
switch (node.Kind)
{
case Node.Kinds.Null: builder.Append("null"); break;
case Node.Kinds.Boolean: builder.Append((bool)node.Value ? "true" : "false"); break;
case Node.Kinds.Number: builder.Append(NumberToString(node)); break;
case Node.Kinds.String:
var value = (string)node.Value;
if (value.Length == 0) builder.Append(@"""""");
else
{
builder.Append('"');
if (node.HasPlain()) builder.Append(value);
else builder.AppendEscaped(value);
builder.Append('"');
}
break;
case Node.Kinds.Array:
if (node.Children.Length == 0) builder.Append("[]");
else
{
builder.Append('[');
builder.AppendLine();
indent++;
for (int i = 0; i < node.Children.Length; i++)
{
if (i > 0)
{
builder.Append(", ");
builder.AppendLine();
}
Indent(indent, builder);
GenerateIndented(node.Children[i], builder, indent);
}
indent--;
builder.AppendLine();
Indent(indent, builder);
builder.Append(']');
}
break;
case Node.Kinds.Object:
if (node.Children.Length == 0) builder.Append("{}");
else
{
builder.Append('{');
builder.AppendLine();
indent++;
for (int i = 0; i < node.Children.Length; i += 2)
{
if (i > 0)
{
builder.Append(", ");
builder.AppendLine();
}
Indent(indent, builder);
GenerateIndented(node.Children[i], builder, indent);
builder.Append(": ");
GenerateIndented(node.Children[i + 1], builder, indent);
}
indent--;
builder.AppendLine();
Indent(indent, builder);
builder.Append('}');
}
break;
}
}
19
Source : StringBuilderExtension.cs
with MIT License
from trampster
with MIT License
from trampster
public static StringBuilder AppendDoubleEscaped(this StringBuilder builder, string input)
{
var firstBuilder = new StringBuilder();
firstBuilder.AppendEscaped(input);
builder.AppendEscaped(firstBuilder.ToString());
return builder;
}