Determine an acceptable scalar style.
(emitter *yaml_emitter_t, event *yaml_event_t)
| 1002 | |
| 1003 | // Determine an acceptable scalar style. |
| 1004 | func yaml_emitter_select_scalar_style(emitter *yaml_emitter_t, event *yaml_event_t) bool { |
| 1005 | |
| 1006 | no_tag := len(emitter.tag_data.handle) == 0 && len(emitter.tag_data.suffix) == 0 |
| 1007 | if no_tag && !event.implicit && !event.quoted_implicit { |
| 1008 | return yaml_emitter_set_emitter_error(emitter, "neither tag nor implicit flags are specified") |
| 1009 | } |
| 1010 | |
| 1011 | style := event.scalar_style() |
| 1012 | if style == yaml_ANY_SCALAR_STYLE { |
| 1013 | style = yaml_PLAIN_SCALAR_STYLE |
| 1014 | } |
| 1015 | if emitter.canonical { |
| 1016 | style = yaml_DOUBLE_QUOTED_SCALAR_STYLE |
| 1017 | } |
| 1018 | if emitter.simple_key_context && emitter.scalar_data.multiline { |
| 1019 | style = yaml_DOUBLE_QUOTED_SCALAR_STYLE |
| 1020 | } |
| 1021 | |
| 1022 | if style == yaml_PLAIN_SCALAR_STYLE { |
| 1023 | if emitter.flow_level > 0 && !emitter.scalar_data.flow_plain_allowed || |
| 1024 | emitter.flow_level == 0 && !emitter.scalar_data.block_plain_allowed { |
| 1025 | style = yaml_SINGLE_QUOTED_SCALAR_STYLE |
| 1026 | } |
| 1027 | if len(emitter.scalar_data.value) == 0 && (emitter.flow_level > 0 || emitter.simple_key_context) { |
| 1028 | style = yaml_SINGLE_QUOTED_SCALAR_STYLE |
| 1029 | } |
| 1030 | if no_tag && !event.implicit { |
| 1031 | style = yaml_SINGLE_QUOTED_SCALAR_STYLE |
| 1032 | } |
| 1033 | } |
| 1034 | if style == yaml_SINGLE_QUOTED_SCALAR_STYLE { |
| 1035 | if !emitter.scalar_data.single_quoted_allowed { |
| 1036 | style = yaml_DOUBLE_QUOTED_SCALAR_STYLE |
| 1037 | } |
| 1038 | } |
| 1039 | if style == yaml_LITERAL_SCALAR_STYLE || style == yaml_FOLDED_SCALAR_STYLE { |
| 1040 | if !emitter.scalar_data.block_allowed || emitter.flow_level > 0 || emitter.simple_key_context { |
| 1041 | style = yaml_DOUBLE_QUOTED_SCALAR_STYLE |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | if no_tag && !event.quoted_implicit && style != yaml_PLAIN_SCALAR_STYLE { |
| 1046 | emitter.tag_data.handle = []byte{'!'} |
| 1047 | } |
| 1048 | emitter.scalar_data.style = style |
| 1049 | return true |
| 1050 | } |
| 1051 | |
| 1052 | // Write an anchor. |
| 1053 | func yaml_emitter_process_anchor(emitter *yaml_emitter_t) bool { |
no test coverage detected