xqsr3 0.39.1 → 0.39.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/count_word_frequencies.rb +2 -0
- data/lib/xqsr3/array_utilities/join_with_or.rb +50 -53
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +66 -69
- data/lib/xqsr3/containers/frequency_map.rb +408 -394
- data/lib/xqsr3/containers/multi_map.rb +464 -446
- data/lib/xqsr3/conversion/bool_parser.rb +49 -54
- data/lib/xqsr3/conversion/integer_parser.rb +84 -89
- data/lib/xqsr3/diagnostics/exception_utilities.rb +127 -132
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +98 -102
- data/lib/xqsr3/diagnostics/inspect_builder.rb +83 -84
- data/lib/xqsr3/extensions/array/join_with_or.rb +2 -1
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +1 -4
- data/lib/xqsr3/extensions/enumerable/unique.rb +1 -4
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -0
- data/lib/xqsr3/extensions/hash/except.rb +1 -1
- data/lib/xqsr3/extensions/hash/has_match.rb +3 -2
- data/lib/xqsr3/extensions/hash/match.rb +3 -2
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +1 -4
- data/lib/xqsr3/extensions/io/writelines.rb +4 -7
- data/lib/xqsr3/extensions/kernel/integer.rb +7 -9
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +1 -3
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -0
- data/lib/xqsr3/extensions/string/map_option_string.rb +1 -0
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -0
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -0
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -0
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -0
- data/lib/xqsr3/extensions/string/to_bool.rb +1 -0
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -0
- data/lib/xqsr3/extensions/string/truncate.rb +1 -0
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +58 -55
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +11 -9
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +10 -8
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -37
- data/lib/xqsr3/hash_utilities/deep_transform.rb +63 -67
- data/lib/xqsr3/hash_utilities/key_matching.rb +72 -76
- data/lib/xqsr3/internal_/test_unit_version_.rb +10 -8
- data/lib/xqsr3/io/writelines.rb +12 -12
- data/lib/xqsr3/quality/parameter_checking.rb +406 -411
- data/lib/xqsr3/string_utilities/ends_with.rb +60 -64
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +31 -35
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +32 -36
- data/lib/xqsr3/string_utilities/quote_if.rb +48 -57
- data/lib/xqsr3/string_utilities/starts_with.rb +60 -64
- data/lib/xqsr3/string_utilities/to_symbol.rb +77 -81
- data/lib/xqsr3/string_utilities/truncate.rb +56 -60
- data/lib/xqsr3/version.rb +2 -2
- data/test/performance/frequency_map.rb +3 -0
- data/test/scratch/test_assert_raise_with_message.rb +2 -0
- data/test/unit/array_utilities/tc_join_with_or.rb +3 -1
- data/test/unit/command_line_utilities/tc_map_option_string.rb +3 -0
- data/test/unit/containers/tc_frequency_map.rb +5 -2
- data/test/unit/containers/tc_multi_map.rb +3 -0
- data/test/unit/conversion/tc_integer_parser.rb +18 -17
- data/test/unit/conversion/tc_to_bool.rb +2 -0
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +7 -5
- data/test/unit/diagnostics/tc_exception_utilities.rb +2 -0
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +2 -0
- data/test/unit/extensions/enumerable/tc_detect_map.rb +3 -2
- data/test/unit/extensions/enumerable/tc_unique.rb +2 -0
- data/test/unit/extensions/hash/tc_deep_transform.rb +2 -0
- data/test/unit/extensions/hash/tc_except.rb +3 -1
- data/test/unit/extensions/hash/tc_hash.rb +1 -0
- data/test/unit/extensions/hash/tc_slice.rb +2 -0
- data/test/unit/extensions/integer/tc_to_s_grp.rb +2 -0
- data/test/unit/extensions/io/tc_writelines.rb +86 -0
- data/test/unit/extensions/kernel/tc_integer.rb +10 -9
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +2 -0
- data/test/unit/extensions/object/tc_inspect.rb +15 -13
- data/test/unit/extensions/string/tc_bool.tb +2 -0
- data/test/unit/extensions/string/tc_ends_with.rb +2 -0
- data/test/unit/extensions/string/tc_map_option_string.rb +2 -0
- data/test/unit/extensions/string/tc_nil_if_empty.rb +2 -0
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +2 -0
- data/test/unit/extensions/string/tc_quote_if.rb +2 -0
- data/test/unit/extensions/string/tc_starts_with.rb +2 -0
- data/test/unit/extensions/string/tc_to_symbol.rb +2 -0
- data/test/unit/extensions/string/tc_truncate.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +2 -0
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +2 -0
- data/test/unit/hash_utilities/tc_has_match.rb +1 -0
- data/test/unit/hash_utilities/tc_match.rb +1 -0
- data/test/unit/io/tc_writelines.rb +63 -0
- data/test/unit/quality/tc_parameter_checking.rb +1 -0
- data/test/unit/string_utilities/tc_truncate.rb +2 -0
- data/test/unit/tc_version.rb +2 -0
- metadata +3 -3
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Definition of the ::Xqsr3::StringUtilities::EndsWith module
|
6
6
|
#
|
7
7
|
# Created: 13th April 2016
|
8
|
-
# Updated:
|
8
|
+
# Updated: 12th April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -45,99 +45,95 @@
|
|
45
45
|
# ######################################################################## #
|
46
46
|
|
47
47
|
|
48
|
-
# ##########################################################
|
49
|
-
# ::Xqsr3::StringUtilities::EndsWith
|
50
|
-
|
51
48
|
=begin
|
52
49
|
=end
|
53
50
|
|
54
51
|
module Xqsr3
|
55
52
|
module StringUtilities
|
56
53
|
|
57
|
-
# +include+-able module that provides ::string_ends_with? and #ends_with?
|
58
|
-
# methods
|
59
|
-
module EndsWith
|
54
|
+
# +include+-able module that provides ::string_ends_with? and #ends_with?
|
55
|
+
# methods
|
56
|
+
module EndsWith
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
private
|
59
|
+
# @!visibility private
|
60
|
+
module EndsWith_Helper_ # :nodoc: all
|
64
61
|
|
65
|
-
|
62
|
+
def self.string_ends_with_helper_ s, prefix # :nodoc:
|
66
63
|
|
67
|
-
|
64
|
+
if prefix.nil? || prefix.empty?
|
68
65
|
|
69
|
-
|
70
|
-
|
66
|
+
return ''
|
67
|
+
elsif prefix.size < s.size
|
71
68
|
|
72
|
-
|
73
|
-
|
69
|
+
return prefix if s[(s.size - prefix.size) ... s.size] == prefix
|
70
|
+
elsif prefix.size == s.size
|
74
71
|
|
75
|
-
|
76
|
-
|
72
|
+
return prefix if prefix == s
|
73
|
+
else
|
74
|
+
|
75
|
+
nil
|
76
|
+
end
|
77
77
|
|
78
78
|
nil
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
|
-
end
|
81
|
+
def self.string_ends_with_array_ s, args # :nodoc:
|
83
82
|
|
84
|
-
|
83
|
+
return '' if args.empty?
|
85
84
|
|
86
|
-
|
85
|
+
args.each do |prefix|
|
87
86
|
|
88
|
-
|
87
|
+
case prefix
|
88
|
+
when ::NilClass
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
return ''
|
91
|
+
when ::String
|
92
92
|
|
93
|
-
|
94
|
-
when ::String
|
93
|
+
r = self.string_ends_with_helper_ s, prefix
|
95
94
|
|
96
|
-
|
95
|
+
return r if r
|
96
|
+
else
|
97
97
|
|
98
|
-
|
99
|
-
else
|
98
|
+
if prefix.respond_to? :to_str
|
100
99
|
|
101
|
-
|
100
|
+
return self.string_ends_with_helper_ s.prefix.to_str
|
101
|
+
end
|
102
102
|
|
103
|
-
|
103
|
+
raise TypeError, "ends_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
|
104
104
|
end
|
105
|
-
|
106
|
-
raise TypeError, "ends_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
|
107
105
|
end
|
108
|
-
end
|
109
106
|
|
110
|
-
|
107
|
+
return nil
|
108
|
+
end
|
111
109
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
def ends_with? *args
|
136
|
-
|
137
|
-
EndsWith_Helper_.string_ends_with_array_ self, args
|
138
|
-
end
|
139
|
-
end # module EndsWith
|
110
|
+
public
|
111
|
+
|
112
|
+
# Reports on whether a string +s+ ends with a given prefix or set of
|
113
|
+
# prefixes (+args+)
|
114
|
+
#
|
115
|
+
# === Signature
|
116
|
+
#
|
117
|
+
# * *Parameters:*
|
118
|
+
# - +s+ (+String+) The string to be evaluated;
|
119
|
+
# - +args+ 0+ arguments against which +s+ will be evaluated;
|
120
|
+
def self.string_ends_with? s, *args
|
121
|
+
|
122
|
+
EndsWith_Helper_.string_ends_with_array_ s, args
|
123
|
+
end
|
124
|
+
|
125
|
+
# Reports on whether the instance ends with a given prefix or set of
|
126
|
+
# prefixes (+args+)
|
127
|
+
#
|
128
|
+
# === Signature
|
129
|
+
#
|
130
|
+
# * *Parameters:*
|
131
|
+
# - +args+ 0+ arguments against which the instance will be evaluated
|
132
|
+
def ends_with? *args
|
140
133
|
|
134
|
+
EndsWith_Helper_.string_ends_with_array_ self, args
|
135
|
+
end
|
136
|
+
end # module EndsWith
|
141
137
|
end # module StringUtilities
|
142
138
|
end # module Xqsr3
|
143
139
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Definition of the ::Xqsr3::StringUtilities::NilIfEmpty module
|
6
6
|
#
|
7
7
|
# Created: 25th January 2018
|
8
|
-
# Updated:
|
8
|
+
# Updated: 12th April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -45,53 +45,49 @@
|
|
45
45
|
# ######################################################################## #
|
46
46
|
|
47
47
|
|
48
|
-
# ##########################################################
|
49
|
-
# ::Xqsr3::StringUtilities::NilIfEmpty
|
50
|
-
|
51
48
|
=begin
|
52
49
|
=end
|
53
50
|
|
54
51
|
module Xqsr3
|
55
52
|
module StringUtilities
|
56
53
|
|
57
|
-
# +include+-able module that provides ::string_nil_if_empty and
|
58
|
-
# #nil_if_empty methods
|
59
|
-
module NilIfEmpty
|
54
|
+
# +include+-able module that provides ::string_nil_if_empty and
|
55
|
+
# #nil_if_empty methods
|
56
|
+
module NilIfEmpty
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
private
|
59
|
+
# @!visibility private
|
60
|
+
module NilIfEmpty_Helper_ # :nodoc: all
|
64
61
|
|
65
|
-
|
62
|
+
def self.string_nil_if_empty_array_ s # :nodoc:
|
66
63
|
|
67
|
-
|
64
|
+
return s if s && !s.empty?
|
68
65
|
|
69
|
-
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
public
|
70
|
+
|
71
|
+
# Returns +nil+ if the given string is empty, otherwise returning the
|
72
|
+
# given string
|
73
|
+
#
|
74
|
+
# === Signature
|
75
|
+
#
|
76
|
+
# * *Parameters:*
|
77
|
+
#
|
78
|
+
# * *Required parameters*:
|
79
|
+
# - +s+ (+String+) The string to be evaluated;
|
80
|
+
def self.string_nil_if_empty s
|
81
|
+
|
82
|
+
NilIfEmpty_Helper_.string_nil_if_empty_array_ s
|
70
83
|
end
|
71
|
-
end
|
72
|
-
public
|
73
|
-
|
74
|
-
# Returns +nil+ if the given string is empty, otherwise returning the
|
75
|
-
# given string
|
76
|
-
#
|
77
|
-
# === Signature
|
78
|
-
#
|
79
|
-
# * *Parameters:*
|
80
|
-
#
|
81
|
-
# * *Required parameters*:
|
82
|
-
# - +s+ (String) The string to be evaluated
|
83
|
-
def self.string_nil_if_empty s
|
84
|
-
|
85
|
-
NilIfEmpty_Helper_.string_nil_if_empty_array_ s
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns +nil+ if the instance is empty, otherwise returning self
|
89
|
-
def nil_if_empty
|
90
84
|
|
91
|
-
|
92
|
-
|
93
|
-
end # module NilIfEmpty
|
85
|
+
# Returns +nil+ if the instance is empty, otherwise returning self
|
86
|
+
def nil_if_empty
|
94
87
|
|
88
|
+
NilIfEmpty_Helper_.string_nil_if_empty_array_ self
|
89
|
+
end
|
90
|
+
end # module NilIfEmpty
|
95
91
|
end # module StringUtilities
|
96
92
|
end # module Xqsr3
|
97
93
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# module
|
7
7
|
#
|
8
8
|
# Created: 25th January 2018
|
9
|
-
# Updated:
|
9
|
+
# Updated: 12th April 2024
|
10
10
|
#
|
11
11
|
# Home: http://github.com/synesissoftware/xqsr3
|
12
12
|
#
|
@@ -46,54 +46,50 @@
|
|
46
46
|
# ######################################################################## #
|
47
47
|
|
48
48
|
|
49
|
-
# ##########################################################
|
50
|
-
# ::Xqsr3::StringUtilities::NilIfWhitespace
|
51
|
-
|
52
49
|
=begin
|
53
50
|
=end
|
54
51
|
|
55
52
|
module Xqsr3
|
56
53
|
module StringUtilities
|
57
54
|
|
58
|
-
# +include+-able module that provides ::string_nil_if_whitespace and
|
59
|
-
# #nil_if_whitespace methods
|
60
|
-
module NilIfWhitespace
|
55
|
+
# +include+-able module that provides ::string_nil_if_whitespace and
|
56
|
+
# #nil_if_whitespace methods
|
57
|
+
module NilIfWhitespace
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
private
|
60
|
+
# @!visibility private
|
61
|
+
module NilIfWhitespace_Helper_ # :nodoc: all
|
65
62
|
|
66
|
-
|
63
|
+
def self.string_nil_if_whitespace_array_ s # :nodoc:
|
67
64
|
|
68
|
-
|
65
|
+
return nil if s.strip.empty?
|
69
66
|
|
70
|
-
|
67
|
+
s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
public
|
71
|
+
|
72
|
+
# Returns +nil+ if the given string is empty or contains only whitespace,
|
73
|
+
# otherwise returning the given string
|
74
|
+
#
|
75
|
+
# === Signature
|
76
|
+
#
|
77
|
+
# * *Parameters:*
|
78
|
+
#
|
79
|
+
# * *Required parameters*:
|
80
|
+
# - +s+ (+String+) The string to be evaluated;
|
81
|
+
def self.string_nil_if_whitespace s
|
82
|
+
|
83
|
+
NilIfWhitespace_Helper_.string_nil_if_whitespace_array_ s
|
71
84
|
end
|
72
|
-
end
|
73
|
-
public
|
74
|
-
|
75
|
-
# Returns +nil+ if the given string is empty or contains only whitespace,
|
76
|
-
# otherwise returning the given string
|
77
|
-
#
|
78
|
-
# === Signature
|
79
|
-
#
|
80
|
-
# * *Parameters:*
|
81
|
-
#
|
82
|
-
# * *Required parameters*:
|
83
|
-
# - +s+ (String) The string to be evaluated
|
84
|
-
def self.string_nil_if_whitespace s
|
85
|
-
|
86
|
-
NilIfWhitespace_Helper_.string_nil_if_whitespace_array_ s
|
87
|
-
end
|
88
|
-
|
89
|
-
# Returns +nil+ if the instance is empty or contains only whitespace,
|
90
|
-
# otherwise returning self
|
91
|
-
def nil_if_whitespace
|
92
85
|
|
93
|
-
|
94
|
-
|
95
|
-
|
86
|
+
# Returns +nil+ if the instance is empty or contains only whitespace,
|
87
|
+
# otherwise returning self
|
88
|
+
def nil_if_whitespace
|
96
89
|
|
90
|
+
NilIfWhitespace_Helper_.string_nil_if_whitespace_array_ self
|
91
|
+
end
|
92
|
+
end # module NilIfWhitespace
|
97
93
|
end # module StringUtilities
|
98
94
|
end # module Xqsr3
|
99
95
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Definition of the ::Xqsr3::StringUtilities::QuoteIf module
|
6
6
|
#
|
7
7
|
# Created: 3rd June 2017
|
8
|
-
# Updated:
|
8
|
+
# Updated: 12th April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -45,81 +45,72 @@
|
|
45
45
|
# ######################################################################## #
|
46
46
|
|
47
47
|
|
48
|
-
# ##########################################################
|
49
|
-
# ::Xqsr3::StringUtilities::QuoteIf
|
50
|
-
|
51
48
|
=begin
|
52
49
|
=end
|
53
50
|
|
54
51
|
module Xqsr3
|
55
52
|
module StringUtilities
|
56
53
|
|
57
|
-
# +include+-able module that provides ::quote_if and #quote_if methods
|
58
|
-
module QuoteIf
|
54
|
+
# +include+-able module that provides ::quote_if and #quote_if methods
|
55
|
+
module QuoteIf
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
private
|
58
|
+
# @!visibility private
|
59
|
+
module QuoteIf_Helper_ # :nodoc: all
|
63
60
|
|
64
|
-
|
61
|
+
def self.string_quote_if_array_ s, options # :nodoc:
|
65
62
|
|
66
|
-
|
63
|
+
s = s.to_s unless String === s
|
67
64
|
|
68
|
-
|
69
|
-
|
65
|
+
quotes = options[:quotes] || [ '"', '"' ]
|
66
|
+
quotes = [ quotes, quotes ] if String === quotes
|
70
67
|
|
71
|
-
|
68
|
+
quotables = options[:quotables] || /\s/
|
72
69
|
|
73
|
-
|
74
|
-
|
70
|
+
case quotables
|
71
|
+
when ::String
|
75
72
|
|
76
|
-
|
77
|
-
|
73
|
+
return s unless s.include? quotables
|
74
|
+
when ::Array
|
78
75
|
|
79
|
-
|
80
|
-
|
76
|
+
return s unless quotables.any? { |quotable| s.include? quotable }
|
77
|
+
when ::Regexp
|
81
78
|
|
82
|
-
|
83
|
-
|
79
|
+
return s unless s =~ quotables
|
80
|
+
else
|
84
81
|
|
85
|
-
|
86
|
-
|
82
|
+
raise ArgumentError, "Invalid type (#{quotables.class}) specified for quotables parameter"
|
83
|
+
end
|
87
84
|
|
88
|
-
|
85
|
+
return quotes[0] + s + quotes[1]
|
86
|
+
end
|
89
87
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
# Converts the instance to a quoted form if necessary
|
115
|
-
#
|
116
|
-
# See Xqsr3::StringUtilities::QuoteIf::quite_if() for options
|
117
|
-
def quote_if **options
|
118
|
-
|
119
|
-
QuoteIf_Helper_.string_quote_if_array_ self, options
|
120
|
-
end
|
121
|
-
end # module QuoteIf
|
88
|
+
public
|
89
|
+
|
90
|
+
# Converts a string to a quoted form if necessary
|
91
|
+
#
|
92
|
+
# === Signature
|
93
|
+
#
|
94
|
+
# * *Parameters:*
|
95
|
+
# - +s+ (+String+) The string to be evaluated;
|
96
|
+
# - +options+ (+Hash+) Options that control the behaviour of the method;
|
97
|
+
#
|
98
|
+
# * *Options:*
|
99
|
+
# - +:quotes+ (+String+, +Array+) A string that is used as the opening and closing quotes, or an array whose first two elements are used as the opening and closing quotes. Defaults to +'"'+
|
100
|
+
# - +:quotables+ (+String+, +Array+, +Regexp+) A string representing the quotable character, or an array containing the quotable characters, or a regular expression that determines by match whether the string should be quoted. Defaults to the regular expression +/\s/+
|
101
|
+
def self.quote_if s, **options
|
102
|
+
|
103
|
+
QuoteIf_Helper_.string_quote_if_array_ s, options
|
104
|
+
end
|
105
|
+
|
106
|
+
# Converts the instance to a quoted form if necessary
|
107
|
+
#
|
108
|
+
# See Xqsr3::StringUtilities::QuoteIf::quite_if() for options
|
109
|
+
def quote_if **options
|
122
110
|
|
111
|
+
QuoteIf_Helper_.string_quote_if_array_ self, options
|
112
|
+
end
|
113
|
+
end # module QuoteIf
|
123
114
|
end # module StringUtilities
|
124
115
|
end # module Xqsr3
|
125
116
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Definition of the ::Xqsr3::StringUtilities::StartsWith module
|
6
6
|
#
|
7
7
|
# Created: 13th April 2016
|
8
|
-
# Updated:
|
8
|
+
# Updated: 12th April 2024
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/xqsr3
|
11
11
|
#
|
@@ -45,99 +45,95 @@
|
|
45
45
|
# ######################################################################## #
|
46
46
|
|
47
47
|
|
48
|
-
# ##########################################################
|
49
|
-
# ::Xqsr3::StringUtilities::StartsWith
|
50
|
-
|
51
48
|
=begin
|
52
49
|
=end
|
53
50
|
|
54
51
|
module Xqsr3
|
55
52
|
module StringUtilities
|
56
53
|
|
57
|
-
# +include+-able module that provides ::string_starts_with? and #starts_with?
|
58
|
-
# methods
|
59
|
-
module StartsWith
|
54
|
+
# +include+-able module that provides ::string_starts_with? and #starts_with?
|
55
|
+
# methods
|
56
|
+
module StartsWith
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
private
|
59
|
+
# @!visibility private
|
60
|
+
module StartsWith_Helper_ # :nodoc: all
|
64
61
|
|
65
|
-
|
62
|
+
def self.string_starts_with_helper_ s, prefix # :nodoc:
|
66
63
|
|
67
|
-
|
64
|
+
if prefix.nil? || prefix.empty?
|
68
65
|
|
69
|
-
|
70
|
-
|
66
|
+
return ''
|
67
|
+
elsif prefix.size < s.size
|
71
68
|
|
72
|
-
|
73
|
-
|
69
|
+
return prefix if s[0 ... prefix.size] == prefix
|
70
|
+
elsif prefix.size == s.size
|
74
71
|
|
75
|
-
|
76
|
-
|
72
|
+
return prefix if prefix == s
|
73
|
+
else
|
74
|
+
|
75
|
+
nil
|
76
|
+
end
|
77
77
|
|
78
78
|
nil
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
|
-
end
|
81
|
+
def self.string_starts_with_array_ s, args # :nodoc:
|
83
82
|
|
84
|
-
|
83
|
+
return '' if args.empty?
|
85
84
|
|
86
|
-
|
85
|
+
args.each do |prefix|
|
87
86
|
|
88
|
-
|
87
|
+
case prefix
|
88
|
+
when ::NilClass
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
return ''
|
91
|
+
when ::String
|
92
92
|
|
93
|
-
|
94
|
-
when ::String
|
93
|
+
r = self.string_starts_with_helper_ s, prefix
|
95
94
|
|
96
|
-
|
95
|
+
return r if r
|
96
|
+
else
|
97
97
|
|
98
|
-
|
99
|
-
else
|
98
|
+
if prefix.respond_to? :to_str
|
100
99
|
|
101
|
-
|
100
|
+
return self.string_starts_with_helper_ s.prefix.to_str
|
101
|
+
end
|
102
102
|
|
103
|
-
|
103
|
+
raise TypeError, "starts_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
|
104
104
|
end
|
105
|
-
|
106
|
-
raise TypeError, "starts_with? can be passed instances of #{::String}, or nil, or types that respond to to_str"
|
107
105
|
end
|
108
|
-
end
|
109
106
|
|
110
|
-
|
107
|
+
return nil
|
108
|
+
end
|
111
109
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
def starts_with? *args
|
136
|
-
|
137
|
-
StartsWith_Helper_.string_starts_with_array_ self, args
|
138
|
-
end
|
139
|
-
end # module StartsWith
|
110
|
+
public
|
111
|
+
|
112
|
+
# Reports on whether a string +s+ starts with a given prefix or set of
|
113
|
+
# prefixes (+args+)
|
114
|
+
#
|
115
|
+
# === Signature
|
116
|
+
#
|
117
|
+
# * *Parameters:*
|
118
|
+
# - +s+ (+String+) The string to be evaluated;
|
119
|
+
# - +args+ 0+ arguments against which +s+ will be evaluated;
|
120
|
+
def self.string_starts_with? s, *args
|
121
|
+
|
122
|
+
StartsWith_Helper_.string_starts_with_array_ s, args
|
123
|
+
end
|
124
|
+
|
125
|
+
# Reports on whether the instance starts with a given prefix or set of
|
126
|
+
# prefixes (+args+)
|
127
|
+
#
|
128
|
+
# === Signature
|
129
|
+
#
|
130
|
+
# * *Parameters:*
|
131
|
+
# - +args+ 0+ arguments against which the instance will be evaluated;
|
132
|
+
def starts_with? *args
|
140
133
|
|
134
|
+
StartsWith_Helper_.string_starts_with_array_ self, args
|
135
|
+
end
|
136
|
+
end # module StartsWith
|
141
137
|
end # module StringUtilities
|
142
138
|
end # module Xqsr3
|
143
139
|
|