Path: blob/main/vendor/gopkg.in/yaml.v3/writerc.go
2872 views
//1// Copyright (c) 2011-2019 Canonical Ltd2// Copyright (c) 2006-2010 Kirill Simonov3//4// Permission is hereby granted, free of charge, to any person obtaining a copy of5// this software and associated documentation files (the "Software"), to deal in6// the Software without restriction, including without limitation the rights to7// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies8// of the Software, and to permit persons to whom the Software is furnished to do9// so, subject to the following conditions:10//11// The above copyright notice and this permission notice shall be included in all12// copies or substantial portions of the Software.13//14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20// SOFTWARE.2122package yaml2324// Set the writer error and return false.25func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool {26emitter.error = yaml_WRITER_ERROR27emitter.problem = problem28return false29}3031// Flush the output buffer.32func yaml_emitter_flush(emitter *yaml_emitter_t) bool {33if emitter.write_handler == nil {34panic("write handler not set")35}3637// Check if the buffer is empty.38if emitter.buffer_pos == 0 {39return true40}4142if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil {43return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error())44}45emitter.buffer_pos = 046return true47}484950