MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / EncodeEscapedChar

Function EncodeEscapedChar

pkg/util/stringencoding/string_encoding.go:82–118  ·  view source on GitHub ↗

EncodeEscapedChar is used internally to write out a character from a larger string that needs to be escaped to a buffer.

(
	buf *bytes.Buffer,
	entireString string,
	currentRune rune,
	currentByte byte,
	currentIdx int,
	quoteChar byte,
)

Source from the content-addressed store, hash-verified

80// EncodeEscapedChar is used internally to write out a character from a larger
81// string that needs to be escaped to a buffer.
82func EncodeEscapedChar(
83 buf *bytes.Buffer,
84 entireString string,
85 currentRune rune,
86 currentByte byte,
87 currentIdx int,
88 quoteChar byte,
89) {
90 ln := utf8.RuneLen(currentRune)
91 if currentRune == utf8.RuneError {
92 // Errors are due to invalid unicode points, so escape the bytes.
93 // Make sure this is run at least once in case ln == -1.
94 buf.Write(HexMap[entireString[currentIdx]])
95 for ri := 1; ri < ln; ri++ {
96 if currentIdx+ri < len(entireString) {
97 buf.Write(HexMap[entireString[currentIdx+ri]])
98 }
99 }
100 } else if ln == 1 {
101 // For single-byte runes, do the same as encodeSQLBytes.
102 if encodedChar := EncodeMap[currentByte]; encodedChar != DontEscape {
103 buf.WriteByte('\\')
104 buf.WriteByte(encodedChar)
105 } else if currentByte == quoteChar {
106 buf.WriteByte('\\')
107 buf.WriteByte(quoteChar)
108 } else {
109 // Escape non-printable characters.
110 buf.Write(HexMap[currentByte])
111 }
112 } else if ln == 2 {
113 // For multi-byte runes, print them based on their width.
114 fmt.Fprintf(buf, `\u%04X`, currentRune)
115 } else {
116 fmt.Fprintf(buf, `\U%08X`, currentRune)
117 }
118}
119
120func writeHexDigit(buf *bytes.Buffer, v int) {
121 if v < 10 {

Callers 1

EncodeSQLStringWithFlagsFunction · 0.92

Calls 1

WriteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…