MCPcopy
hub / github.com/cube2222/octosql / Myprintf

Method Myprintf

parser/sqlparser/tracked_buffer.go:68–117  ·  view source on GitHub ↗

Myprintf mimics fmt.Fprintf(buf, ...), but limited to Node(%v), Node.Value(%s) and string(%s). It also allows a %a for a value argument, in which case it adds tracking info for future substitutions. The name must be something other than the usual Printf() to avoid "go vet" warnings due to our custo

(format string, values ...interface{})

Source from the content-addressed store, hash-verified

66// The name must be something other than the usual Printf() to avoid "go vet"
67// warnings due to our custom format specifiers.
68func (buf *TrackedBuffer) Myprintf(format string, values ...interface{}) {
69 end := len(format)
70 fieldnum := 0
71 for i := 0; i < end; {
72 lasti := i
73 for i < end && format[i] != '%' {
74 i++
75 }
76 if i > lasti {
77 buf.WriteString(format[lasti:i])
78 }
79 if i >= end {
80 break
81 }
82 i++ // '%'
83 switch format[i] {
84 case 'c':
85 switch v := values[fieldnum].(type) {
86 case byte:
87 buf.WriteByte(v)
88 case rune:
89 buf.WriteRune(v)
90 default:
91 panic(fmt.Sprintf("unexpected TrackedBuffer type %T", v))
92 }
93 case 's':
94 switch v := values[fieldnum].(type) {
95 case []byte:
96 buf.Write(v)
97 case string:
98 buf.WriteString(v)
99 default:
100 panic(fmt.Sprintf("unexpected TrackedBuffer type %T", v))
101 }
102 case 'v':
103 node := values[fieldnum].(SQLNode)
104 if buf.nodeFormatter == nil {
105 node.Format(buf)
106 } else {
107 buf.nodeFormatter(buf, node)
108 }
109 case 'a':
110 buf.WriteArg(values[fieldnum].(string))
111 default:
112 panic("unexpected")
113 }
114 fieldnum++
115 i++
116 }
117}
118
119// WriteArg writes a value argument into the buffer along with
120// tracking information for future substitutions. arg must contain

Callers 15

StringFunction · 0.95
DescribeTypeMethod · 0.95
NewParsedQueryFunction · 0.95
WriteNodeMethod · 0.95
BuildParsedQueryFunction · 0.95
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80

Calls 5

WriteArgMethod · 0.95
WriteStringMethod · 0.80
WriteByteMethod · 0.65
WriteMethod · 0.65
FormatMethod · 0.65

Tested by

no test coverage detected