Add support for Sdump.
This commit adds a function named Sdump which works exactly like Dump and Fdump except it returns the formatted output as a string. This serves the same purpose as the the Sprint* family of functions.
This commit is contained in:
parent
9b87fb3e12
commit
3a62f585a7
|
@ -17,6 +17,7 @@
|
||||||
package spew
|
package spew
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -247,6 +248,14 @@ func (c *ConfigState) Dump(a ...interface{}) {
|
||||||
fdump(c, os.Stdout, a...)
|
fdump(c, os.Stdout, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sdump returns a string with the passed arguments formatted exactly the same
|
||||||
|
// as Dump.
|
||||||
|
func (c *ConfigState) Sdump(a ...interface{}) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fdump(c, &buf, a...)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
// convertArgs accepts a slice of arguments and returns a slice of the same
|
// convertArgs accepts a slice of arguments and returns a slice of the same
|
||||||
// length with each argument converted to a spew Formatter interface using
|
// length with each argument converted to a spew Formatter interface using
|
||||||
// the ConfigState associated with s.
|
// the ConfigState associated with s.
|
||||||
|
|
|
@ -363,6 +363,14 @@ func Fdump(w io.Writer, a ...interface{}) {
|
||||||
fdump(&Config, w, a...)
|
fdump(&Config, w, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sdump returns a string with the passed arguments formatted exactly the same
|
||||||
|
// as Dump.
|
||||||
|
func Sdump(a ...interface{}) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fdump(&Config, &buf, a...)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Dump displays the passed parameters to standard out with newlines, customizable
|
Dump displays the passed parameters to standard out with newlines, customizable
|
||||||
indentation, and additional debug information such as complete types and all
|
indentation, and additional debug information such as complete types and all
|
||||||
|
|
Loading…
Reference in New Issue