mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Replace manual scan_quoted_string with regex capture groups\n\nResult: {"status":"keep","combined_µs":4102,"parse_µs":2849,"render_µs":1253,"allocations":25535}
This commit is contained in:
+7
-10
@@ -142,19 +142,16 @@ module Liquid
|
||||
end
|
||||
end
|
||||
|
||||
# Regex for quoted string content (without quotes)
|
||||
SINGLE_QUOTED_CONTENT = /'([^']*)'/
|
||||
DOUBLE_QUOTED_CONTENT = /"([^"]*)"/
|
||||
|
||||
# ── Strings ─────────────────────────────────────────────────────
|
||||
# Scan a quoted string ('...' or "..."). Returns the content without quotes, or nil.
|
||||
def scan_quoted_string
|
||||
b = @ss.peek_byte
|
||||
return unless b == QUOTE_S || b == QUOTE_D
|
||||
|
||||
quote = b
|
||||
@ss.scan_byte
|
||||
start = @ss.pos
|
||||
@ss.scan_byte while (b = @ss.peek_byte) && b != quote
|
||||
content = @source.byteslice(start, @ss.pos - start)
|
||||
@ss.scan_byte if @ss.peek_byte == quote # consume closing quote
|
||||
content
|
||||
if @ss.scan(SINGLE_QUOTED_CONTENT) || @ss.scan(DOUBLE_QUOTED_CONTENT)
|
||||
@ss[1]
|
||||
end
|
||||
end
|
||||
|
||||
# Regex for quoted strings (single or double quoted, including quotes)
|
||||
|
||||
Reference in New Issue
Block a user