blob: b8a116bf9a22b9911958f44904289a8c6b482bd2 [file] [log] [blame]
khenaidoo26721882021-08-11 17:42:52 -04001//
2// Copyright (c) 2011-2019 Canonical Ltd
3// Copyright (c) 2006-2010 Kirill Simonov
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy of
6// this software and associated documentation files (the "Software"), to deal in
7// the Software without restriction, including without limitation the rights to
8// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9// of the Software, and to permit persons to whom the Software is furnished to do
10// so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23package yaml
24
25// Set the writer error and return false.
26func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool {
27 emitter.error = yaml_WRITER_ERROR
28 emitter.problem = problem
29 return false
30}
31
32// Flush the output buffer.
33func yaml_emitter_flush(emitter *yaml_emitter_t) bool {
34 if emitter.write_handler == nil {
35 panic("write handler not set")
36 }
37
38 // Check if the buffer is empty.
39 if emitter.buffer_pos == 0 {
40 return true
41 }
42
43 if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil {
44 return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error())
45 }
46 emitter.buffer_pos = 0
47 return true
48}