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
849fc19c
Commit
849fc19c
authored
Nov 30, 2011
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
html: clean up the z.rawTag calculation in the tokenizer.
R=andybalholm CC=golang-dev
https://golang.org/cl/5440064
parent
3b392277
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
9 deletions
+42
-9
src/pkg/html/token.go
src/pkg/html/token.go
+42
-9
No files found.
src/pkg/html/token.go
View file @
849fc19c
...
@@ -379,6 +379,28 @@ func (z *Tokenizer) readMarkupDeclaration() TokenType {
...
@@ -379,6 +379,28 @@ func (z *Tokenizer) readMarkupDeclaration() TokenType {
return
DoctypeToken
return
DoctypeToken
}
}
// startTagIn returns whether the start tag in z.buf[z.data.start:z.data.end]
// case-insensitively matches any element of ss.
func
(
z
*
Tokenizer
)
startTagIn
(
ss
...
string
)
bool
{
loop
:
for
_
,
s
:=
range
ss
{
if
z
.
data
.
end
-
z
.
data
.
start
!=
len
(
s
)
{
continue
loop
}
for
i
:=
0
;
i
<
len
(
s
);
i
++
{
c
:=
z
.
buf
[
z
.
data
.
start
+
i
]
if
'A'
<=
c
&&
c
<=
'Z'
{
c
+=
'a'
-
'A'
}
if
c
!=
s
[
i
]
{
continue
loop
}
}
return
true
}
return
false
}
// readStartTag reads the next start tag token. The opening "<a" has already
// readStartTag reads the next start tag token. The opening "<a" has already
// been consumed, where 'a' means anything in [A-Za-z].
// been consumed, where 'a' means anything in [A-Za-z].
func
(
z
*
Tokenizer
)
readStartTag
()
TokenType
{
func
(
z
*
Tokenizer
)
readStartTag
()
TokenType
{
...
@@ -406,15 +428,26 @@ func (z *Tokenizer) readStartTag() TokenType {
...
@@ -406,15 +428,26 @@ func (z *Tokenizer) readStartTag() TokenType {
}
}
}
}
// Several tags flag the tokenizer's next token as raw.
// Several tags flag the tokenizer's next token as raw.
// The tag name lengths of these special cases ranges in [3, 9].
c
,
raw
:=
z
.
buf
[
z
.
data
.
start
],
false
if
x
:=
z
.
data
.
end
-
z
.
data
.
start
;
3
<=
x
&&
x
<=
9
{
if
'A'
<=
c
&&
c
<=
'Z'
{
switch
z
.
buf
[
z
.
data
.
start
]
{
c
+=
'a'
-
'A'
case
'i'
,
'n'
,
'p'
,
's'
,
't'
,
'x'
,
'I'
,
'N'
,
'P'
,
'S'
,
'T'
,
'X'
:
}
switch
s
:=
strings
.
ToLower
(
string
(
z
.
buf
[
z
.
data
.
start
:
z
.
data
.
end
]));
s
{
switch
c
{
case
"iframe"
,
"noembed"
,
"noframes"
,
"noscript"
,
"plaintext"
,
"script"
,
"style"
,
"textarea"
,
"title"
,
"xmp"
:
case
'i'
:
z
.
rawTag
=
s
raw
=
z
.
startTagIn
(
"iframe"
)
}
case
'n'
:
}
raw
=
z
.
startTagIn
(
"noembed"
,
"noframes"
,
"noscript"
)
case
'p'
:
raw
=
z
.
startTagIn
(
"plaintext"
)
case
's'
:
raw
=
z
.
startTagIn
(
"script"
,
"style"
)
case
't'
:
raw
=
z
.
startTagIn
(
"textarea"
,
"title"
)
case
'x'
:
raw
=
z
.
startTagIn
(
"xmp"
)
}
if
raw
{
z
.
rawTag
=
strings
.
ToLower
(
string
(
z
.
buf
[
z
.
data
.
start
:
z
.
data
.
end
]))
}
}
// Look for a self-closing token like "<br/>".
// Look for a self-closing token like "<br/>".
if
z
.
err
==
nil
&&
z
.
buf
[
z
.
raw
.
end
-
2
]
==
'/'
{
if
z
.
err
==
nil
&&
z
.
buf
[
z
.
raw
.
end
-
2
]
==
'/'
{
...
...
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