MCPcopy Index your code
hub / github.com/php/frankenphp / escapeCString

Function escapeCString

internal/extgen/cfile.go:80–100  ·  view source on GitHub ↗

escapeCString escapes characters that would break a C double-quoted string literal.

(s string)

Source from the content-addressed store, hash-verified

78
79// escapeCString escapes characters that would break a C double-quoted string literal.
80func escapeCString(s string) string {
81 var b strings.Builder
82 b.Grow(len(s))
83 for _, r := range s {
84 switch r {
85 case '\\':
86 b.WriteString(`\\`)
87 case '"':
88 b.WriteString(`\"`)
89 case '\n':
90 b.WriteString(`\n`)
91 case '\r':
92 b.WriteString(`\r`)
93 case '\t':
94 b.WriteString(`\t`)
95 default:
96 b.WriteRune(r)
97 }
98 }
99 return b.String()
100}

Callers 1

TestEscapeCStringFunction · 0.85

Calls 2

WriteStringMethod · 0.80
StringMethod · 0.45

Tested by 1

TestEscapeCStringFunction · 0.68