stringify method
Marker for group start and end. Print an object to a string.
Implementation
@override
String stringify(dynamic object, {bool asStringLiteral = false}) {
final output = StringBuffer();
if (object is String) {
if (asStringLiteral) {
return "'$object'";
} else {
return object;
}
} else if (object is Iterable) {
if (object.isEmpty) {
return '$listStart$listEnd';
}
output.writeln(listStart);
++_curIndentCount;
for (var i = 0; i < object.length; ++i) {
final item = object.elementAt(i);
output.write(_curIndent());
final itemString = stringify(item, asStringLiteral: true);
output.write(itemString);
if (i < object.length - 1) {
output.write(comma);
}
output.writeln();
}
--_curIndentCount;
output.write(_curIndent());
output.write(listEnd);
} else if (object is Map) {
output.write(structStart);
final keys = object.keys.toList();
for (var i = 0; i < keys.length; ++i) {
final key = keys[i];
final value = object[key];
final keyString = stringify(key);
final valueString = stringify(value);
output.write('$keyString: $valueString');
if (i < keys.length - 1) {
output.write('$comma ');
}
}
output.write(structEnd);
} else if (object is HTStruct) {
if (object.isEmpty) {
output.write('$structStart$structEnd');
} else {
final structString = _stringifyStruct(object);
output.write(structString);
}
} else if (object is HTType) {
final typeString = _stringifyType(object, showTypeKeyword: true);
output.write(typeString);
} else {
output.write(object.toString());
}
return output.toString();
}