summaryrefslogtreecommitdiff
path: root/vendor/github.com/pquerna/ffjson/inception/writerstack.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-08-08 23:17:16 +0200
committerGitHub <noreply@github.com>2019-08-08 23:17:16 +0200
commit202eadef2cd46f3a74075a6cfe4e4064d0e14a63 (patch)
treeddc9ac4270eec6021bde3eb18aa79a49bab8f172 /vendor/github.com/pquerna/ffjson/inception/writerstack.go
parente74957234a6f6bca47c68fd5365a39c77cdbbf3c (diff)
parent711474d92e4a5c378d818a14445893c6349b40a3 (diff)
downloadpodman-202eadef2cd46f3a74075a6cfe4e4064d0e14a63.tar.gz
podman-202eadef2cd46f3a74075a6cfe4e4064d0e14a63.tar.bz2
podman-202eadef2cd46f3a74075a6cfe4e4064d0e14a63.zip
Merge pull request #3765 from TomSweeneyRedHat/dev/tsweeney/buildahvendor
Vendor Buildah 1.10.1
Diffstat (limited to 'vendor/github.com/pquerna/ffjson/inception/writerstack.go')
-rw-r--r--vendor/github.com/pquerna/ffjson/inception/writerstack.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/github.com/pquerna/ffjson/inception/writerstack.go b/vendor/github.com/pquerna/ffjson/inception/writerstack.go
new file mode 100644
index 000000000..1521961c9
--- /dev/null
+++ b/vendor/github.com/pquerna/ffjson/inception/writerstack.go
@@ -0,0 +1,65 @@
+package ffjsoninception
+
+import "strings"
+
+// ConditionalWrite is a stack containing a number of pending writes
+type ConditionalWrite struct {
+ Queued []string
+}
+
+// Write will add a string to be written
+func (w *ConditionalWrite) Write(s string) {
+ w.Queued = append(w.Queued, s)
+}
+
+// DeleteLast will delete the last added write
+func (w *ConditionalWrite) DeleteLast() {
+ if len(w.Queued) == 0 {
+ return
+ }
+ w.Queued = w.Queued[:len(w.Queued)-1]
+}
+
+// Last will return the last added write
+func (w *ConditionalWrite) Last() string {
+ if len(w.Queued) == 0 {
+ return ""
+ }
+ return w.Queued[len(w.Queued)-1]
+}
+
+// Flush will return all queued writes, and return
+// "" (empty string) in nothing has been queued
+// "buf.WriteByte('" + byte + "')" + '\n' if one bute has been queued.
+// "buf.WriteString(`" + string + "`)" + "\n" if more than one byte has been queued.
+func (w *ConditionalWrite) Flush() string {
+ combined := strings.Join(w.Queued, "")
+ if len(combined) == 0 {
+ return ""
+ }
+
+ w.Queued = nil
+ if len(combined) == 1 {
+ return "buf.WriteByte('" + combined + "')" + "\n"
+ }
+ return "buf.WriteString(`" + combined + "`)" + "\n"
+}
+
+func (w *ConditionalWrite) FlushTo(out string) string {
+ out += w.Flush()
+ return out
+}
+
+// WriteFlush will add a string and return the Flush result for the queue
+func (w *ConditionalWrite) WriteFlush(s string) string {
+ w.Write(s)
+ return w.Flush()
+}
+
+// GetQueued will return the current queued content without flushing.
+func (w *ConditionalWrite) GetQueued() string {
+ t := w.Queued
+ s := w.Flush()
+ w.Queued = t
+ return s
+}