diff options
Diffstat (limited to 'libgo/go/html/escape.go')
-rw-r--r-- | libgo/go/html/escape.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/libgo/go/html/escape.go b/libgo/go/html/escape.go index 0de97c5ac1b..e9edc474da5 100644 --- a/libgo/go/html/escape.go +++ b/libgo/go/html/escape.go @@ -6,6 +6,7 @@ package html import ( "bytes" + "os" "strings" "utf8" ) @@ -182,12 +183,24 @@ func unescape(b []byte) []byte { return b } +// lower lower-cases the A-Z bytes in b in-place, so that "aBc" becomes "abc". +func lower(b []byte) []byte { + for i, c := range b { + if 'A' <= c && c <= 'Z' { + b[i] = c + 'a' - 'A' + } + } + return b +} + const escapedChars = `&'<>"` -func escape(buf *bytes.Buffer, s string) { +func escape(w writer, s string) os.Error { i := strings.IndexAny(s, escapedChars) for i != -1 { - buf.WriteString(s[0:i]) + if _, err := w.WriteString(s[:i]); err != nil { + return err + } var esc string switch s[i] { case '&': @@ -204,10 +217,13 @@ func escape(buf *bytes.Buffer, s string) { panic("unrecognized escape character") } s = s[i+1:] - buf.WriteString(esc) + if _, err := w.WriteString(esc); err != nil { + return err + } i = strings.IndexAny(s, escapedChars) } - buf.WriteString(s) + _, err := w.WriteString(s) + return err } // EscapeString escapes special characters like "<" to become "<". It |