diff --git a/Sources/FoundationEssentials/AttributedString/AttributedString.swift b/Sources/FoundationEssentials/AttributedString/AttributedString.swift index 1f871c647..4631c6820 100644 --- a/Sources/FoundationEssentials/AttributedString/AttributedString.swift +++ b/Sources/FoundationEssentials/AttributedString/AttributedString.swift @@ -400,3 +400,22 @@ extension Range where Bound == BigString.Index { Range(uncheckedBounds: (AttributedString.Index(lowerBound, version: version), AttributedString.Index(upperBound, version: version))) } } + +extension AttributedString { + /// Returns a boolean value indicating whether this string is identical to + /// `other`. + /// + /// Two string values are identical if there is no way to distinguish between + /// them. + /// + /// Comparing strings this way includes comparing (normally) hidden + /// implementation details such as the memory location of any underlying + /// string storage object. Therefore, identical strings are guaranteed to + /// compare equal with `==`, but not all equal strings are considered + /// identical. + /// + /// - Performance: O(1) + public func isIdentical(to other: Self) -> Bool { + self._guts === other._guts + } +} diff --git a/Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift b/Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift index 4191d9d46..df1313d8a 100644 --- a/Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift +++ b/Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift @@ -205,3 +205,23 @@ extension AttributedSubstring { } } } + +extension AttributedSubstring { + /// Returns a boolean value indicating whether this substring is identical to + /// `other`. + /// + /// Two substring values are identical if there is no way to distinguish + /// between them. + /// + /// Comparing substrings this way includes comparing (normally) hidden + /// implementation details such as the memory location of any underlying + /// substring storage object. Therefore, identical substrings are guaranteed + /// to compare equal with `==`, but not all equal substrings are considered + /// identical. + /// + /// - Performance: O(1) + public func isIdentical(to other: Self) -> Bool { + self._guts === other._guts && + self._range == other._range + } +}