2 * Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 // Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
25 // passed with a default Formatter interface returned by NewFormatter. It
26 // returns the formatted string as a value that satisfies error. See
27 // NewFormatter for formatting details.
29 // This function is shorthand for the following syntax:
31 // fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b))
32 func Errorf(format string, a ...interface{}) (err error) {
33 return fmt.Errorf(format, convertArgs(a)...)
36 // Fprint is a wrapper for fmt.Fprint that treats each argument as if it were
37 // passed with a default Formatter interface returned by NewFormatter. It
38 // returns the number of bytes written and any write error encountered. See
39 // NewFormatter for formatting details.
41 // This function is shorthand for the following syntax:
43 // fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b))
44 func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
45 return fmt.Fprint(w, convertArgs(a)...)
48 // Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were
49 // passed with a default Formatter interface returned by NewFormatter. It
50 // returns the number of bytes written and any write error encountered. See
51 // NewFormatter for formatting details.
53 // This function is shorthand for the following syntax:
55 // fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b))
56 func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
57 return fmt.Fprintf(w, format, convertArgs(a)...)
60 // Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it
61 // passed with a default Formatter interface returned by NewFormatter. See
62 // NewFormatter for formatting details.
64 // This function is shorthand for the following syntax:
66 // fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b))
67 func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
68 return fmt.Fprintln(w, convertArgs(a)...)
71 // Print is a wrapper for fmt.Print that treats each argument as if it were
72 // passed with a default Formatter interface returned by NewFormatter. It
73 // returns the number of bytes written and any write error encountered. See
74 // NewFormatter for formatting details.
76 // This function is shorthand for the following syntax:
78 // fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b))
79 func Print(a ...interface{}) (n int, err error) {
80 return fmt.Print(convertArgs(a)...)
83 // Printf is a wrapper for fmt.Printf that treats each argument as if it were
84 // passed with a default Formatter interface returned by NewFormatter. It
85 // returns the number of bytes written and any write error encountered. See
86 // NewFormatter for formatting details.
88 // This function is shorthand for the following syntax:
90 // fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b))
91 func Printf(format string, a ...interface{}) (n int, err error) {
92 return fmt.Printf(format, convertArgs(a)...)
95 // Println is a wrapper for fmt.Println that treats each argument as if it were
96 // passed with a default Formatter interface returned by NewFormatter. It
97 // returns the number of bytes written and any write error encountered. See
98 // NewFormatter for formatting details.
100 // This function is shorthand for the following syntax:
102 // fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b))
103 func Println(a ...interface{}) (n int, err error) {
104 return fmt.Println(convertArgs(a)...)
107 // Sprint is a wrapper for fmt.Sprint that treats each argument as if it were
108 // passed with a default Formatter interface returned by NewFormatter. It
109 // returns the resulting string. See NewFormatter for formatting details.
111 // This function is shorthand for the following syntax:
113 // fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b))
114 func Sprint(a ...interface{}) string {
115 return fmt.Sprint(convertArgs(a)...)
118 // Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were
119 // passed with a default Formatter interface returned by NewFormatter. It
120 // returns the resulting string. See NewFormatter for formatting details.
122 // This function is shorthand for the following syntax:
124 // fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b))
125 func Sprintf(format string, a ...interface{}) string {
126 return fmt.Sprintf(format, convertArgs(a)...)
129 // Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it
130 // were passed with a default Formatter interface returned by NewFormatter. It
131 // returns the resulting string. See NewFormatter for formatting details.
133 // This function is shorthand for the following syntax:
135 // fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b))
136 func Sprintln(a ...interface{}) string {
137 return fmt.Sprintln(convertArgs(a)...)
140 // convertArgs accepts a slice of arguments and returns a slice of the same
141 // length with each argument converted to a default spew Formatter interface.
142 func convertArgs(args []interface{}) (formatters []interface{}) {
143 formatters = make([]interface{}, len(args))
144 for index, arg := range args {
145 formatters[index] = NewFormatter(arg)