Skip to content

Commit e0331c0

Browse files
committed
string identical
1 parent 5cf1d36 commit e0331c0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Sources/FoundationEssentials/AttributedString/AttributedString.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,22 @@ extension Range where Bound == BigString.Index {
403403
Range<AttributedString.Index>(uncheckedBounds: (AttributedString.Index(lowerBound, version: version), AttributedString.Index(upperBound, version: version)))
404404
}
405405
}
406+
407+
extension AttributedString {
408+
/// Returns a boolean value indicating whether this string is identical to
409+
/// `other`.
410+
///
411+
/// Two string values are identical if there is no way to distinguish between
412+
/// them.
413+
///
414+
/// Comparing strings this way includes comparing (normally) hidden
415+
/// implementation details such as the memory location of any underlying
416+
/// string storage object. Therefore, identical strings are guaranteed to
417+
/// compare equal with `==`, but not all equal strings are considered
418+
/// identical.
419+
///
420+
/// - Performance: O(1)
421+
public func isIdentical(to other: Self) -> Bool {
422+
self._guts === other._guts
423+
}
424+
}

Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,23 @@ extension AttributedSubstring {
205205
}
206206
}
207207
}
208+
209+
extension AttributedSubstring {
210+
/// Returns a boolean value indicating whether this substring is identical to
211+
/// `other`.
212+
///
213+
/// Two substring values are identical if there is no way to distinguish
214+
/// between them.
215+
///
216+
/// Comparing substrings this way includes comparing (normally) hidden
217+
/// implementation details such as the memory location of any underlying
218+
/// substring storage object. Therefore, identical substrings are guaranteed
219+
/// to compare equal with `==`, but not all equal substrings are considered
220+
/// identical.
221+
///
222+
/// - Performance: O(1)
223+
public func isIdentical(to other: Self) -> Bool {
224+
self._guts === other._guts &&
225+
self._range == other._range
226+
}
227+
}

0 commit comments

Comments
 (0)