Skip to content

Commit d50d7f3

Browse files
committed
PR Feedback.
* Rename QuoteLiteral -> quote_literal and move to after predicate_to_string. * Xpath -> XPath. * Replace %-substitution w/ String "#{...}".
1 parent b32affc commit d50d7f3

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

lib/rexml/parsers/xpathparser.rb

+16-13
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def predicate_to_string( path, &block )
178178
when :literal
179179
path.shift
180180
string << " "
181-
string << QuoteLiteral(path.shift)
181+
string << quote_literal(path.shift)
182182
string << " "
183183
else
184184
string << " "
@@ -188,6 +188,21 @@ def predicate_to_string( path, &block )
188188
return string.squeeze(" ")
189189
end
190190

191+
def quote_literal( literal )
192+
case literal
193+
when String
194+
# XPath 1.0 does not support escape characters.
195+
# Assumes literal does not contain both single and double quotes.
196+
if literal.include?("'")
197+
"\"#{literal}\""
198+
else
199+
"'#{literal}'"
200+
end
201+
else
202+
literal.inspect
203+
end
204+
end
205+
191206
private
192207
#LocationPath
193208
# | RelativeLocationPath
@@ -363,18 +378,6 @@ def Predicate path, parsed
363378
path
364379
end
365380

366-
def QuoteLiteral literal
367-
case literal
368-
when String
369-
# Xpath 1.0 does not support escape characters.
370-
# Assumes literal does not contain both single and double quotes.
371-
pattern = literal.include?('"') ? "'%s'" : '"%s"'
372-
pattern % literal
373-
else
374-
literal.inspect
375-
end
376-
end
377-
378381
# The following return arrays of true/false, a 1-1 mapping of the
379382
# supplied nodeset, except for axe(), which returns a filtered
380383
# nodeset

0 commit comments

Comments
 (0)