lib/regexp-examples/constants.rb in regexp-examples-1.3.1 vs lib/regexp-examples/constants.rb in regexp-examples-1.3.2
- old
+ new
@@ -19,43 +19,45 @@
# Maximum number of results to be generated, for Regexp#examples
# This is to prevent the system "freezing" when given instructions like:
# /[ab]{30}/.examples
# (Which would attempt to generate 2**30 == 1073741824 examples!!!)
- MAX_RESULTS_LIMIT_DEFAULT = 10000
+ MAX_RESULTS_LIMIT_DEFAULT = 10_000
class << self
attr_reader :max_repeater_variance, :max_group_results, :max_results_limit
- def configure!(max_repeater_variance: nil, max_group_results: nil, max_results_limit: nil)
+ def configure!(max_repeater_variance: nil,
+ max_group_results: nil,
+ max_results_limit: nil)
@max_repeater_variance = (max_repeater_variance || MAX_REPEATER_VARIANCE_DEFAULT)
@max_group_results = (max_group_results || MAX_GROUP_RESULTS_DEFAULT)
@max_results_limit = (max_results_limit || MAX_RESULTS_LIMIT_DEFAULT)
end
end
end
def self.max_repeater_variance
ResultCountLimiters.max_repeater_variance
end
+
def self.max_group_results
ResultCountLimiters.max_group_results
end
+
def self.max_results_limit
ResultCountLimiters.max_results_limit
end
# Definitions of various special characters, used in regular expressions.
# For example, `/\h/.examples` will return the value of `Hex` in this module
module CharSets
Lower = Array('a'..'z')
Upper = Array('A'..'Z')
Digit = Array('0'..'9')
- # Note: Punct should also include the following chars: $ + < = > ^ ` | ~
- # I.e. Punct = %w(! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \\ ] ^ _ ` { | } ~)
- # However, due to a ruby bug (!!) these do not work properly at the moment!
- Punct = %w(! " # % & ' ( ) * , - . / : ; ? @ [ \\ ] _ { })
+ Punct = %w[! " # % & ' ( ) * , - . / : ; ? @ [ \\ ] _ { }] \
+ | (RUBY_VERSION >= '2.4.0' ? %w[$ + < = > ^ ` | ~] : [])
Hex = Array('a'..'f') | Array('A'..'F') | Digit
Word = Lower | Upper | Digit | ['_']
- Whitespace = [' ', "\t", "\n", "\r", "\v", "\f"]
+ Whitespace = [' ', "\t", "\n", "\r", "\v", "\f"].freeze
Control = (0..31).map(&:chr) | ["\x7f"]
# Ensure that the "common" characters appear first in the array
# Also, ensure "\n" comes first, to make it obvious when included
Any = ["\n"] | Lower | Upper | Digit | Punct | (0..127).map(&:chr)
AnyNoNewLine = Any - ["\n"]