private static void WriteObject(AcfObject obj, StringBuilder sb, int indent) { // "name" WriteIndent(sb, indent); WriteString(obj.Name, sb); sb.AppendLine(); // { WriteIndent(sb, indent); sb.Append('{'); sb.AppendLine(); foreach (var entry in obj) { if (entry.Value is AcfObject subobj) { WriteObject(subobj, sb, indent + 1); } else { // "key" "value" var str = entry.Value as AcfString; WriteIndent(sb, indent + 1); WriteString(entry.Key, sb); sb.Append("\t\t"); WriteString(str.Value, sb); sb.AppendLine(); } } // } WriteIndent(sb, indent); sb.Append('}'); sb.AppendLine(); }
// After '{' private static AcfObject ParseObject(string source, ref int offset, string objectName) { int offs = offset; var entries = new Dictionary <string, AcfEntry>(); var result = new AcfObject(objectName, entries); while (!MatchChar(source, ref offs, '}')) { var key = ParseString(source, ref offs); if (MatchChar(source, ref offs, '{')) { entries[key] = ParseObject(source, ref offs, key); } else { var value = ParseString(source, ref offs); if (value == null) { throw new AcfSyntaxException(offs, "Expected '{' or string value after string key."); } entries[key] = new AcfString(value); } } offset = offs; return(result); }
internal static string ToString(AcfObject obj) { var sb = new StringBuilder(); WriteObject(obj, sb, 0); return(sb.ToString()); }