MCPcopy Index your code
hub / github.com/segmentio/encoding / appendCompactEscapeHTML

Function appendCompactEscapeHTML

json/encode.go:909–970  ·  view source on GitHub ↗
(dst []byte, src []byte)

Source from the content-addressed store, hash-verified

907}
908
909func appendCompactEscapeHTML(dst []byte, src []byte) []byte {
910 start := 0
911 escape := false
912 inString := false
913
914 for i, c := range src {
915 if !inString {
916 switch c {
917 case '"': // enter string
918 inString = true
919 case ' ', '\n', '\r', '\t': // skip space
920 if start < i {
921 dst = append(dst, src[start:i]...)
922 }
923 start = i + 1
924 }
925 continue
926 }
927
928 if escape {
929 escape = false
930 continue
931 }
932
933 if c == '\\' {
934 escape = true
935 continue
936 }
937
938 if c == '"' {
939 inString = false
940 continue
941 }
942
943 if c == '<' || c == '>' || c == '&' {
944 if start < i {
945 dst = append(dst, src[start:i]...)
946 }
947 dst = append(dst, `\u00`...)
948 dst = append(dst, hex[c>>4], hex[c&0xF])
949 start = i + 1
950 continue
951 }
952
953 // Convert U+2028 and U+2029 (E2 80 A8 and E2 80 A9).
954 if c == 0xE2 && i+2 < len(src) && src[i+1] == 0x80 && src[i+2]&^1 == 0xA8 {
955 if start < i {
956 dst = append(dst, src[start:i]...)
957 }
958 dst = append(dst, `\u202`...)
959 dst = append(dst, hex[src[i+2]&0xF])
960 start = i + 3
961 continue
962 }
963 }
964
965 if start < len(src) {
966 dst = append(dst, src[start:]...)

Callers 2

encodeRawMessageMethod · 0.85
encodeJSONMarshalerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…