From e1bc1c3861f208283c13410848dc34d73c1b0df4 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 17 Jul 2024 11:31:12 -0500 Subject: [PATCH] refactor(encode): Pull out literal inference --- crates/toml_edit/src/encode.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/toml_edit/src/encode.rs b/crates/toml_edit/src/encode.rs index 1da651aa..fd5eeec0 100644 --- a/crates/toml_edit/src/encode.rs +++ b/crates/toml_edit/src/encode.rs @@ -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)