MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / escapeUnicodeString

Function escapeUnicodeString

pkg/sql/ast/value.go:243–265  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

241}
242
243func escapeUnicodeString(s string) string {
244 var result strings.Builder
245 for _, ch := range s {
246 switch ch {
247 case '\'':
248 result.WriteString("''")
249 case '\\':
250 result.WriteString(`\\`)
251 default:
252 if ch <= 127 { // ASCII
253 result.WriteRune(ch)
254 } else {
255 codepoint := int(ch)
256 if codepoint <= 0xFFFF {
257 result.WriteString(fmt.Sprintf("\\%04X", codepoint))
258 } else {
259 result.WriteString(fmt.Sprintf("\\+%06X", codepoint))
260 }
261 }
262 }
263 }
264 return result.String()
265}
266
267// DateTimeField represents date/time fields that can be extracted or used in operations
268type DateTimeField int

Callers 2

StringMethod · 0.85
TestEscapeUnicodeStringFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestEscapeUnicodeStringFunction · 0.68