Here are the examples of the csharp api System.Text.StringBuilder.Append(char) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
8245 Examples
19
View Source File : TypeResolver.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public string GenericToString()
{
if (GenArgs_ == null)
return "";
StringBuilder sb = new StringBuilder();
sb.Append('<');
bool last = false;
foreach (var arg in GenArgs_)
{
if (last)
sb.Append(',');
last = true;
sb.Append(arg.FullName);
}
sb.Append('>');
return sb.ToString();
}
19
View Source File : DbiScope.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
static string ReadUnicodeString(IImageStream stream, long end) {
var sb = new StringBuilder();
for (;;) {
if (stream.Position + 2 > end)
return null;
var c = (char)stream.ReadUInt16();
if (c == 0)
break;
sb.Append(c);
}
return sb.ToString();
}
19
View Source File : PdbCustomDebugInfoReader.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
string ReadUnicodeZ(long recPosEnd, bool needZeroChar) {
var sb = new StringBuilder();
for (;;) {
if (reader.Position >= recPosEnd)
return needZeroChar ? null : sb.ToString();
var c = (char)reader.ReadUInt16();
if (c == 0)
return sb.ToString();
sb.Append(c);
}
}
19
View Source File : CodePrinter.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public void Append(string str)
{
if (str == null)
return;
bool isNewLine = IsNewLine();
foreach (char ch in str)
{
if (ch == '\r')
continue;
if (ch == '\n')
{
isNewLine = true;
++LineCount;
}
else if (isNewLine)
{
isNewLine = false;
AppendIndent();
}
Builder.Append(ch);
}
}
19
View Source File : CodePrinter.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public void AppendLine(string str)
{
Append(str);
Builder.Append('\n');
++LineCount;
}
19
View Source File : CodePrinter.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public void AppendLine()
{
Builder.Append('\n');
++LineCount;
}
19
View Source File : CodePrinter.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private void AppendIndent()
{
for (int i = 0; i < Indents; ++i)
Builder.Append('\t');
}
19
View Source File : NameHelper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private static void SigToCppName(TypeSig sig, StringBuilder sb, TypeManager typeMgr)
{
string elemName = GetElemTypeName(sig.ElementType);
if (elemName != null)
{
sb.Append(elemName);
return;
}
switch (sig.ElementType)
{
case ElementType.Clreplaced:
case ElementType.ValueType:
case ElementType.GenericInst:
{
TypeX type = typeMgr.GetTypeByName(sig.FullName);
if (type != null)
{
if (type.Def.IsValueType)
sb.Append(type.GetCppName());
else
sb.Append("struct " + type.GetCppName() + '*');
}
else
{
if (sig.IsValueType)
sb.Append("il2cppValueType");
else
sb.Append("il2cppObject*");
}
}
return;
case ElementType.Ptr:
case ElementType.ByRef:
SigToCppName(sig.Next, sb, typeMgr);
sb.Append('*');
return;
case ElementType.SZArray:
sb.Append("il2cppSZArray<");
SigToCppName(sig.Next, sb, typeMgr);
sb.Append(">*");
return;
case ElementType.Array:
//! il2cppArray<next, 0, 10, 0, 10, ...>*
break;
case ElementType.Pinned:
case ElementType.CModReqd:
case ElementType.CModOpt:
SigToCppName(sig.Next, sb, typeMgr);
return;
default:
throw new ArgumentOutOfRangeException("SigToCppName TypeSig " + sig.FullName);
}
}
19
View Source File : NameHelper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private static string ToRadix(uint value, uint radix)
{
StringBuilder sb = new StringBuilder();
do
{
uint dig = value % radix;
value /= radix;
sb.Append(DigMap[(int)dig]);
} while (value != 0);
return sb.ToString();
}
19
View Source File : Program.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static StringBuilder AppendFormatLine(this StringBuilder self, string format, params object[] args)
{
return self.AppendFormat(format, args).Append('\n');
}
19
View Source File : Program.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private static string PrintAllTypes(TypeManager typeMgr, bool showVersion)
{
StringBuilder sb = new StringBuilder();
sb.Append("======\n");
foreach (var type in typeMgr.Types)
{
if (type.IsEmptyType)
continue;
sb.Append(type.PrettyName() + (showVersion ? " [" + type.Def.Module.RuntimeVersion + "]" : "") + '\n');
foreach (var met in type.Methods)
{
sb.AppendFormatLine("-> {0}{1}", met.PrettyName(), met.IsCallVirtOnly ? " = 0" : "");
if (met.HasOverrideImpls)
{
var impls = met.OverrideImpls.ToList();
for (int i = 0, sz = impls.Count; i < sz; ++i)
{
var impl = impls[i];
sb.AppendFormatLine(" {0} {1}: {2}",
i + 1 == sz ? '\\' : '|',
impl.PrettyName(),
impl.DeclType.PrettyName() + (showVersion ? " [" + impl.DeclType.Def.Module.RuntimeVersion + "]" : ""));
}
}
}
foreach (var fld in type.Fields)
sb.AppendFormatLine("--> {0}", fld.PrettyName());
sb.Append('\n');
}
sb.Append("======\n");
return sb.ToString();
}
19
View Source File : InstructionPrinter.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void AddOperandString(StringBuilder sb, Instruction instr, string extra) {
var op = instr.Operand;
switch (instr.OpCode.OperandType) {
case OperandType.InlineBrTarget:
case OperandType.ShortInlineBrTarget:
sb.Append(extra);
AddInstructionTarget(sb, op as Instruction);
break;
case OperandType.InlineField:
case OperandType.InlineMethod:
case OperandType.InlineTok:
case OperandType.InlineType:
sb.Append(extra);
if (op is IFullName)
sb.Append((op as IFullName).FullName);
else if (op != null)
sb.Append(op.ToString());
else
sb.Append("null");
break;
case OperandType.InlineI:
case OperandType.InlineI8:
case OperandType.InlineR:
case OperandType.ShortInlineI:
case OperandType.ShortInlineR:
sb.Append(string.Format("{0}{1}", extra, op));
break;
case OperandType.InlineSig:
sb.Append(extra);
sb.Append(FullNameCreator.MethodFullName(null, (UTF8String)null, op as MethodSig, null, null, null, null));
break;
case OperandType.InlineString:
sb.Append(extra);
EscapeString(sb, op as string, true);
break;
case OperandType.InlineSwitch:
var targets = op as IList<Instruction>;
if (targets == null)
sb.Append("null");
else {
sb.Append('(');
for (int i = 0; i < targets.Count; i++) {
if (i != 0)
sb.Append(',');
AddInstructionTarget(sb, targets.Get(i, null));
}
sb.Append(')');
}
break;
case OperandType.InlineVar:
case OperandType.ShortInlineVar:
sb.Append(extra);
if (op == null)
sb.Append("null");
else
sb.Append(op.ToString());
break;
case OperandType.InlineNone:
case OperandType.InlinePhi:
default:
break;
}
}
19
View Source File : InstructionPrinter.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
static void EscapeString(StringBuilder sb, string s, bool addQuotes) {
if (s == null) {
sb.Append("null");
return;
}
if (addQuotes)
sb.Append('"');
foreach (var c in s) {
if ((int)c < 0x20) {
switch (c) {
case '\a': sb.Append(@"\a"); break;
case '\b': sb.Append(@"\b"); break;
case '\f': sb.Append(@"\f"); break;
case '\n': sb.Append(@"\n"); break;
case '\r': sb.Append(@"\r"); break;
case '\t': sb.Append(@"\t"); break;
case '\v': sb.Append(@"\v"); break;
default:
sb.Append(string.Format(@"\u{0:X4}", (int)c));
break;
}
}
else if (c == '\\' || c == '"') {
sb.Append('\\');
sb.Append(c);
}
else
sb.Append(c);
}
if (addQuotes)
sb.Append('"');
}
19
View Source File : TypeNameParser.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
internal string ReadId(bool ignoreWhiteSpace) {
SkipWhite();
var sb = new StringBuilder();
int c;
while ((c = GetIdChar(ignoreWhiteSpace)) != -1)
sb.Append((char)c);
Verify(sb.Length > 0, "Expected an id");
return sb.ToString();
}
19
View Source File : ImageSectionHeader.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
static string ToString(byte[] name) {
var sb = new StringBuilder(name.Length);
foreach (var b in name) {
if (b == 0)
break;
sb.Append((char)b);
}
return sb.ToString();
}
19
View Source File : TypeNameParser.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
string ReadreplacedemblyNameId() {
SkipWhite();
var sb = new StringBuilder();
int c;
while ((c = GetAsmNameChar()) != -1)
sb.Append((char)c);
var name = sb.ToString().Trim();
Verify(name.Length > 0, "Expected an replacedembly name");
return name;
}
19
View Source File : Utils.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
internal static string GetreplacedemblyNameString(UTF8String name, Version version, UTF8String culture, PublicKeyBase publicKey, replacedemblyAttributes attributes) {
var sb = new StringBuilder();
foreach (var c in UTF8String.ToSystemStringOrEmpty(name)) {
if (c == ',' || c == '=')
sb.Append('\\');
sb.Append(c);
}
if (version != null) {
sb.Append(", Version=");
sb.Append(CreateVersionWithNoUndefinedValues(version).ToString());
}
if ((object)culture != null) {
sb.Append(", Culture=");
sb.Append(UTF8String.IsNullOrEmpty(culture) ? "neutral" : culture.String);
}
sb.Append(", ");
sb.Append(publicKey == null || publicKey is PublicKeyToken ? "PublicKeyToken=" : "PublicKey=");
sb.Append(publicKey == null ? "null" : publicKey.ToString());
if ((attributes & replacedemblyAttributes.Retargetable) != 0)
sb.Append(", Retargetable=Yes");
if ((attributes & replacedemblyAttributes.ContentType_Mask) == replacedemblyAttributes.ContentType_WindowsRuntime)
sb.Append(", ContentType=WindowsRuntime");
return sb.ToString();
}
19
View Source File : GeneratorContext.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private static string EscapeName(string fullName)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fullName.Length; ++i)
{
char ch = fullName[i];
if (IsLegalIdentChar(ch))
sb.Append(ch);
else if (ch >= 0x7F)
sb.AppendFormat("{0:X}", (uint)ch);
else
sb.Append('_');
}
return sb.ToString();
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void TypeNameKey(
StringBuilder sb,
TypeDef tyDef,
IList<TypeSig> genArgs)
{
ClreplacedSigName(sb, tyDef);
if (genArgs.IsCollectionValid())
{
sb.Append('<');
TypeSigListName(sb, genArgs, true);
sb.Append('>');
}
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void MethodNameKey(
StringBuilder sb,
string name,
int genCount,
TypeSig retType,
IList<TypeSig> paramTypes,
CallingConvention callConv)
{
sb.Append(name);
sb.Append('|');
TypeSigName(sb, retType, false);
if (genCount > 0)
{
sb.Append('<');
sb.Append(genCount);
sb.Append('>');
}
sb.Append('(');
TypeSigListName(sb, paramTypes, false);
sb.Append(')');
sb.Append('|');
sb.Append(((uint)callConv).ToString("X"));
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void MethodNameKeyWithGen(
StringBuilder sb,
string name,
IList<TypeSig> genArgs,
TypeSig retType,
IList<TypeSig> paramTypes,
CallingConvention callConv)
{
sb.Append(name);
sb.Append('|');
TypeSigName(sb, retType, false);
if (genArgs.IsCollectionValid())
{
sb.Append('<');
TypeSigListName(sb, genArgs, false);
sb.Append('>');
}
sb.Append('(');
TypeSigListName(sb, paramTypes, false);
sb.Append(')');
sb.Append('|');
sb.Append(((uint)callConv).ToString("X"));
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void FieldNameKey(
StringBuilder sb,
string name,
TypeSig fldType)
{
sb.Append(name);
sb.Append('|');
TypeSigName(sb, fldType, false);
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void TypeSigListName(StringBuilder sb, IList<TypeSig> tySigList, bool printGenOwner)
{
bool last = false;
foreach (var tySig in tySigList)
{
if (last)
sb.Append(',');
last = true;
TypeSigName(sb, tySig, printGenOwner);
}
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void TypeSigName(StringBuilder sb, TypeSig tySig, bool printGenOwner, int depth = 0)
{
if (depth > 512)
throw new TypeLoadException("The TypeSig chain is too long. Or there are some recursive generics that are expanded");
if (tySig == null)
return;
switch (tySig.ElementType)
{
case ElementType.Clreplaced:
case ElementType.ValueType:
case ElementType.TypedByRef:
ClreplacedSigName(sb, tySig);
return;
case ElementType.Ptr:
TypeSigName(sb, tySig.Next, printGenOwner, depth + 1);
sb.Append('*');
return;
case ElementType.ByRef:
TypeSigName(sb, tySig.Next, printGenOwner, depth + 1);
sb.Append('&');
return;
case ElementType.Pinned:
TypeSigName(sb, tySig.Next, printGenOwner, depth + 1);
return;
case ElementType.SZArray:
TypeSigName(sb, tySig.Next, printGenOwner, depth + 1);
sb.Append("[]");
return;
case ElementType.Array:
{
TypeSigName(sb, tySig.Next, printGenOwner, depth + 1);
ArraySig arySig = (ArraySig)tySig;
GetArraySigPostfix(sb, arySig);
return;
}
case ElementType.CModReqd:
TypeSigName(sb, tySig.Next, printGenOwner, depth + 1);
sb.Append(" modreq(");
ClreplacedSigName(sb, ((CModReqdSig)tySig).Modifier.ToTypeSig());
sb.Append(')');
return;
case ElementType.CModOpt:
TypeSigName(sb, tySig.Next, printGenOwner, depth + 1);
sb.Append(" modopt(");
ClreplacedSigName(sb, ((CModOptSig)tySig).Modifier.ToTypeSig());
sb.Append(')');
return;
case ElementType.GenericInst:
{
GenericInstSig genInstSig = (GenericInstSig)tySig;
TypeSigName(sb, genInstSig.GenericType, printGenOwner, depth + 1);
sb.Append('<');
TypeSigListName(sb, genInstSig.GenericArguments, printGenOwner);
sb.Append('>');
return;
}
case ElementType.Var:
case ElementType.MVar:
{
var genSig = (GenericSig)tySig;
if (genSig.IsMethodVar)
{
sb.Append("!!");
}
else
{
sb.Append('!');
if (printGenOwner)
{
sb.Append('(');
ClreplacedSigName(sb, genSig.OwnerType);
sb.Append(')');
}
}
sb.Append(genSig.Number);
return;
}
default:
if (tySig is CorLibTypeSig)
{
ClreplacedSigName(sb, tySig);
return;
}
throw new ArgumentOutOfRangeException();
}
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static void GetArraySigPostfix(StringBuilder sb, ArraySig arySig)
{
sb.Append('[');
uint rank = arySig.Rank;
if (rank == 0)
throw new NotSupportedException();
else if (rank == 1)
sb.Append('*');
else
{
for (int i = 0; i < (int)rank; i++)
{
if (i != 0)
sb.Append(',');
const int NO_LOWER = int.MinValue;
const uint NO_SIZE = uint.MaxValue;
int lower = arySig.LowerBounds.Get(i, NO_LOWER);
uint size = arySig.Sizes.Get(i, NO_SIZE);
if (lower != NO_LOWER)
{
sb.Append(lower);
sb.Append("..");
if (size != NO_SIZE)
sb.Append(lower + (int)size - 1);
else
sb.Append('.');
}
}
}
sb.Append(']');
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private static string ReplaceNonCharacters(string aString, char replacement)
{
var sb = new StringBuilder(aString.Length);
for (var i = 0; i < aString.Length; i++)
{
if (char.IsSurrogatePair(aString, i))
{
int c = char.ConvertToUtf32(aString, i);
i++;
if (IsCharacter(c))
sb.Append(char.ConvertFromUtf32(c));
else
sb.Append(replacement);
}
else
{
char c = aString[i];
if (IsCharacter(c))
sb.Append(c);
else
sb.Append(replacement);
}
}
return sb.ToString();
}
19
View Source File : Helper.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static string ByteArrayToCode(byte[] arr)
{
StringBuilder sb = new StringBuilder();
sb.Append('{');
for (int i = 0; i < arr.Length; ++i)
{
if (i != 0)
sb.Append(',');
sb.Append(arr[i].ToString());
}
sb.Append('}');
return sb.ToString();
}
19
View Source File : HierarchyDump.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public void DumpTypes(StringBuilder sb)
{
foreach (TypeX tyX in Context.TypeMgr.Types)
{
sb.AppendFormat("[{0} {1}] {2}\n",
tyX.IsValueType ? "struct" : "clreplaced",
tyX.GetNameKey(),
TypeAttrToString(tyX.Def.Attributes));
if (tyX.IsInstantiated)
sb.Append(" - Instantiated\n");
if (tyX.BaseType != null)
sb.AppendFormat(" - Base: {0}\n", tyX.BaseType);
if (tyX.Interfaces.IsCollectionValid())
{
sb.Append(" - Interfaces:\n");
foreach (TypeX infTyX in tyX.Interfaces)
sb.AppendFormat(" - {0}\n", infTyX);
}
if (tyX.HasVariances)
{
sb.Append(" - Variances: ");
foreach (var vt in tyX.Variances)
sb.AppendFormat("{0} ", vt);
sb.Append('\n');
}
if (tyX.HasVarianceBaseTypes)
{
sb.Append(" - VarianceBaseTypes:\n");
foreach (TypeX vaTyX in tyX.VarianceBaseTypes)
sb.AppendFormat(" - {0}\n", vaTyX);
}
if (tyX.DerivedTypes.IsCollectionValid())
{
sb.Append(" - DerivedTypes:\n");
foreach (TypeX derivedTyX in tyX.DerivedTypes)
sb.AppendFormat(" - {0}\n", derivedTyX);
}
if (tyX.Fields.IsCollectionValid())
{
sb.Append(" - Fields:\n");
foreach (FieldX fldX in tyX.Fields)
{
sb.AppendFormat(" - {0}, {1}, {2}\n",
fldX.GetNameKey() + '|' + ((uint)fldX.Def.Attributes).ToString("X"),
fldX.GetReplacedNameKey(),
FieldAttrToString(fldX.Def.Attributes));
}
}
if (tyX.Methods.IsCollectionValid())
{
sb.Append(" - Methods:\n");
foreach (MethodX metX in tyX.Methods)
{
sb.AppendFormat(" - {0}, {1}{2}, {3}{4} {5}\n",
metX.GetNameKey() + '|' + ((uint)metX.Def.Attributes).ToString("X"),
metX.GetReplacedNameKey(),
metX.IsProcessed ? "" : " = 0",
MethodAttrToString(metX.Def.Attributes),
metX.Def.ImplAttributes,
metX.Def.SemanticsAttributes);
if (metX.HasOverrideImpls)
{
foreach (var kv in metX.OverrideImpls)
{
MethodX overMetX = kv.Key;
sb.AppendFormat(" - {0}, {1}\n",
overMetX.DeclType.GetNameKey() + " -> " + overMetX.GetNameKey() + '|' + ((uint)overMetX.Def.Attributes).ToString("X"),
overMetX.GetReplacedNameKey());
}
}
}
}
/*if (tyX.IsInstantiated &&
tyX.VTable != null)
{
if (Helper.IsCollectionValid(tyX.VTable.Table))
{
sb.Append(" - VTable:\n");
foreach (var kv2 in tyX.VTable.Table)
{
sb.AppendFormat(" - [{0}]\n", kv2.Key);
foreach (var kv3 in kv2.Value)
{
if (kv3.Key == kv3.Value.Item2)
continue;
sb.AppendFormat(" - {0}: {1} -> {2}\n",
kv3.Key,
kv3.Value.Item1,
kv3.Value.Item2);
}
}
}
if (Helper.IsCollectionValid(tyX.VTable.MethodReplaceMap))
{
sb.Append(" - ReplaceMap:\n");
foreach (var kv2 in tyX.VTable.MethodReplaceMap)
{
sb.AppendFormat(" - {0} => {1}\n", kv2.Key.FullName, kv2.Value.Item2.FullName);
}
}
if (Helper.IsCollectionValid(tyX.VTable.FallbackTable))
{
sb.Append(" - FallbackTable:\n");
foreach (var kv2 in tyX.VTable.FallbackTable)
{
sb.AppendFormat(" - {0} => {1}\n", kv2.Key, kv2.Value.FullName);
}
}
}*/
sb.Append('\n');
}
}
19
View Source File : NameFilter.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static string[] SplitQuoted(string original)
{
char escape = '\\';
char[] separators = { ';' };
var result = new List<string>();
if (!string.IsNullOrEmpty(original)) {
int endIndex = -1;
var b = new StringBuilder();
while (endIndex < original.Length) {
endIndex += 1;
if (endIndex >= original.Length) {
result.Add(b.ToString());
} else if (original[endIndex] == escape) {
endIndex += 1;
if (endIndex >= original.Length) {
throw new ArgumentException("Missing terminating escape character", nameof(original));
}
// include escape if this is not an escaped separator
if (Array.IndexOf(separators, original[endIndex]) < 0)
b.Append(escape);
b.Append(original[endIndex]);
} else {
if (Array.IndexOf(separators, original[endIndex]) >= 0) {
result.Add(b.ToString());
b.Length = 0;
} else {
b.Append(original[endIndex]);
}
}
}
}
return result.ToArray();
}
19
View Source File : StringGenerator.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
public static string StringToArrayOrRaw(string str, out bool isRaw)
{
isRaw = true;
StringBuilder sbRaw = new StringBuilder();
foreach (char c in str)
{
if (c >= 0x21 && c <= 0x7E)
{
switch (c)
{
case '\\':
sbRaw.Append("\\\\");
break;
case '"':
sbRaw.Append("\\\"");
break;
default:
sbRaw.Append(c);
break;
}
}
else
{
isRaw = false;
break;
}
}
if (isRaw)
return "u\"" + sbRaw + "\"";
return StringToArray(str);
}
19
View Source File : StringGenerator.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private static string StringToArray(string str)
{
StringBuilder sb = new StringBuilder();
sb.Append('{');
for (int i = 0; i < str.Length; ++i)
{
if (i != 0)
sb.Append(',');
sb.Append((ushort)str[i]);
}
sb.Append(",0}");
return sb.ToString();
}
19
View Source File : Program.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
private static string ValidatePath(string str)
{
StringBuilder sb = new StringBuilder();
foreach (var ch in str)
{
if (ch == '<' || ch == '>')
sb.Append('_');
else
sb.Append(ch);
}
return sb.ToString();
}
19
View Source File : Options.cs
License : MIT License
Project Creator : aolszowka
License : MIT License
Project Creator : aolszowka
private static string GetDescription (string description)
{
if (description == null)
return string.Empty;
StringBuilder sb = new StringBuilder (description.Length);
int start = -1;
for (int i = 0; i < description.Length; ++i) {
switch (description [i]) {
case '{':
if (i == start) {
sb.Append ('{');
start = -1;
}
else if (start < 0)
start = i + 1;
break;
case '}':
if (start < 0) {
if ((i+1) == description.Length || description [i+1] != '}')
throw new InvalidOperationException ("Invalid option description: " + description);
++i;
sb.Append ("}");
}
else {
sb.Append (description.Substring (start, i - start));
start = -1;
}
break;
case ':':
if (start < 0)
goto default;
start = i + 1;
break;
default:
if (start < 0)
sb.Append (description [i]);
break;
}
}
return sb.ToString ();
}
19
View Source File : DefaultTextFormatter.cs
License : MIT License
Project Creator : ap0llo
License : MIT License
Project Creator : ap0llo
public string EscapeText(string text)
{
var stringBuilder = new StringBuilder();
for (var i = 0; i < text.Length; i++)
{
switch (text[i])
{
case '\\':
case '/':
case '<':
case '>':
case '*':
case '_':
case '-':
case '=':
case '#':
case '`':
case '~':
case '[':
case ']':
case '!':
case '|':
stringBuilder.Append('\\');
break;
default:
break;
}
stringBuilder.Append(text[i]);
}
return stringBuilder.ToString();
}
19
View Source File : MkDocsTextFormatter.cs
License : MIT License
Project Creator : ap0llo
License : MIT License
Project Creator : ap0llo
public string EscapeText(string text)
{
var stringBuilder = new StringBuilder();
for (var i = 0; i < text.Length; i++)
{
switch (text[i])
{
case '<':
stringBuilder.Append("<");
break;
case '>':
stringBuilder.Append(">");
break;
case '\\':
case '*':
case '_':
case '-':
case '=':
case '#':
case '`':
case '~':
case '[':
case ']':
case '!':
case '|':
stringBuilder.Append('\\');
stringBuilder.Append(text[i]);
break;
case '/':
default:
stringBuilder.Append(text[i]);
break;
}
}
return stringBuilder.ToString();
}
19
View Source File : DocumentSerializer.cs
License : MIT License
Project Creator : ap0llo
License : MIT License
Project Creator : ap0llo
public void Visit(MdHeading block)
{
m_Writer.RequestBlankLine();
var anchor = "";
if (!String.IsNullOrWhiteSpace(block.Anchor))
{
if (m_Options.HeadingAnchorStyle == MdHeadingAnchorStyle.Tag ||
(m_Options.HeadingAnchorStyle == MdHeadingAnchorStyle.Auto && !StringComparer.Ordinal.Equals(block.Anchor, block.AutoGeneratedId)))
{
anchor = $"<a id=\"{block.Anchor}\"></a>";
}
}
if (m_Options.HeadingStyle == MdHeadingStyle.Setext && block.Level <= 2)
{
var underlineChar = block.Level == 1 ? '=' : '-';
var text = block.Text.ToString(m_Options);
if (!String.IsNullOrEmpty(anchor))
{
m_Writer.WriteLine(anchor);
m_Writer.WriteLine("");
}
// if no maximum line length was specified, write heading into a single line
if (m_Options.MaxLineLength <= 0)
{
m_Writer.WriteLine(text);
m_Writer.WriteLine(new string(underlineChar, text.Length));
}
// if max line length was specified, split the value into multiple lines if necessary
else
{
var headingTextLines = LineFormatter.GetLines(text, m_Options.MaxLineLength - m_Writer.PrefixLength);
foreach (var line in headingTextLines)
{
m_Writer.WriteLine(line);
}
m_Writer.WriteLine(new string(underlineChar, headingTextLines.Max(x => x.Length)));
}
}
else
{
var lineBuilder = new StringBuilder();
lineBuilder.Append('#', block.Level);
lineBuilder.Append(' ');
if (!String.IsNullOrEmpty(anchor))
{
lineBuilder
.Append(anchor)
.Append(" ");
}
lineBuilder.Append(block.Text.ToString(m_Options));
m_Writer.WriteLine(lineBuilder.ToString());
}
m_Writer.RequestBlankLine();
}
19
View Source File : HtmlUtilities.cs
License : MIT License
Project Creator : ap0llo
License : MIT License
Project Creator : ap0llo
public static string ToUrlSlug(string? value)
{
value = value?.Trim();
if (String.IsNullOrEmpty(value))
{
return "";
}
var anchor = new StringBuilder();
foreach (var c in value!)
{
if (Char.IsLetter(c) || Char.IsNumber(c))
{
anchor.Append(Char.ToLower(c));
}
else if (Char.IsWhiteSpace(c))
{
anchor.Append('-');
}
}
return anchor.ToString();
}
19
View Source File : AmqpMessageIdHelper.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
public static string ConvertBinaryToHexString(byte[] bytes)
{
// Each byte is represented as 2 chars
StringBuilder builder = new StringBuilder(bytes.Length * 2);
foreach (byte b in bytes)
{
// The byte will be expanded to int before shifting, replicating the
// sign bit, so mask everything beyond the first 4 bits afterwards
int upper = (b >> 4) & 0x0F;
// We only want the first 4 bits
int lower = b & 0x0F;
builder.Append(HEX_CHARS[upper]);
builder.Append(HEX_CHARS[lower]);
}
return builder.ToString();
}
19
View Source File : StringBuilderExtensions.cs
License : MIT License
Project Creator : ap0llo
License : MIT License
Project Creator : ap0llo
public static void AppendRepeat(this StringBuilder stringBuilder, char c, int count)
{
for (var i = 0; i < count; i++)
{
stringBuilder.Append(c);
}
}
19
View Source File : DocumentSerializer.cs
License : MIT License
Project Creator : ap0llo
License : MIT License
Project Creator : ap0llo
public void SerializeGFMTable(MdTable table)
{
// convert table to string
var tablereplacedtring = new[] { table.HeaderRow }.Union(table.Rows)
.Select(row =>
row.Cells
.Select(c => c.ToString(m_Options))
.ToArray())
.ToArray();
// determine the maximum width of every column
var columnWidths = new int[table.ColumnCount];
for (var rowIndex = 0; rowIndex < tablereplacedtring.Length; rowIndex++)
{
for (var columnIndex = 0; columnIndex < tablereplacedtring[rowIndex].Length; columnIndex++)
{
columnWidths[columnIndex] = Math.Max(
columnWidths[columnIndex],
tablereplacedtring[rowIndex][columnIndex].Length);
}
}
// helper functions that writes a single row to the output
void SaveRow(string[] row)
{
var lineBuilder = new StringBuilder();
lineBuilder.Append("|");
for (var i = 0; i < columnWidths.Length; i++)
{
// current row has a cell for column i
if (i < row.Length)
{
lineBuilder.Append(" ");
lineBuilder.Append(row[i].PadRight(columnWidths[i]));
lineBuilder.Append(" ");
}
// row has less columns than the table => write out empty cell
else
{
lineBuilder.AppendRepeat(' ', columnWidths[i] + 2);
}
lineBuilder.Append("|");
}
m_Writer.WriteLine(lineBuilder.ToString());
}
m_Writer.RequestBlankLine();
// save header row
SaveRow(tablereplacedtring[0]);
// write separator between header and table
var separatorLineBuilder = new StringBuilder();
separatorLineBuilder.Append("|");
for (var i = 0; i < columnWidths.Length; i++)
{
separatorLineBuilder.Append(' ');
separatorLineBuilder.AppendRepeat('-', columnWidths[i]);
separatorLineBuilder.Append(' ');
separatorLineBuilder.Append("|");
}
m_Writer.WriteLine(separatorLineBuilder.ToString());
// write table rows
foreach (var row in tablereplacedtring.Skip(1))
{
SaveRow(row);
}
m_Writer.RequestBlankLine();
}
19
View Source File : BaseTestCase.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
public static string ToString(IDictionary dictionary, int indt = 0)
{
if (dictionary == null) return "[]";
StringBuilder sb = new StringBuilder();
int indent = Math.Max(0, Math.Min(indt, 16));
StringBuilder sbTabs = new StringBuilder();
for (int i = 0; i < indent; i++)
{
sbTabs.Append('\t');
}
string wspace = sbTabs.ToString();
sb.AppendFormat("[\n");
foreach (object key in dictionary.Keys)
{
if (key != null)
{
//Console.WriteLine("key: {0}, value: {1}", key, dictionary[key]);
sb.AppendFormat("{0}\t[Key:{1}, Value: {2}]\n", wspace, key.ToString(), dictionary[key]?.ToString());
}
}
sb.AppendFormat("{0}]", wspace);
return sb.ToString();
}
19
View Source File : BaseTestCase.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
public static string ToString(StringDictionary dictionary, int indt = 0)
{
if (dictionary == null) return "[]";
StringBuilder sb = new StringBuilder();
int indent = Math.Max(0, Math.Min(indt, 16));
StringBuilder sbTabs = new StringBuilder();
for (int i = 0; i < indent; i++)
{
sbTabs.Append('\t');
}
string wspace = sbTabs.ToString();
sb.AppendFormat("{0}[\n", wspace);
foreach (string key in dictionary.Keys)
{
if (key != null)
{
sb.AppendFormat("{0}\t[Key:{1}, Value: {2}]\n", wspace, key, dictionary[key] ?? "null");
}
}
sb.AppendFormat("{0}]", wspace);
return sb.ToString();
}
19
View Source File : URISupport.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
public Uri toUri()
{
StringBuilder sb = new StringBuilder();
if (scheme != null)
{
sb.Append(scheme);
sb.Append(':');
}
if (!string.IsNullOrEmpty(host))
{
sb.Append(host);
}
else
{
sb.Append('(');
for (int i = 0; i < components.Length; i++)
{
if (i != 0)
{
sb.Append(',');
}
sb.Append(components[i].ToString());
}
sb.Append(')');
}
if (path != null)
{
sb.Append('/');
sb.Append(path);
}
if (parameters.Count != 0)
{
sb.Append("?");
sb.Append(CreateQueryString(parameters));
}
if (fragment != null)
{
sb.Append("#");
sb.Append(fragment);
}
return new Uri(sb.ToString());
}
19
View Source File : DateTimeDateFormatter.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
protected override void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer)
{
int day = dateToFormat.Day;
if (day < 10)
{
buffer.Append('0');
}
buffer.Append(day);
buffer.Append(' ');
buffer.Append(m_dateTimeFormatInfo.GetAbbreviatedMonthName(dateToFormat.Month));
buffer.Append(' ');
buffer.Append(dateToFormat.Year);
buffer.Append(' ');
// Append the 'HH:mm:ss'
base.FormatDateWithoutMillis(dateToFormat, buffer);
}
19
View Source File : AnsiColorTerminalAppender.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
public override void ActivateOptions()
{
base.ActivateOptions();
StringBuilder buf = new StringBuilder();
// Reset any existing codes
buf.Append("\x1b[0;");
int lightAdjustment = ((m_attributes & AnsiAttributes.Light) > 0) ? 60 : 0;
// set the foreground color
buf.Append(30 + lightAdjustment + (int)m_foreColor);
buf.Append(';');
// set the background color
buf.Append(40 + lightAdjustment + (int)m_backColor);
// set the attributes
if ((m_attributes & AnsiAttributes.Bright) > 0)
{
buf.Append(";1");
}
if ((m_attributes & AnsiAttributes.Dim) > 0)
{
buf.Append(";2");
}
if ((m_attributes & AnsiAttributes.Underscore) > 0)
{
buf.Append(";4");
}
if ((m_attributes & AnsiAttributes.Blink) > 0)
{
buf.Append(";5");
}
if ((m_attributes & AnsiAttributes.Reverse) > 0)
{
buf.Append(";7");
}
if ((m_attributes & AnsiAttributes.Hidden) > 0)
{
buf.Append(";8");
}
if ((m_attributes & AnsiAttributes.Strikethrough) > 0)
{
buf.Append(";9");
}
buf.Append('m');
m_combinedColor = buf.ToString();
}
19
View Source File : RemoteSyslogAppender.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
protected override void Append(LoggingEvent loggingEvent)
{
try
{
// Priority
int priority = GeneratePriority(m_facility, GetSeverity(loggingEvent.Level));
// Idenreplacedy
string idenreplacedy;
if (m_idenreplacedy != null)
{
idenreplacedy = m_idenreplacedy.Format(loggingEvent);
}
else
{
idenreplacedy = loggingEvent.Domain;
}
// Message. The message goes after the tag/idenreplacedy
string message = RenderLoggingEvent(loggingEvent);
Byte[] buffer;
int i = 0;
char c;
StringBuilder builder = new StringBuilder();
while (i < message.Length)
{
// Clear StringBuilder
builder.Length = 0;
// Write priority
builder.Append('<');
builder.Append(priority);
builder.Append('>');
// Write idenreplacedy
builder.Append(idenreplacedy);
builder.Append(": ");
for (; i < message.Length; i++)
{
c = message[i];
// Accept only visible ASCII characters and space. See RFC 3164 section 4.1.3
if (((int)c >= 32) && ((int)c <= 126))
{
builder.Append(c);
}
// If character is newline, break and send the current line
else if ((c == '\r') || (c == '\n'))
{
// Check the next character to handle \r\n or \n\r
if ((message.Length > i + 1) && ((message[i + 1] == '\r') || (message[i + 1] == '\n')))
{
i++;
}
i++;
break;
}
}
// Grab as a byte array
buffer = this.Encoding.GetBytes(builder.ToString());
#if NET_4_5 || NETSTANDARD
Client.SendAsync(buffer, buffer.Length, RemoteEndPoint).Wait();
#else
this.Client.Send(buffer, buffer.Length, this.RemoteEndPoint);
#endif
}
}
catch (Exception e)
{
ErrorHandler.Error(
"Unable to send logging event to remote syslog " +
this.RemoteAddress.ToString() +
" on port " +
this.RemotePort + ".",
e,
ErrorCode.WriteFailure);
}
}
19
View Source File : AbsoluteTimeDateFormatter.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
protected virtual void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer)
{
int hour = dateToFormat.Hour;
if (hour < 10)
{
buffer.Append('0');
}
buffer.Append(hour);
buffer.Append(':');
int mins = dateToFormat.Minute;
if (mins < 10)
{
buffer.Append('0');
}
buffer.Append(mins);
buffer.Append(':');
int secs = dateToFormat.Second;
if (secs < 10)
{
buffer.Append('0');
}
buffer.Append(secs);
}
19
View Source File : Iso8601DateFormatter.cs
License : Apache License 2.0
Project Creator : apache
License : Apache License 2.0
Project Creator : apache
protected override void FormatDateWithoutMillis(DateTime dateToFormat, StringBuilder buffer)
{
buffer.Append(dateToFormat.Year);
buffer.Append('-');
int month = dateToFormat.Month;
if (month < 10)
{
buffer.Append('0');
}
buffer.Append(month);
buffer.Append('-');
int day = dateToFormat.Day;
if (day < 10)
{
buffer.Append('0');
}
buffer.Append(day);
buffer.Append(' ');
// Append the 'HH:mm:ss'
base.FormatDateWithoutMillis(dateToFormat, buffer);
}
19
View Source File : JsonPrettyWriter.cs
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
public void WriteLabel(StageItem l)
{
Indent();
_b.Append('"');
StringHandler.EscapeString(l.name, _b);
_b.Append('"');
_b.Append(" : ");
}
19
View Source File : JsonPrettyWriter.cs
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
License : GNU Lesser General Public License v3.0
Project Creator : ApexGameTools
public void WriteElementStart()
{
Indent();
_b.Append('{');
NextLine(1);
}
See More Examples