MCPcopy Index your code
hub / github.com/XmirrorSecurity/OpenSCA-cli / text

Method text

opensca/sca/java/xml/xml.go:982–1144  ·  view source on GitHub ↗

Read plain text section (XML calls it character data). If quote >= 0, we are in a quoted string and need to find the matching quote. If cdata == true, we are in a <![CDATA[ section and need to find ]]>. On failure return nil and leave the error in d.err.

(quote int, cdata bool)

Source from the content-addressed store, hash-verified

980// If cdata == true, we are in a <![CDATA[ section and need to find ]]>.
981// On failure return nil and leave the error in d.err.
982func (d *Decoder) text(quote int, cdata bool) []byte {
983 var b0, b1 byte
984 var trunc int
985 d.buf.Reset()
986Input:
987 for {
988 b, ok := d.getc()
989 if !ok {
990 if cdata {
991 if d.err == io.EOF {
992 d.err = d.syntaxError("unexpected EOF in CDATA section")
993 }
994 return nil
995 }
996 break Input
997 }
998
999 // <![CDATA[ section ends with ]]>.
1000 // It is an error for ]]> to appear in ordinary text.
1001 if b0 == ']' && b1 == ']' && b == '>' {
1002 if cdata {
1003 trunc = 2
1004 break Input
1005 }
1006 d.err = d.syntaxError("unescaped ]]> not in CDATA section")
1007 return nil
1008 }
1009
1010 // Stop reading text if we see a <.
1011 if b == '<' && !cdata {
1012 if quote >= 0 {
1013 d.err = d.syntaxError("unescaped < inside quoted string")
1014 return nil
1015 }
1016 d.ungetc('<')
1017 break Input
1018 }
1019 if quote >= 0 && b == byte(quote) {
1020 break Input
1021 }
1022 if b == '&' && !cdata {
1023 // Read escaped character expression up to semicolon.
1024 // XML in all its glory allows a document to define and use
1025 // its own character names with <!ENTITY ...> directives.
1026 // Parsers are required to recognize lt, gt, amp, apos, and quot
1027 // even if they have not been declared.
1028 before := d.buf.Len()
1029 d.buf.WriteByte('&')
1030 var ok bool
1031 var text string
1032 var haveText bool
1033 if b, ok = d.mustgetc(); !ok {
1034 return nil
1035 }
1036 if b == '#' {
1037 d.buf.WriteByte(b)
1038 if b, ok = d.mustgetc(); !ok {
1039 return nil

Callers 2

rawTokenMethod · 0.95
attrvalMethod · 0.95

Calls 9

getcMethod · 0.95
syntaxErrorMethod · 0.95
ungetcMethod · 0.95
mustgetcMethod · 0.95
readNameMethod · 0.95
isNameFunction · 0.85
isInCharacterRangeFunction · 0.85
WriteByteMethod · 0.80
WriteStringMethod · 0.80

Tested by

no test coverage detected