Source File
emitterc.go
Belonging Package
gopkg.in/yaml.v2
package yaml
import (
)
func ( *yaml_emitter_t) bool {
if .buffer_pos+5 >= len(.buffer) {
return yaml_emitter_flush()
}
return true
}
func ( *yaml_emitter_t, byte) bool {
if .buffer_pos+5 >= len(.buffer) && !yaml_emitter_flush() {
return false
}
.buffer[.buffer_pos] =
.buffer_pos++
.column++
return true
}
func ( *yaml_emitter_t) bool {
if .buffer_pos+5 >= len(.buffer) && !yaml_emitter_flush() {
return false
}
switch .line_break {
case yaml_CR_BREAK:
.buffer[.buffer_pos] = '\r'
.buffer_pos += 1
case yaml_LN_BREAK:
.buffer[.buffer_pos] = '\n'
.buffer_pos += 1
case yaml_CRLN_BREAK:
.buffer[.buffer_pos+0] = '\r'
.buffer[.buffer_pos+1] = '\n'
.buffer_pos += 2
default:
panic("unknown line break setting")
}
.column = 0
.line++
return true
}
func ( *yaml_emitter_t, []byte, *int) bool {
if .buffer_pos+5 >= len(.buffer) && !yaml_emitter_flush() {
return false
}
:= .buffer_pos
:= width([*])
switch {
case 4:
.buffer[+3] = [*+3]
fallthrough
case 3:
.buffer[+2] = [*+2]
fallthrough
case 2:
.buffer[+1] = [*+1]
fallthrough
case 1:
.buffer[+0] = [*+0]
default:
panic("unknown character width")
}
.column++
.buffer_pos +=
* +=
return true
}
func ( *yaml_emitter_t, string) bool {
.error = yaml_EMITTER_ERROR
.problem =
return false
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
.events = append(.events, *)
for !yaml_emitter_need_more_events() {
:= &.events[.events_head]
if !yaml_emitter_analyze_event(, ) {
return false
}
if !yaml_emitter_state_machine(, ) {
return false
}
yaml_event_delete()
.events_head++
}
return true
}
func ( *yaml_emitter_t) bool {
if .events_head == len(.events) {
return true
}
var int
switch .events[.events_head].typ {
case yaml_DOCUMENT_START_EVENT:
= 1
break
case yaml_SEQUENCE_START_EVENT:
= 2
break
case yaml_MAPPING_START_EVENT:
= 3
break
default:
return false
}
if len(.events)-.events_head > {
return false
}
var int
for := .events_head; < len(.events); ++ {
switch .events[].typ {
case yaml_STREAM_START_EVENT, yaml_DOCUMENT_START_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT:
++
case yaml_STREAM_END_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_END_EVENT, yaml_MAPPING_END_EVENT:
--
}
if == 0 {
return false
}
}
return true
}
func ( *yaml_emitter_t, *yaml_tag_directive_t, bool) bool {
for := 0; < len(.tag_directives); ++ {
if bytes.Equal(.handle, .tag_directives[].handle) {
if {
return true
}
return yaml_emitter_set_emitter_error(, "duplicate %TAG directive")
}
}
func ( *yaml_emitter_t, , bool) bool {
.indents = append(.indents, .indent)
if .indent < 0 {
if {
.indent = .best_indent
} else {
.indent = 0
}
} else if ! {
.indent += .best_indent
}
return true
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
switch .state {
default:
case yaml_EMIT_STREAM_START_STATE:
return yaml_emitter_emit_stream_start(, )
case yaml_EMIT_FIRST_DOCUMENT_START_STATE:
return yaml_emitter_emit_document_start(, , true)
case yaml_EMIT_DOCUMENT_START_STATE:
return yaml_emitter_emit_document_start(, , false)
case yaml_EMIT_DOCUMENT_CONTENT_STATE:
return yaml_emitter_emit_document_content(, )
case yaml_EMIT_DOCUMENT_END_STATE:
return yaml_emitter_emit_document_end(, )
case yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE:
return yaml_emitter_emit_flow_sequence_item(, , true)
case yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE:
return yaml_emitter_emit_flow_sequence_item(, , false)
case yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE:
return yaml_emitter_emit_flow_mapping_key(, , true)
case yaml_EMIT_FLOW_MAPPING_KEY_STATE:
return yaml_emitter_emit_flow_mapping_key(, , false)
case yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE:
return yaml_emitter_emit_flow_mapping_value(, , true)
case yaml_EMIT_FLOW_MAPPING_VALUE_STATE:
return yaml_emitter_emit_flow_mapping_value(, , false)
case yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE:
return yaml_emitter_emit_block_sequence_item(, , true)
case yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE:
return yaml_emitter_emit_block_sequence_item(, , false)
case yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE:
return yaml_emitter_emit_block_mapping_key(, , true)
case yaml_EMIT_BLOCK_MAPPING_KEY_STATE:
return yaml_emitter_emit_block_mapping_key(, , false)
case yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE:
return yaml_emitter_emit_block_mapping_value(, , true)
case yaml_EMIT_BLOCK_MAPPING_VALUE_STATE:
return yaml_emitter_emit_block_mapping_value(, , false)
case yaml_EMIT_END_STATE:
return yaml_emitter_set_emitter_error(, "expected nothing after STREAM-END")
}
panic("invalid emitter state")
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
if .typ != yaml_STREAM_START_EVENT {
return yaml_emitter_set_emitter_error(, "expected STREAM-START")
}
if .encoding == yaml_ANY_ENCODING {
.encoding = .encoding
if .encoding == yaml_ANY_ENCODING {
.encoding = yaml_UTF8_ENCODING
}
}
if .best_indent < 2 || .best_indent > 9 {
.best_indent = 2
}
if .best_width >= 0 && .best_width <= .best_indent*2 {
.best_width = 80
}
if .best_width < 0 {
.best_width = 1<<31 - 1
}
if .line_break == yaml_ANY_BREAK {
.line_break = yaml_LN_BREAK
}
.indent = -1
.line = 0
.column = 0
.whitespace = true
.indention = true
if .encoding != yaml_UTF8_ENCODING {
if !yaml_emitter_write_bom() {
return false
}
}
.state = yaml_EMIT_FIRST_DOCUMENT_START_STATE
return true
}
func ( *yaml_emitter_t, *yaml_event_t, bool) bool {
if .typ == yaml_DOCUMENT_START_EVENT {
if .version_directive != nil {
if !yaml_emitter_analyze_version_directive(, .version_directive) {
return false
}
}
for := 0; < len(.tag_directives); ++ {
:= &.tag_directives[]
if !yaml_emitter_analyze_tag_directive(, ) {
return false
}
if !yaml_emitter_append_tag_directive(, , false) {
return false
}
}
for := 0; < len(default_tag_directives); ++ {
:= &default_tag_directives[]
if !yaml_emitter_append_tag_directive(, , true) {
return false
}
}
:= .implicit
if ! || .canonical {
= false
}
if .open_ended && (.version_directive != nil || len(.tag_directives) > 0) {
if !yaml_emitter_write_indicator(, []byte("..."), true, false, false) {
return false
}
if !yaml_emitter_write_indent() {
return false
}
}
if .version_directive != nil {
= false
if !yaml_emitter_write_indicator(, []byte("%YAML"), true, false, false) {
return false
}
if !yaml_emitter_write_indicator(, []byte("1.1"), true, false, false) {
return false
}
if !yaml_emitter_write_indent() {
return false
}
}
if len(.tag_directives) > 0 {
= false
for := 0; < len(.tag_directives); ++ {
:= &.tag_directives[]
if !yaml_emitter_write_indicator(, []byte("%TAG"), true, false, false) {
return false
}
if !yaml_emitter_write_tag_handle(, .handle) {
return false
}
if !yaml_emitter_write_tag_content(, .prefix, true) {
return false
}
if !yaml_emitter_write_indent() {
return false
}
}
}
if yaml_emitter_check_empty_document() {
= false
}
if ! {
if !yaml_emitter_write_indent() {
return false
}
if !yaml_emitter_write_indicator(, []byte("---"), true, false, false) {
return false
}
if .canonical {
if !yaml_emitter_write_indent() {
return false
}
}
}
.state = yaml_EMIT_DOCUMENT_CONTENT_STATE
return true
}
if .typ == yaml_STREAM_END_EVENT {
if .open_ended {
if !yaml_emitter_write_indicator(, []byte("..."), true, false, false) {
return false
}
if !yaml_emitter_write_indent() {
return false
}
}
if !yaml_emitter_flush() {
return false
}
.state = yaml_EMIT_END_STATE
return true
}
return yaml_emitter_set_emitter_error(, "expected DOCUMENT-START or STREAM-END")
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
.states = append(.states, yaml_EMIT_DOCUMENT_END_STATE)
return yaml_emitter_emit_node(, , true, false, false, false)
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
if .typ != yaml_DOCUMENT_END_EVENT {
return yaml_emitter_set_emitter_error(, "expected DOCUMENT-END")
}
if !yaml_emitter_write_indent() {
return false
}
if !yaml_emitter_write_indicator(, []byte("..."), true, false, false) {
return false
}
if !yaml_emitter_write_indent() {
return false
}
}
if !yaml_emitter_flush() {
return false
}
.state = yaml_EMIT_DOCUMENT_START_STATE
.tag_directives = .tag_directives[:0]
return true
}
func ( *yaml_emitter_t, *yaml_event_t, bool) bool {
if {
if !yaml_emitter_write_indicator(, []byte{'['}, true, true, false) {
return false
}
if !yaml_emitter_increase_indent(, true, false) {
return false
}
.flow_level++
}
if .typ == yaml_SEQUENCE_END_EVENT {
.flow_level--
.indent = .indents[len(.indents)-1]
.indents = .indents[:len(.indents)-1]
if .canonical && ! {
if !yaml_emitter_write_indicator(, []byte{','}, false, false, false) {
return false
}
if !yaml_emitter_write_indent() {
return false
}
}
if !yaml_emitter_write_indicator(, []byte{']'}, false, false, false) {
return false
}
.state = .states[len(.states)-1]
.states = .states[:len(.states)-1]
return true
}
if ! {
if !yaml_emitter_write_indicator(, []byte{','}, false, false, false) {
return false
}
}
if .canonical || .column > .best_width {
if !yaml_emitter_write_indent() {
return false
}
}
.states = append(.states, yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE)
return yaml_emitter_emit_node(, , false, true, false, false)
}
func ( *yaml_emitter_t, *yaml_event_t, bool) bool {
if {
if !yaml_emitter_write_indicator(, []byte{'{'}, true, true, false) {
return false
}
if !yaml_emitter_increase_indent(, true, false) {
return false
}
.flow_level++
}
if .typ == yaml_MAPPING_END_EVENT {
.flow_level--
.indent = .indents[len(.indents)-1]
.indents = .indents[:len(.indents)-1]
if .canonical && ! {
if !yaml_emitter_write_indicator(, []byte{','}, false, false, false) {
return false
}
if !yaml_emitter_write_indent() {
return false
}
}
if !yaml_emitter_write_indicator(, []byte{'}'}, false, false, false) {
return false
}
.state = .states[len(.states)-1]
.states = .states[:len(.states)-1]
return true
}
if ! {
if !yaml_emitter_write_indicator(, []byte{','}, false, false, false) {
return false
}
}
if .canonical || .column > .best_width {
if !yaml_emitter_write_indent() {
return false
}
}
if !.canonical && yaml_emitter_check_simple_key() {
.states = append(.states, yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE)
return yaml_emitter_emit_node(, , false, false, true, true)
}
if !yaml_emitter_write_indicator(, []byte{'?'}, true, false, false) {
return false
}
.states = append(.states, yaml_EMIT_FLOW_MAPPING_VALUE_STATE)
return yaml_emitter_emit_node(, , false, false, true, false)
}
func ( *yaml_emitter_t, *yaml_event_t, bool) bool {
if {
if !yaml_emitter_write_indicator(, []byte{':'}, false, false, false) {
return false
}
} else {
if .canonical || .column > .best_width {
if !yaml_emitter_write_indent() {
return false
}
}
if !yaml_emitter_write_indicator(, []byte{':'}, true, false, false) {
return false
}
}
.states = append(.states, yaml_EMIT_FLOW_MAPPING_KEY_STATE)
return yaml_emitter_emit_node(, , false, false, true, false)
}
func ( *yaml_emitter_t, *yaml_event_t, bool) bool {
if {
if !yaml_emitter_increase_indent(, false, .mapping_context && !.indention) {
return false
}
}
if .typ == yaml_SEQUENCE_END_EVENT {
.indent = .indents[len(.indents)-1]
.indents = .indents[:len(.indents)-1]
.state = .states[len(.states)-1]
.states = .states[:len(.states)-1]
return true
}
if !yaml_emitter_write_indent() {
return false
}
if !yaml_emitter_write_indicator(, []byte{'-'}, true, false, true) {
return false
}
.states = append(.states, yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE)
return yaml_emitter_emit_node(, , false, true, false, false)
}
func ( *yaml_emitter_t, *yaml_event_t, bool) bool {
if {
if !yaml_emitter_increase_indent(, false, false) {
return false
}
}
if .typ == yaml_MAPPING_END_EVENT {
.indent = .indents[len(.indents)-1]
.indents = .indents[:len(.indents)-1]
.state = .states[len(.states)-1]
.states = .states[:len(.states)-1]
return true
}
if !yaml_emitter_write_indent() {
return false
}
if yaml_emitter_check_simple_key() {
.states = append(.states, yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE)
return yaml_emitter_emit_node(, , false, false, true, true)
}
if !yaml_emitter_write_indicator(, []byte{'?'}, true, false, true) {
return false
}
.states = append(.states, yaml_EMIT_BLOCK_MAPPING_VALUE_STATE)
return yaml_emitter_emit_node(, , false, false, true, false)
}
func ( *yaml_emitter_t, *yaml_event_t, bool) bool {
if {
if !yaml_emitter_write_indicator(, []byte{':'}, false, false, false) {
return false
}
} else {
if !yaml_emitter_write_indent() {
return false
}
if !yaml_emitter_write_indicator(, []byte{':'}, true, false, true) {
return false
}
}
.states = append(.states, yaml_EMIT_BLOCK_MAPPING_KEY_STATE)
return yaml_emitter_emit_node(, , false, false, true, false)
}
func ( *yaml_emitter_t, *yaml_event_t,
bool, bool, bool, bool) bool {
.root_context =
.sequence_context =
.mapping_context =
.simple_key_context =
switch .typ {
case yaml_ALIAS_EVENT:
return yaml_emitter_emit_alias(, )
case yaml_SCALAR_EVENT:
return yaml_emitter_emit_scalar(, )
case yaml_SEQUENCE_START_EVENT:
return yaml_emitter_emit_sequence_start(, )
case yaml_MAPPING_START_EVENT:
return yaml_emitter_emit_mapping_start(, )
default:
return yaml_emitter_set_emitter_error(,
fmt.Sprintf("expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, but got %v", .typ))
}
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
if !yaml_emitter_process_anchor() {
return false
}
.state = .states[len(.states)-1]
.states = .states[:len(.states)-1]
return true
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
if !yaml_emitter_select_scalar_style(, ) {
return false
}
if !yaml_emitter_process_anchor() {
return false
}
if !yaml_emitter_process_tag() {
return false
}
if !yaml_emitter_increase_indent(, true, false) {
return false
}
if !yaml_emitter_process_scalar() {
return false
}
.indent = .indents[len(.indents)-1]
.indents = .indents[:len(.indents)-1]
.state = .states[len(.states)-1]
.states = .states[:len(.states)-1]
return true
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
if !yaml_emitter_process_anchor() {
return false
}
if !yaml_emitter_process_tag() {
return false
}
if .flow_level > 0 || .canonical || .sequence_style() == yaml_FLOW_SEQUENCE_STYLE ||
yaml_emitter_check_empty_sequence() {
.state = yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE
} else {
.state = yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE
}
return true
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
if !yaml_emitter_process_anchor() {
return false
}
if !yaml_emitter_process_tag() {
return false
}
if .flow_level > 0 || .canonical || .mapping_style() == yaml_FLOW_MAPPING_STYLE ||
yaml_emitter_check_empty_mapping() {
.state = yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE
} else {
.state = yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE
}
return true
}
func ( *yaml_emitter_t) bool {
return false // [Go] Huh?
}
func ( *yaml_emitter_t) bool {
if len(.events)-.events_head < 2 {
return false
}
return .events[.events_head].typ == yaml_SEQUENCE_START_EVENT &&
.events[.events_head+1].typ == yaml_SEQUENCE_END_EVENT
}
func ( *yaml_emitter_t) bool {
if len(.events)-.events_head < 2 {
return false
}
return .events[.events_head].typ == yaml_MAPPING_START_EVENT &&
.events[.events_head+1].typ == yaml_MAPPING_END_EVENT
}
func ( *yaml_emitter_t) bool {
:= 0
switch .events[.events_head].typ {
case yaml_ALIAS_EVENT:
+= len(.anchor_data.anchor)
case yaml_SCALAR_EVENT:
if .scalar_data.multiline {
return false
}
+= len(.anchor_data.anchor) +
len(.tag_data.handle) +
len(.tag_data.suffix) +
len(.scalar_data.value)
case yaml_SEQUENCE_START_EVENT:
if !yaml_emitter_check_empty_sequence() {
return false
}
+= len(.anchor_data.anchor) +
len(.tag_data.handle) +
len(.tag_data.suffix)
case yaml_MAPPING_START_EVENT:
if !yaml_emitter_check_empty_mapping() {
return false
}
+= len(.anchor_data.anchor) +
len(.tag_data.handle) +
len(.tag_data.suffix)
default:
return false
}
return <= 128
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
:= len(.tag_data.handle) == 0 && len(.tag_data.suffix) == 0
if && !.implicit && !.quoted_implicit {
return yaml_emitter_set_emitter_error(, "neither tag nor implicit flags are specified")
}
:= .scalar_style()
if == yaml_ANY_SCALAR_STYLE {
= yaml_PLAIN_SCALAR_STYLE
}
if .canonical {
= yaml_DOUBLE_QUOTED_SCALAR_STYLE
}
if .simple_key_context && .scalar_data.multiline {
= yaml_DOUBLE_QUOTED_SCALAR_STYLE
}
if == yaml_PLAIN_SCALAR_STYLE {
if .flow_level > 0 && !.scalar_data.flow_plain_allowed ||
.flow_level == 0 && !.scalar_data.block_plain_allowed {
= yaml_SINGLE_QUOTED_SCALAR_STYLE
}
if len(.scalar_data.value) == 0 && (.flow_level > 0 || .simple_key_context) {
= yaml_SINGLE_QUOTED_SCALAR_STYLE
}
if && !.implicit {
= yaml_SINGLE_QUOTED_SCALAR_STYLE
}
}
if == yaml_SINGLE_QUOTED_SCALAR_STYLE {
if !.scalar_data.single_quoted_allowed {
= yaml_DOUBLE_QUOTED_SCALAR_STYLE
}
}
if == yaml_LITERAL_SCALAR_STYLE || == yaml_FOLDED_SCALAR_STYLE {
if !.scalar_data.block_allowed || .flow_level > 0 || .simple_key_context {
= yaml_DOUBLE_QUOTED_SCALAR_STYLE
}
}
if && !.quoted_implicit && != yaml_PLAIN_SCALAR_STYLE {
.tag_data.handle = []byte{'!'}
}
.scalar_data.style =
return true
}
func ( *yaml_emitter_t) bool {
if .anchor_data.anchor == nil {
return true
}
:= []byte{'&'}
if .anchor_data.alias {
[0] = '*'
}
if !yaml_emitter_write_indicator(, , true, false, false) {
return false
}
return yaml_emitter_write_anchor(, .anchor_data.anchor)
}
func ( *yaml_emitter_t) bool {
if len(.tag_data.handle) == 0 && len(.tag_data.suffix) == 0 {
return true
}
if len(.tag_data.handle) > 0 {
if !yaml_emitter_write_tag_handle(, .tag_data.handle) {
return false
}
if len(.tag_data.suffix) > 0 {
if !yaml_emitter_write_tag_content(, .tag_data.suffix, false) {
return false
}
}
func ( *yaml_emitter_t) bool {
switch .scalar_data.style {
case yaml_PLAIN_SCALAR_STYLE:
return yaml_emitter_write_plain_scalar(, .scalar_data.value, !.simple_key_context)
case yaml_SINGLE_QUOTED_SCALAR_STYLE:
return yaml_emitter_write_single_quoted_scalar(, .scalar_data.value, !.simple_key_context)
case yaml_DOUBLE_QUOTED_SCALAR_STYLE:
return yaml_emitter_write_double_quoted_scalar(, .scalar_data.value, !.simple_key_context)
case yaml_LITERAL_SCALAR_STYLE:
return yaml_emitter_write_literal_scalar(, .scalar_data.value)
case yaml_FOLDED_SCALAR_STYLE:
return yaml_emitter_write_folded_scalar(, .scalar_data.value)
}
panic("unknown scalar style")
}
func ( *yaml_emitter_t, *yaml_version_directive_t) bool {
if .major != 1 || .minor != 1 {
return yaml_emitter_set_emitter_error(, "incompatible %YAML directive")
}
return true
}
func ( *yaml_emitter_t, *yaml_tag_directive_t) bool {
:= .handle
:= .prefix
if len() == 0 {
return yaml_emitter_set_emitter_error(, "tag handle must not be empty")
}
if [0] != '!' {
return yaml_emitter_set_emitter_error(, "tag handle must start with '!'")
}
if [len()-1] != '!' {
return yaml_emitter_set_emitter_error(, "tag handle must end with '!'")
}
for := 1; < len()-1; += width([]) {
if !is_alpha(, ) {
return yaml_emitter_set_emitter_error(, "tag handle must contain alphanumerical characters only")
}
}
if len() == 0 {
return yaml_emitter_set_emitter_error(, "tag prefix must not be empty")
}
return true
}
func ( *yaml_emitter_t, []byte, bool) bool {
if len() == 0 {
:= "anchor value must not be empty"
if {
= "alias value must not be empty"
}
return yaml_emitter_set_emitter_error(, )
}
for := 0; < len(); += width([]) {
if !is_alpha(, ) {
:= "anchor value must contain alphanumerical characters only"
if {
= "alias value must contain alphanumerical characters only"
}
return yaml_emitter_set_emitter_error(, )
}
}
.anchor_data.anchor =
.anchor_data.alias =
return true
}
func ( *yaml_emitter_t, []byte) bool {
if len() == 0 {
return yaml_emitter_set_emitter_error(, "tag value must not be empty")
}
for := 0; < len(.tag_directives); ++ {
:= &.tag_directives[]
if bytes.HasPrefix(, .prefix) {
.tag_data.handle = .handle
.tag_data.suffix = [len(.prefix):]
return true
}
}
.tag_data.suffix =
return true
}
func ( *yaml_emitter_t, []byte) bool {
var (
= false
= false
= false
= false
= false
= false
= false
= false
= false
= false
= false
= false
= false
= false
)
.scalar_data.value =
if len() == 0 {
.scalar_data.multiline = false
.scalar_data.flow_plain_allowed = false
.scalar_data.block_plain_allowed = true
.scalar_data.single_quoted_allowed = true
.scalar_data.block_allowed = false
return true
}
if len() >= 3 && (([0] == '-' && [1] == '-' && [2] == '-') || ([0] == '.' && [1] == '.' && [2] == '.')) {
= true
= true
}
= true
for , := 0, 0; < len(); += {
= width([])
= + >= len() || is_blank(, +)
if == 0 {
switch [] {
case '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`':
= true
= true
case '?', ':':
= true
if {
= true
}
case '-':
if {
= true
= true
}
}
} else {
switch [] {
case ',', '?', '[', ']', '{', '}':
= true
case ':':
= true
if {
= true
}
case '#':
if {
= true
= true
}
}
}
if !is_printable(, ) || !is_ascii(, ) && !.unicode {
= true
}
if is_space(, ) {
if == 0 {
= true
}
if +width([]) == len() {
= true
}
if {
= true
}
= true
= false
} else if is_break(, ) {
= true
if == 0 {
= true
}
if +width([]) == len() {
= true
}
if {
= true
}
= false
= true
} else {
= false
= false
}
= is_blankz(, )
}
.scalar_data.multiline =
.scalar_data.flow_plain_allowed = true
.scalar_data.block_plain_allowed = true
.scalar_data.single_quoted_allowed = true
.scalar_data.block_allowed = true
if || || || {
.scalar_data.flow_plain_allowed = false
.scalar_data.block_plain_allowed = false
}
if {
.scalar_data.block_allowed = false
}
if {
.scalar_data.flow_plain_allowed = false
.scalar_data.block_plain_allowed = false
.scalar_data.single_quoted_allowed = false
}
if || {
.scalar_data.flow_plain_allowed = false
.scalar_data.block_plain_allowed = false
.scalar_data.single_quoted_allowed = false
.scalar_data.block_allowed = false
}
if {
.scalar_data.flow_plain_allowed = false
.scalar_data.block_plain_allowed = false
}
if {
.scalar_data.flow_plain_allowed = false
}
if {
.scalar_data.block_plain_allowed = false
}
return true
}
func ( *yaml_emitter_t, *yaml_event_t) bool {
.anchor_data.anchor = nil
.tag_data.handle = nil
.tag_data.suffix = nil
.scalar_data.value = nil
switch .typ {
case yaml_ALIAS_EVENT:
if !yaml_emitter_analyze_anchor(, .anchor, true) {
return false
}
case yaml_SCALAR_EVENT:
if len(.anchor) > 0 {
if !yaml_emitter_analyze_anchor(, .anchor, false) {
return false
}
}
if len(.tag) > 0 && (.canonical || (!.implicit && !.quoted_implicit)) {
if !yaml_emitter_analyze_tag(, .tag) {
return false
}
}
if !yaml_emitter_analyze_scalar(, .value) {
return false
}
case yaml_SEQUENCE_START_EVENT:
if len(.anchor) > 0 {
if !yaml_emitter_analyze_anchor(, .anchor, false) {
return false
}
}
if len(.tag) > 0 && (.canonical || !.implicit) {
if !yaml_emitter_analyze_tag(, .tag) {
return false
}
}
case yaml_MAPPING_START_EVENT:
if len(.anchor) > 0 {
if !yaml_emitter_analyze_anchor(, .anchor, false) {
return false
}
}
if len(.tag) > 0 && (.canonical || !.implicit) {
if !yaml_emitter_analyze_tag(, .tag) {
return false
}
}
}
return true
}
func ( *yaml_emitter_t) bool {
if !flush() {
return false
}
:= .buffer_pos
.buffer[+0] = '\xEF'
.buffer[+1] = '\xBB'
.buffer[+2] = '\xBF'
.buffer_pos += 3
return true
}
func ( *yaml_emitter_t) bool {
:= .indent
if < 0 {
= 0
}
if !.indention || .column > || (.column == && !.whitespace) {
if !put_break() {
return false
}
}
for .column < {
if !put(, ' ') {
return false
}
}
.whitespace = true
.indention = true
return true
}
func ( *yaml_emitter_t, []byte, , , bool) bool {
if && !.whitespace {
if !put(, ' ') {
return false
}
}
if !write_all(, ) {
return false
}
.whitespace =
.indention = (.indention && )
.open_ended = false
return true
}
func ( *yaml_emitter_t, []byte) bool {
if !write_all(, ) {
return false
}
.whitespace = false
.indention = false
return true
}
func ( *yaml_emitter_t, []byte) bool {
if !.whitespace {
if !put(, ' ') {
return false
}
}
if !write_all(, ) {
return false
}
.whitespace = false
.indention = false
return true
}
func ( *yaml_emitter_t, []byte, bool) bool {
if && !.whitespace {
if !put(, ' ') {
return false
}
}
for := 0; < len(); {
var bool
switch [] {
case ';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '_', '.', '~', '*', '\'', '(', ')', '[', ']':
= true
default:
= is_alpha(, )
}
if {
if !write(, , &) {
return false
}
} else {
:= width([])
for := 0; < ; ++ {
:= []
++
if !put(, '%') {
return false
}
:= >> 4
if < 10 {
+= '0'
} else {
+= 'A' - 10
}
if !put(, ) {
return false
}
= & 0x0f
if < 10 {
+= '0'
} else {
+= 'A' - 10
}
if !put(, ) {
return false
}
}
}
}
.whitespace = false
.indention = false
return true
}
func ( *yaml_emitter_t, []byte, bool) bool {
if !.whitespace {
if !put(, ' ') {
return false
}
}
:= false
:= false
for := 0; < len(); {
if is_space(, ) {
if && ! && .column > .best_width && !is_space(, +1) {
if !yaml_emitter_write_indent() {
return false
}
+= width([])
} else {
if !write(, , &) {
return false
}
}
= true
} else if is_break(, ) {
if ! && [] == '\n' {
if !put_break() {
return false
}
}
if !write_break(, , &) {
return false
}
.indention = true
= true
} else {
if {
if !yaml_emitter_write_indent() {
return false
}
}
if !write(, , &) {
return false
}
.indention = false
= false
= false
}
}
.whitespace = false
.indention = false
if .root_context {
.open_ended = true
}
return true
}
func ( *yaml_emitter_t, []byte, bool) bool {
if !yaml_emitter_write_indicator(, []byte{'\''}, true, false, false) {
return false
}
:= false
:= false
for := 0; < len(); {
if is_space(, ) {
if && ! && .column > .best_width && > 0 && < len()-1 && !is_space(, +1) {
if !yaml_emitter_write_indent() {
return false
}
+= width([])
} else {
if !write(, , &) {
return false
}
}
= true
} else if is_break(, ) {
if ! && [] == '\n' {
if !put_break() {
return false
}
}
if !write_break(, , &) {
return false
}
.indention = true
= true
} else {
if {
if !yaml_emitter_write_indent() {
return false
}
}
if [] == '\'' {
if !put(, '\'') {
return false
}
}
if !write(, , &) {
return false
}
.indention = false
= false
= false
}
}
if !yaml_emitter_write_indicator(, []byte{'\''}, false, false, false) {
return false
}
.whitespace = false
.indention = false
return true
}
func ( *yaml_emitter_t, []byte, bool) bool {
:= false
if !yaml_emitter_write_indicator(, []byte{'"'}, true, false, false) {
return false
}
for := 0; < len(); {
if !is_printable(, ) || (!.unicode && !is_ascii(, )) ||
is_bom(, ) || is_break(, ) ||
[] == '"' || [] == '\\' {
:= []
var int
var rune
switch {
case &0x80 == 0x00:
, = 1, rune(&0x7F)
case &0xE0 == 0xC0:
, = 2, rune(&0x1F)
case &0xF0 == 0xE0:
, = 3, rune(&0x0F)
case &0xF8 == 0xF0:
, = 4, rune(&0x07)
}
for := 1; < ; ++ {
= [+]
= ( << 6) + (rune() & 0x3F)
}
+=
if !put(, '\\') {
return false
}
var bool
switch {
case 0x00:
= put(, '0')
case 0x07:
= put(, 'a')
case 0x08:
= put(, 'b')
case 0x09:
= put(, 't')
case 0x0A:
= put(, 'n')
case 0x0b:
= put(, 'v')
case 0x0c:
= put(, 'f')
case 0x0d:
= put(, 'r')
case 0x1b:
= put(, 'e')
case 0x22:
= put(, '"')
case 0x5c:
= put(, '\\')
case 0x85:
= put(, 'N')
case 0xA0:
= put(, '_')
case 0x2028:
= put(, 'L')
case 0x2029:
= put(, 'P')
default:
if <= 0xFF {
= put(, 'x')
= 2
} else if <= 0xFFFF {
= put(, 'u')
= 4
} else {
= put(, 'U')
= 8
}
for := ( - 1) * 4; && >= 0; -= 4 {
:= byte(( >> uint()) & 0x0F)
if < 10 {
= put(, +'0')
} else {
= put(, +'A'-10)
}
}
}
if ! {
return false
}
= false
} else if is_space(, ) {
if && ! && .column > .best_width && > 0 && < len()-1 {
if !yaml_emitter_write_indent() {
return false
}
if is_space(, +1) {
if !put(, '\\') {
return false
}
}
+= width([])
} else if !write(, , &) {
return false
}
= true
} else {
if !write(, , &) {
return false
}
= false
}
}
if !yaml_emitter_write_indicator(, []byte{'"'}, false, false, false) {
return false
}
.whitespace = false
.indention = false
return true
}
func ( *yaml_emitter_t, []byte) bool {
if is_space(, 0) || is_break(, 0) {
:= []byte{'0' + byte(.best_indent)}
if !yaml_emitter_write_indicator(, , false, false, false) {
return false
}
}
.open_ended = false
var [1]byte
if len() == 0 {
[0] = '-'
} else {
:= len() - 1
for []&0xC0 == 0x80 {
--
}
if !is_break(, ) {
[0] = '-'
} else if == 0 {
[0] = '+'
.open_ended = true
} else {
--
for []&0xC0 == 0x80 {
--
}
if is_break(, ) {
[0] = '+'
.open_ended = true
}
}
}
if [0] != 0 {
if !yaml_emitter_write_indicator(, [:], false, false, false) {
return false
}
}
return true
}
func ( *yaml_emitter_t, []byte) bool {
if !yaml_emitter_write_indicator(, []byte{'|'}, true, false, false) {
return false
}
if !yaml_emitter_write_block_scalar_hints(, ) {
return false
}
if !put_break() {
return false
}
.indention = true
.whitespace = true
:= true
for := 0; < len(); {
if is_break(, ) {
if !write_break(, , &) {
return false
}
.indention = true
= true
} else {
if {
if !yaml_emitter_write_indent() {
return false
}
}
if !write(, , &) {
return false
}
.indention = false
= false
}
}
return true
}
func ( *yaml_emitter_t, []byte) bool {
if !yaml_emitter_write_indicator(, []byte{'>'}, true, false, false) {
return false
}
if !yaml_emitter_write_block_scalar_hints(, ) {
return false
}
if !put_break() {
return false
}
.indention = true
.whitespace = true
:= true
:= true
for := 0; < len(); {
if is_break(, ) {
if ! && ! && [] == '\n' {
:= 0
for is_break(, ) {
+= width([])
}
if !is_blankz(, ) {
if !put_break() {
return false
}
}
}
if !write_break(, , &) {
return false
}
.indention = true
= true
} else {
if {
if !yaml_emitter_write_indent() {
return false
}
= is_blank(, )
}
if ! && is_space(, ) && !is_space(, +1) && .column > .best_width {
if !yaml_emitter_write_indent() {
return false
}
+= width([])
} else {
if !write(, , &) {
return false
}
}
.indention = false
= false
}
}
return true
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |