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

Method text

server/webdav/internal/xml/xml.go:960–1123  ·  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

958// If cdata == true, we are in a <![CDATA[ section and need to find ]]>.
959// On failure return nil and leave the error in d.err.
960func (d *Decoder) text(quote int, cdata bool) []byte {
961 var b0, b1 byte
962 var trunc int
963 d.buf.Reset()
964Input:
965 for {
966 b, ok := d.getc()
967 if !ok {
968 if cdata {
969 if d.err == io.EOF {
970 d.err = d.syntaxError("unexpected EOF in CDATA section")
971 }
972 return nil
973 }
974 break Input
975 }
976
977 // <![CDATA[ section ends with ]]>.
978 // It is an error for ]]> to appear in ordinary text.
979 if b0 == ']' && b1 == ']' && b == '>' {
980 if cdata {
981 trunc = 2
982 break Input
983 }
984 d.err = d.syntaxError("unescaped ]]> not in CDATA section")
985 return nil
986 }
987
988 // Stop reading text if we see a <.
989 if b == '<' && !cdata {
990 if quote >= 0 {
991 d.err = d.syntaxError("unescaped < inside quoted string")
992 return nil
993 }
994 d.ungetc('<')
995 break Input
996 }
997 if quote >= 0 && b == byte(quote) {
998 break Input
999 }
1000 if b == '&' && !cdata {
1001 // Read escaped character expression up to semicolon.
1002 // XML in all its glory allows a document to define and use
1003 // its own character names with <!ENTITY ...> directives.
1004 // Parsers are required to recognize lt, gt, amp, apos, and quot
1005 // even if they have not been declared.
1006 before := d.buf.Len()
1007 d.buf.WriteByte('&')
1008 var ok bool
1009 var text string
1010 var haveText bool
1011 if b, ok = d.mustgetc(); !ok {
1012 return nil
1013 }
1014 if b == '#' {
1015 d.buf.WriteByte(b)
1016 if b, ok = d.mustgetc(); !ok {
1017 return nil

Callers 2

rawTokenMethod · 0.95
attrvalMethod · 0.95

Calls 11

getcMethod · 0.95
syntaxErrorMethod · 0.95
ungetcMethod · 0.95
mustgetcMethod · 0.95
readNameMethod · 0.95
isNameFunction · 0.85
isInCharacterRangeFunction · 0.85
TruncateMethod · 0.80
LenMethod · 0.65
ResetMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected