forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/davecgh/go-spew/spew/spew.go

267 lines
5.9 KiB
Go
Raw Normal View History

2024-04-26 19:30:35 +00:00
/*
2024-04-26 19:30:35 +00:00
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
2024-04-26 19:30:35 +00:00
*
2024-04-26 19:30:35 +00:00
* Permission to use, copy, modify, and distribute this software for any
2024-04-26 19:30:35 +00:00
* purpose with or without fee is hereby granted, provided that the above
2024-04-26 19:30:35 +00:00
* copyright notice and this permission notice appear in all copies.
2024-04-26 19:30:35 +00:00
*
2024-04-26 19:30:35 +00:00
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
2024-04-26 19:30:35 +00:00
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
2024-04-26 19:30:35 +00:00
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
2024-04-26 19:30:35 +00:00
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2024-04-26 19:30:35 +00:00
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
2024-04-26 19:30:35 +00:00
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2024-04-26 19:30:35 +00:00
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2024-04-26 19:30:35 +00:00
*/
package spew
import (
"fmt"
"io"
)
// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the formatted string as a value that satisfies error. See
2024-04-26 19:30:35 +00:00
// NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Errorf(format string, a ...interface{}) (err error) {
2024-04-26 19:30:35 +00:00
return fmt.Errorf(format, convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the number of bytes written and any write error encountered. See
2024-04-26 19:30:35 +00:00
// NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
2024-04-26 19:30:35 +00:00
return fmt.Fprint(w, convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the number of bytes written and any write error encountered. See
2024-04-26 19:30:35 +00:00
// NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
2024-04-26 19:30:35 +00:00
return fmt.Fprintf(w, format, convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. See
2024-04-26 19:30:35 +00:00
// NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
2024-04-26 19:30:35 +00:00
return fmt.Fprintln(w, convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Print is a wrapper for fmt.Print that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the number of bytes written and any write error encountered. See
2024-04-26 19:30:35 +00:00
// NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Print(a ...interface{}) (n int, err error) {
2024-04-26 19:30:35 +00:00
return fmt.Print(convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Printf is a wrapper for fmt.Printf that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the number of bytes written and any write error encountered. See
2024-04-26 19:30:35 +00:00
// NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Printf(format string, a ...interface{}) (n int, err error) {
2024-04-26 19:30:35 +00:00
return fmt.Printf(format, convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Println is a wrapper for fmt.Println that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the number of bytes written and any write error encountered. See
2024-04-26 19:30:35 +00:00
// NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Println(a ...interface{}) (n int, err error) {
2024-04-26 19:30:35 +00:00
return fmt.Println(convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the resulting string. See NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Sprint(a ...interface{}) string {
2024-04-26 19:30:35 +00:00
return fmt.Sprint(convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were
2024-04-26 19:30:35 +00:00
// passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the resulting string. See NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Sprintf(format string, a ...interface{}) string {
2024-04-26 19:30:35 +00:00
return fmt.Sprintf(format, convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it
2024-04-26 19:30:35 +00:00
// were passed with a default Formatter interface returned by NewFormatter. It
2024-04-26 19:30:35 +00:00
// returns the resulting string. See NewFormatter for formatting details.
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// This function is shorthand for the following syntax:
2024-04-26 19:30:35 +00:00
//
2024-04-26 19:30:35 +00:00
// fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b))
2024-04-26 19:30:35 +00:00
func Sprintln(a ...interface{}) string {
2024-04-26 19:30:35 +00:00
return fmt.Sprintln(convertArgs(a)...)
2024-04-26 19:30:35 +00:00
}
// convertArgs accepts a slice of arguments and returns a slice of the same
2024-04-26 19:30:35 +00:00
// length with each argument converted to a default spew Formatter interface.
2024-04-26 19:30:35 +00:00
func convertArgs(args []interface{}) (formatters []interface{}) {
2024-04-26 19:30:35 +00:00
formatters = make([]interface{}, len(args))
2024-04-26 19:30:35 +00:00
for index, arg := range args {
2024-04-26 19:30:35 +00:00
formatters[index] = NewFormatter(arg)
2024-04-26 19:30:35 +00:00
}
2024-04-26 19:30:35 +00:00
return formatters
2024-04-26 19:30:35 +00:00
}