Printf mimics fmt.Fprintf(buf, ...), but limited to %s for string and %v for Node.
(format string, values ...any)
| 35 | |
| 36 | // Printf mimics fmt.Fprintf(buf, ...), but limited to %s for string and %v for Node. |
| 37 | func (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. |
| 74 | func String(node SQLNode) string { |