Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/net/imap/sequence_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ def full; FULL end
def initialize(input = nil) input ? replace(input) : clear end

# Removes all elements and returns self.
def clear; @tuples, @string = [], nil; self end
def clear
modifying! # redundant check, to normalize the error message for JRuby
@tuples, @string = [], nil
self
end

# Replace the contents of the set with the contents of +other+ and returns
# +self+.
Expand Down Expand Up @@ -439,11 +443,13 @@ def string=(str)
if str.nil?
clear
else
modifying! # redundant check, to normalize the error message for JRuby
str = String.try_convert(str) or raise ArgumentError, "not a string"
tuples = str_to_tuples str
@tuples, @string = [], -str
tuples_add tuples
end
str
end

# Returns the \IMAP +sequence-set+ string representation, or an empty
Expand Down Expand Up @@ -780,6 +786,7 @@ def ~; remain_frozen dup.complement! end
#
# Related: #add?, #merge, #union, #append
def add(element)
modifying! # short-circuit before input_to_tuple
tuple_add input_to_tuple element
normalize!
end
Expand All @@ -794,7 +801,7 @@ def add(element)
#
# Related: #add, #merge, #union
def append(entry)
modifying!
modifying! # short-circuit before input_to_tuple
tuple = input_to_tuple entry
entry = tuple_to_str tuple
string unless empty? # write @string before tuple_add
Expand All @@ -812,6 +819,7 @@ def append(entry)
#
# Related: #add, #merge, #union, #include?
def add?(element)
modifying! # short-circuit before include?
add element unless include? element
end

Expand All @@ -824,6 +832,7 @@ def add?(element)
#
# Related: #delete?, #delete_at, #subtract, #difference
def delete(element)
modifying! # short-circuit before input_to_tuple
tuple_subtract input_to_tuple element
normalize!
end
Expand Down Expand Up @@ -861,6 +870,7 @@ def delete(element)
#
# Related: #delete, #delete_at, #subtract, #difference, #disjoint?
def delete?(element)
modifying! # short-circuit before input_to_tuple
tuple = input_to_tuple element
if tuple.first == tuple.last
return unless include_tuple? tuple
Expand Down Expand Up @@ -901,6 +911,7 @@ def delete_at(index)
#
# Related: #slice, #delete_at, #delete, #delete?, #subtract, #difference
def slice!(index, length = nil)
modifying! # short-circuit before slice
deleted = slice(index, length) and subtract deleted
deleted
end
Expand All @@ -916,6 +927,7 @@ def slice!(index, length = nil)
#
# Related: #add, #add?, #union
def merge(*sets)
modifying! # short-circuit before input_to_tuples
tuples_add input_to_tuples sets
normalize!
end
Expand Down Expand Up @@ -1424,6 +1436,7 @@ def limit(max:)
#
# Related: #limit
def limit!(max:)
modifying! # short-circuit, and normalize the error message for JRuby
star = include_star?
max = to_tuple_int(max)
tuple_subtract [max + 1, STAR_INT]
Expand All @@ -1438,6 +1451,7 @@ def limit!(max:)
#
# Related: #complement
def complement!
modifying! # short-circuit, and normalize the error message for JRuby
return replace(self.class.full) if empty?
return clear if full?
flat = @tuples.flat_map { [_1 - 1, _2 + 1] }
Expand Down Expand Up @@ -1468,6 +1482,7 @@ def normalize
#
# Related: #normalize, #normalized_string
def normalize!
modifying! # redundant check, to normalize the error message for JRuby
@string = nil
self
end
Expand Down Expand Up @@ -1537,6 +1552,7 @@ def initialize_clone(other)
end

def initialize_dup(other)
modifying! # redundant check, to normalize the error message for JRuby
@tuples = other.tuples.map(&:dup)
@string = other.string&.-@
super
Expand Down
Loading