Skip to content

Commit c5d8484

Browse files
committed
Make AnnotateChar equality consider annotations
This is needed for consistency with the view of equality we've adopted for AnnotatedStrings. By making AnnotateChar require annotations to be equal, we preserve the quality that two strings are equal if all their characters are equal.
1 parent 2e1235e commit c5d8484

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

base/strings/annotated.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,20 @@ cmp(a::AbstractString, b::AnnotatedString) = cmp(a, b.string)
197197
# To avoid method ambiguity
198198
cmp(a::AnnotatedString, b::AnnotatedString) = cmp(a.string, b.string)
199199

200+
# Annotated strings are equal if their strings and annotations are equal
200201
==(a::AnnotatedString, b::AnnotatedString) =
201202
a.string == b.string && a.annotations == b.annotations
202203

203204
==(a::AnnotatedString, b::AbstractString) = isempty(a.annotations) && a.string == b
204205
==(a::AbstractString, b::AnnotatedString) = isempty(b.annotations) && a == b.string
205206

207+
# Annotated chars are equal if their chars and annotations are equal
208+
==(a::AnnotatedChar, b::AnnotatedChar) =
209+
a.char == b.char && a.annotations == b.annotations
210+
211+
==(a::AnnotatedChar, b::AbstractChar) = isempty(a.annotations) && a.char == b
212+
==(a::AbstractChar, b::AnnotatedChar) = isempty(b.annotations) && a == b.char
213+
206214
# To prevent substring equality from hitting the generic fallback
207215

208216
function ==(a::SubString{<:AnnotatedString}, b::SubString{<:AnnotatedString})

0 commit comments

Comments
 (0)