MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / EscapeString

Method EscapeString

opensca/sca/java/xml/xml.go:1956–1991  ·  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

1954// EscapeString writes to p the properly escaped XML equivalent
1955// of the plain text data s.
1956func (p *printer) EscapeString(s string) {
1957 var esc []byte
1958 last := 0
1959 for i := 0; i < len(s); {
1960 r, width := utf8.DecodeRuneInString(s[i:])
1961 i += width
1962 switch r {
1963 case '"':
1964 esc = escQuot
1965 case '\'':
1966 esc = escApos
1967 case '&':
1968 esc = escAmp
1969 case '<':
1970 esc = escLT
1971 case '>':
1972 esc = escGT
1973 case '\t':
1974 esc = escTab
1975 case '\n':
1976 esc = escNL
1977 case '\r':
1978 esc = escCR
1979 default:
1980 if !isInCharacterRange(r) || (r == 0xFFFD && width == 1) {
1981 esc = escFFFD
1982 break
1983 }
1984 continue
1985 }
1986 p.WriteString(s[last : i-width])
1987 p.Write(esc)
1988 last = i
1989 }
1990 p.WriteString(s[last:])
1991}
1992
1993// Escape is like EscapeText but omits the error return value.
1994// It is provided for backwards compatibility with Go 1.0.

Callers 2

marshalValueMethod · 0.95
writeStartMethod · 0.95

Calls 3

WriteStringMethod · 0.95
WriteMethod · 0.95
isInCharacterRangeFunction · 0.85

Tested by

no test coverage detected