Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
c90b05bf
Commit
c90b05bf
authored
Jan 25, 2010
by
Stephen Weinberg
Committed by
Russ Cox
Jan 25, 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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
src/pkg/xml/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{
"base"
,
"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