Skip to content

Commit

Permalink
refactor(encode): Pull out literal inference
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 17, 2024
1 parent fbb0ac2 commit e1bc1c3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,17 @@ fn infer_style(
(Some(style), Some(literal)) => (style, literal),
(None, Some(literal)) => (infer_all_style(value).0, literal),
(Some(style), None) => {
let literal = !value.contains('\'') && (value.contains('"') | value.contains('\\'));
let literal = infer_literal(value);
(style, literal)
}
(None, None) => infer_all_style(value),
}
}

fn infer_literal(value: &str) -> bool {
!value.contains('\'') && (value.contains('"') | value.contains('\\'))
}

fn infer_all_style(value: &str) -> (StringStyle, bool) {
// We need to determine:
// - if we are a "multi-line" pretty (if there are \n)
Expand Down

0 comments on commit e1bc1c3

Please sign in to comment.