Refactoring Props encoder prefs

This commit is contained in:
Mike Farah
2024-02-24 15:14:21 +11:00
parent 2866e90c49
commit f44d47a204
6 changed files with 36 additions and 18 deletions
+4 -6
View File
@@ -11,14 +11,12 @@ import (
)
type propertiesEncoder struct {
unwrapScalar bool
prefs PropertiesPreferences
prefs PropertiesPreferences
}
func NewPropertiesEncoder(unwrapScalar bool, prefs PropertiesPreferences) Encoder {
func NewPropertiesEncoder(prefs PropertiesPreferences) Encoder {
return &propertiesEncoder{
unwrapScalar: unwrapScalar,
prefs: prefs,
prefs: prefs,
}
}
@@ -95,7 +93,7 @@ func (pe *propertiesEncoder) doEncode(p *properties.Properties, node *CandidateN
switch node.Kind {
case ScalarNode:
var nodeValue string
if pe.unwrapScalar || !strings.Contains(node.Value, " ") {
if pe.prefs.UnwrapScalar || !strings.Contains(node.Value, " ") {
nodeValue = node.Value
} else {
nodeValue = fmt.Sprintf("%q", node.Value)