MCPcopy
hub / github.com/sqldef/sqldef / Printf

Method Printf

parser/node.go:37–71  ·  view source on GitHub ↗

Printf mimics fmt.Fprintf(buf, ...), but limited to %s for string and %v for Node.

(format string, values ...any)

Source from the content-addressed store, hash-verified

35
36// Printf mimics fmt.Fprintf(buf, ...), but limited to %s for string and %v for Node.
37func (buf *nodeBuffer) Printf(format string, values ...any) {
38 end := len(format)
39 fieldnum := 0
40 for i := 0; i < end; {
41 lasti := i
42 for i < end && format[i] != '%' {
43 i++
44 }
45 if i > lasti {
46 buf.WriteString(format[lasti:i])
47 }
48 if i >= end {
49 break
50 }
51 i++ // '%'
52 switch format[i] {
53 case 's':
54 switch v := values[fieldnum].(type) {
55 case []byte:
56 buf.Write(v)
57 case string:
58 buf.WriteString(v)
59 default:
60 panic(fmt.Sprintf("unexpected string type %T", v))
61 }
62 case 'v':
63 node := values[fieldnum].(SQLNode)
64 node.Format(buf)
65 default:
66 panic(fmt.Sprintf("unexpected format: %c", format[i]))
67 }
68 fieldnum++
69 i++
70 }
71}
72
73// String returns a string representation of an SQLNode.
74func String(node SQLNode) string {

Callers

nothing calls this directly

Calls 1

FormatMethod · 0.65

Tested by

no test coverage detected