MCPcopy Create free account
hub / github.com/cogentcore/core / EscapeString

Method EscapeString

svg/xml.go:148–186  ·  view source on GitHub ↗

EscapeString writes to p the properly escaped XML equivalent of the plain text data s.

(s string, escapeNewline bool)

Source from the content-addressed store, hash-verified

146// EscapeString writes to p the properly escaped XML equivalent
147// of the plain text data s.
148func (xe *XMLEncoder) EscapeString(s string, escapeNewline bool) {
149 var esc []byte
150 last := 0
151 for i := 0; i < len(s); {
152 r, width := utf8.DecodeRuneInString(s[i:])
153 i += width
154 switch r {
155 case '"':
156 esc = escQuot
157 case '\'':
158 esc = escApos
159 case '&':
160 esc = escAmp
161 case '<':
162 esc = escLT
163 case '>':
164 esc = escGT
165 case '\t':
166 esc = escTab
167 case '\n':
168 if !escapeNewline {
169 continue
170 }
171 esc = escNL
172 case '\r':
173 esc = escCR
174 default:
175 if !isInCharacterRange(r) || (r == 0xFFFD && width == 1) {
176 esc = escFFFD
177 break
178 }
179 continue
180 }
181 xe.WriteString(s[last : i-width])
182 xe.Writer.Write(esc)
183 last = i
184 }
185 xe.WriteString(s[last:])
186}
187
188func (xe *XMLEncoder) WriteStart(start *xml.StartElement) error {
189 if start.Name.Local == "" {

Callers 4

WriteStartMethod · 0.95
HtmlEscapeBytesFunction · 0.80
HtmlEscapeRunesFunction · 0.80
GenDeclMethod · 0.80

Calls 3

WriteStringMethod · 0.95
isInCharacterRangeFunction · 0.85
WriteMethod · 0.65

Tested by

no test coverage detected