mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
use getbyte dispatch instead of start_with? in parse_for_document
This commit is contained in:
@@ -175,11 +175,17 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
OPEN_CURLEY_BYTE = 123 # '{'.ord
|
||||||
|
PERCENT_BYTE = 37 # '%'.ord
|
||||||
|
|
||||||
private def parse_for_document(tokenizer, parse_context, &block)
|
private def parse_for_document(tokenizer, parse_context, &block)
|
||||||
while (token = tokenizer.shift)
|
while (token = tokenizer.shift)
|
||||||
next if token.empty?
|
next if token.empty?
|
||||||
case
|
|
||||||
when token.start_with?(TAGSTART)
|
first_byte = token.getbyte(0)
|
||||||
|
if first_byte == OPEN_CURLEY_BYTE
|
||||||
|
second_byte = token.getbyte(1)
|
||||||
|
if second_byte == PERCENT_BYTE
|
||||||
whitespace_handler(token, parse_context)
|
whitespace_handler(token, parse_context)
|
||||||
parsed = BlockBody.parse_tag_token(token)
|
parsed = BlockBody.parse_tag_token(token)
|
||||||
unless parsed
|
unless parsed
|
||||||
@@ -206,10 +212,19 @@ module Liquid
|
|||||||
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
||||||
@blank &&= new_tag.blank?
|
@blank &&= new_tag.blank?
|
||||||
@nodelist << new_tag
|
@nodelist << new_tag
|
||||||
when token.start_with?(VARSTART)
|
elsif second_byte == OPEN_CURLEY_BYTE
|
||||||
whitespace_handler(token, parse_context)
|
whitespace_handler(token, parse_context)
|
||||||
@nodelist << create_variable(token, parse_context)
|
@nodelist << create_variable(token, parse_context)
|
||||||
@blank = false
|
@blank = false
|
||||||
|
else
|
||||||
|
# Fallback: text token starting with '{'
|
||||||
|
if parse_context.trim_whitespace
|
||||||
|
token.lstrip!
|
||||||
|
end
|
||||||
|
parse_context.trim_whitespace = false
|
||||||
|
@nodelist << token
|
||||||
|
@blank &&= token.match?(WhitespaceOrNothing)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if parse_context.trim_whitespace
|
if parse_context.trim_whitespace
|
||||||
token.lstrip!
|
token.lstrip!
|
||||||
|
|||||||
Reference in New Issue
Block a user