Fix pretty prenting of strings in complex data structures

This commit is contained in:
Niels Mündler 2023-12-08 16:33:38 +01:00 committed by Lucas
parent 92488e535a
commit d0bc782f75
1 changed files with 9 additions and 3 deletions

View File

@ -273,9 +273,15 @@ impl Constant {
match self {
Constant::Integer(i) => RcDoc::as_string(i),
Constant::ByteString(bs) => RcDoc::text("#").append(RcDoc::text(hex::encode(bs))),
Constant::String(s) => RcDoc::text("\"")
.append(RcDoc::text(s))
.append(RcDoc::text("\"")),
Constant::String(s) => RcDoc::text("\"").append(RcDoc::text(
String::from_utf8(
s.as_bytes()
.iter()
.flat_map(|c| escape_default(*c).collect::<Vec<u8>>())
.collect(),
)
.unwrap(),
)),
Constant::Unit => RcDoc::text("()"),
Constant::Bool(b) => RcDoc::text(if *b { "True" } else { "False" }),
Constant::ProtoList(_, items) => RcDoc::text("[")