Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
c90b05bf
Commit
c90b05bf
authored
Jan 26, 2010
by
Stephen Weinberg
Committed by
Russ Cox
Jan 26, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xml: add Escape, copied from template.HTMLEscape.
R=rsc CC=golang-dev
https://golang.org/cl/186282
parent
9f3738a4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
xml.go
src/pkg/xml/xml.go
+35
-0
No files found.
src/pkg/xml/xml.go
View file @
c90b05bf
...
@@ -1479,3 +1479,38 @@ var htmlAutoClose = []string{
...
@@ -1479,3 +1479,38 @@ var htmlAutoClose = []string{
"base"
,
"base"
,
"meta"
,
"meta"
,
}
}
var
(
esc_quot
=
strings
.
Bytes
(
"""
)
// shorter than """
esc_apos
=
strings
.
Bytes
(
"'"
)
// shorter than "'"
esc_amp
=
strings
.
Bytes
(
"&"
)
esc_lt
=
strings
.
Bytes
(
"<"
)
esc_gt
=
strings
.
Bytes
(
">"
)
)
// Escape writes to w the properly escaped XML equivalent
// of the plain text data s.
func
Escape
(
w
io
.
Writer
,
s
[]
byte
)
{
var
esc
[]
byte
last
:=
0
for
i
,
c
:=
range
s
{
switch
c
{
case
'"'
:
esc
=
esc_quot
case
'\'
'
:
esc
=
esc_apos
case
'&'
:
esc
=
esc_amp
case
'<'
:
esc
=
esc_lt
case
'>'
:
esc
=
esc_gt
default
:
continue
}
w
.
Write
(
s
[
last
:
i
])
w
.
Write
(
esc
)
last
=
i
+
1
}
w
.
Write
(
s
[
last
:
])
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment