summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-08-15 23:30:50 +0700
committerShulhan <ms@kilabit.info>2024-08-16 00:30:49 +0700
commite9b1dce76d78e6b26afa57de7469bf262a53790f (patch)
tree4f1fd05e6300bc417e4b078438b928c70bbea61b
parent836385a4ad7bc9a914c9a8544901518f0a64f2ed (diff)
downloadasciidoctor-go-e9b1dce76d78e6b26afa57de7469bf262a53790f.tar.xz
all: remove unnecessary TrimRight
Each lines to be parsed has been trimmed on the first load, so there is no need to do it again, on some cases.
-rw-r--r--document_parser.go11
-rw-r--r--element.go7
2 files changed, 6 insertions, 12 deletions
diff --git a/document_parser.go b/document_parser.go
index 96c37db..3a0a2f8 100644
--- a/document_parser.go
+++ b/document_parser.go
@@ -601,7 +601,7 @@ func (docp *documentParser) parseBlock(parent *element, term int) {
continue
case elKindBlockImage:
- var lineImage = bytes.TrimRight(line[7:], " \t")
+ var lineImage = line[7:]
if el.parseBlockImage(docp.doc, lineImage) {
el.kind = docp.kind
line = nil
@@ -1606,8 +1606,6 @@ func (docp *documentParser) skipCommentAndEmptyLine() (line []byte, ok bool) {
func (docp *documentParser) whatKindOfLine(line []byte) (spaces, got []byte) {
docp.kind = lineKindText
- line = bytes.TrimRight(line, " \f\n\r\t\v")
-
// All of the comparison MUST be in order.
if len(line) == 0 {
@@ -1725,16 +1723,15 @@ func (docp *documentParser) whatKindOfLine(line []byte) (spaces, got []byte) {
docp.kind = lineKindAttribute
case '[':
var (
- newline = bytes.TrimRight(line, " \t")
- l = len(newline)
+ l = len(line)
)
- if newline[l-1] != ']' {
+ if line[l-1] != ']' {
return nil, line
}
if l >= 5 {
// [[x]]
- if newline[1] == '[' && newline[l-2] == ']' {
+ if line[1] == '[' && line[l-2] == ']' {
docp.kind = lineKindID
return nil, line
}
diff --git a/element.go b/element.go
index bdda706..8cd311c 100644
--- a/element.go
+++ b/element.go
@@ -276,7 +276,7 @@ func (el *element) lastSuccessor() (last *element) {
}
func (el *element) parseBlockAudio(doc *Document, line []byte) bool {
- line = bytes.TrimRight(line[7:], " \t")
+ line = line[7:]
var attrBegin = bytes.IndexByte(line, '[')
if attrBegin < 0 {
@@ -620,7 +620,7 @@ func (el *element) parseStyleClass(line []byte) {
}
func (el *element) parseBlockVideo(doc *Document, line []byte) bool {
- line = bytes.TrimRight(line[7:], " \t")
+ line = line[7:]
var (
attrBegin = bytes.IndexByte(line, '[')
@@ -783,9 +783,6 @@ func (el *element) removeLastIfEmpty() {
}
if c.prev != nil {
c.prev.next = nil
- if c.prev.kind == elKindText {
- el.raw = bytes.TrimRight(el.raw, " \t")
- }
} else if c.parent != nil {
c.parent.child = nil
}