module GraphQL::Language
Constants
- EFFICIENT_IGNORE_REGEXP
- EFFICIENT_NUMBER_REGEXP
-
Optimized pattern using: - Possessive quantifiers (*+, ++) to prevent backtracking in number patterns - Atomic group (?>…) for IGNORE to prevent backtracking - Single unified number pattern instead of three alternatives
- INVALID_NUMBER_FOLLOWED_BY_NAME_REGEXP
- LEADING_REGEX
- MAYBE_INVALID_NUMBER
Public Class Methods
# File lib/graphql/language.rb, line 111 def self.add_space_between_numbers_and_names(query_str) # Fast check for digit followed by identifier char. If this doesn't match, skip the more expensive regexp entirely. return query_str unless query_str.match?(MAYBE_INVALID_NUMBER) return query_str unless query_str.match?(INVALID_NUMBER_FOLLOWED_BY_NAME_REGEXP) query_str.gsub(INVALID_NUMBER_FOLLOWED_BY_NAME_REGEXP, "\\k<leading>\\k<num> \\k<name>:") end
# File lib/graphql/language.rb, line 53 def self.escape_single_quoted_newlines(query_str) scanner = StringScanner.new(query_str) inside_single_quoted_string = false #: bool inside_triple_quoted_string = false #: bool new_query_str = nil #: String? while !scanner.eos? if scanner.skip('"""') inside_triple_quoted_string = !inside_triple_quoted_string new_query_str && (new_query_str << scanner.matched) elsif scanner.skip(/(?:\\"|[^"\n\r])+/m) new_query_str && (new_query_str << scanner.matched) elsif scanner.skip('"') new_query_str && (new_query_str << '"') if !inside_triple_quoted_string inside_single_quoted_string = !inside_single_quoted_string end elsif scanner.skip("\n") if inside_single_quoted_string new_query_str ||= query_str[0, scanner.pos - 1] new_query_str << '\\n' else new_query_str && (new_query_str << "\n") end elsif scanner.skip("\r") if inside_single_quoted_string new_query_str ||= query_str[0, scanner.pos - 1] new_query_str << '\\r' else new_query_str && (new_query_str << "\r") end elsif scanner.eos? break else raise ArgumentError, "Unmatchable string scanner segment: #{scanner.rest.inspect}" end end new_query_str || query_str end
Returns a new string if any single-quoted newlines were escaped. Otherwise, returns query_str unchanged.
Returns
-
String