github.com/keysonzzz/kmg@v0.0.0-20151121023212-05317bfd7d39/encoding/kmgYaml/yaml_emitter_check.go (about)

     1  package kmgYaml
     2  
     3  // Check if the document content is an empty scalar.
     4  func yaml_emitter_check_empty_document(emitter *yaml_emitter_t) bool {
     5  	return false // [Go] Huh?
     6  }
     7  
     8  // Check if the next events represent an empty sequence.
     9  func yaml_emitter_check_empty_sequence(emitter *yaml_emitter_t) bool {
    10  	if len(emitter.events)-emitter.events_head < 2 {
    11  		return false
    12  	}
    13  	return emitter.events[emitter.events_head].typ == yaml_SEQUENCE_START_EVENT &&
    14  		emitter.events[emitter.events_head+1].typ == yaml_SEQUENCE_END_EVENT
    15  }
    16  
    17  // Check if the next events represent an empty mapping.
    18  func yaml_emitter_check_empty_mapping(emitter *yaml_emitter_t) bool {
    19  	if len(emitter.events)-emitter.events_head < 2 {
    20  		return false
    21  	}
    22  	return emitter.events[emitter.events_head].typ == yaml_MAPPING_START_EVENT &&
    23  		emitter.events[emitter.events_head+1].typ == yaml_MAPPING_END_EVENT
    24  }
    25  
    26  // Check if the next node can be expressed as a simple key.
    27  func yaml_emitter_check_simple_key(emitter *yaml_emitter_t) bool {
    28  	length := 0
    29  	switch emitter.events[emitter.events_head].typ {
    30  	case yaml_ALIAS_EVENT:
    31  		length += len(emitter.anchor_data.anchor)
    32  	case yaml_SCALAR_EVENT:
    33  		if emitter.scalar_data.multiline {
    34  			return false
    35  		}
    36  		length += len(emitter.anchor_data.anchor) +
    37  			len(emitter.tag_data.handle) +
    38  			len(emitter.tag_data.suffix) +
    39  			len(emitter.scalar_data.value)
    40  	case yaml_SEQUENCE_START_EVENT:
    41  		if !yaml_emitter_check_empty_sequence(emitter) {
    42  			return false
    43  		}
    44  		length += len(emitter.anchor_data.anchor) +
    45  			len(emitter.tag_data.handle) +
    46  			len(emitter.tag_data.suffix)
    47  	case yaml_MAPPING_START_EVENT:
    48  		if !yaml_emitter_check_empty_mapping(emitter) {
    49  			return false
    50  		}
    51  		length += len(emitter.anchor_data.anchor) +
    52  			len(emitter.tag_data.handle) +
    53  			len(emitter.tag_data.suffix)
    54  	default:
    55  		return false
    56  	}
    57  	return length <= 128
    58  }