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

Function emitCDATA

opensca/sca/java/xml/xml.go:2008–2037  ·  view source on GitHub ↗

emitCDATA writes to w the CDATA-wrapped plain text data s. It escapes CDATA directives nested in s.

(w io.Writer, s []byte)

Source from the content-addressed store, hash-verified

2006// emitCDATA writes to w the CDATA-wrapped plain text data s.
2007// It escapes CDATA directives nested in s.
2008func emitCDATA(w io.Writer, s []byte) error {
2009 if len(s) == 0 {
2010 return nil
2011 }
2012 if _, err := w.Write(cdataStart); err != nil {
2013 return err
2014 }
2015
2016 for {
2017 before, after, ok := bytes.Cut(s, cdataEnd)
2018 if !ok {
2019 break
2020 }
2021 // Found a nested CDATA directive end.
2022 if _, err := w.Write(before); err != nil {
2023 return err
2024 }
2025 if _, err := w.Write(cdataEscape); err != nil {
2026 return err
2027 }
2028 s = after
2029 }
2030
2031 if _, err := w.Write(s); err != nil {
2032 return err
2033 }
2034
2035 _, err := w.Write(cdataEnd)
2036 return err
2037}
2038
2039// procInst parses the `param="..."` or `param='...'`
2040// value out of the provided string, returning "" if not found.

Callers

nothing calls this directly

Calls 1

WriteMethod · 0.80

Tested by

no test coverage detected