MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / EscapeString

Method EscapeString

server/webdav/internal/xml/xml.go:1932–1967  ·  view source on GitHub ↗

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

(s string)

Source from the content-addressed store, hash-verified

1930// EscapeString writes to p the properly escaped XML equivalent
1931// of the plain text data s.
1932func (p *printer) EscapeString(s string) {
1933 var esc []byte
1934 last := 0
1935 for i := 0; i < len(s); {
1936 r, width := utf8.DecodeRuneInString(s[i:])
1937 i += width
1938 switch r {
1939 case '"':
1940 esc = esc_quot
1941 case '\'':
1942 esc = esc_apos
1943 case '&':
1944 esc = esc_amp
1945 case '<':
1946 esc = esc_lt
1947 case '>':
1948 esc = esc_gt
1949 case '\t':
1950 esc = esc_tab
1951 case '\n':
1952 esc = esc_nl
1953 case '\r':
1954 esc = esc_cr
1955 default:
1956 if !isInCharacterRange(r) || (r == 0xFFFD && width == 1) {
1957 esc = esc_fffd
1958 break
1959 }
1960 continue
1961 }
1962 p.WriteString(s[last : i-width])
1963 p.Write(esc)
1964 last = i
1965 }
1966 p.WriteString(s[last:])
1967}
1968
1969// Escape is like EscapeText but omits the error return value.
1970// It is provided for backwards compatibility with Go 1.0.

Callers 4

marshalValueMethod · 0.95
writeStartMethod · 0.95
PlistFunction · 0.80
ErrorPageFunction · 0.80

Calls 2

isInCharacterRangeFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected