Skip to content

Commit d91d8da

Browse files
committed
[stdlib] String.Index: conform to CustomDebugStringConvertible instead
Apply the LSG’s modifications as detailed in their review notes.
1 parent 28ed16b commit d91d8da

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

stdlib/public/core/StringIndex.swift

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -524,53 +524,43 @@ extension String.Index {
524524
}
525525
}
526526

527-
/// A textual representation of this instance.
527+
/// A textual representation of this instance, intended for debugging.
528528
///
529529
/// - Important: The contents of the returned string are not guaranteed to
530530
/// remain stable: they may arbitrarily change in any Swift release.
531531
@_alwaysEmitIntoClient // FIXME: Use @backDeployed
532532
@inline(never)
533-
public var description: String {
533+
public var debugDescription: String {
534534
// 23[utf8]+1
535535
var d = "\(_encodedOffset)[\(_encodingDescription)]"
536536
if transcodedOffset != 0 {
537537
d += "+\(transcodedOffset)"
538538
}
539539
return d
540540
}
541+
}
542+
543+
@available(SwiftStdlib 6.1, *)
544+
extension String.Index: CustomDebugStringConvertible {}
541545

542-
/// A textual representation of this instance.
546+
extension String.Index {
547+
/// A textual representation of this instance, intended for debugging.
548+
///
549+
/// - Important: The contents of the returned string are not guaranteed to
550+
/// remain stable: they may arbitrarily change in any Swift release.
543551
@_alwaysEmitIntoClient
544-
@available(*, deprecated, renamed: "description")
552+
@available(*, deprecated, renamed: "debugDescription")
545553
public var _description: String {
546554
description
547555
}
548-
}
549556

550-
@available(SwiftStdlib 6.1, *)
551-
extension String.Index: CustomStringConvertible {}
552-
553-
extension String.Index {
554-
/// A more detailed description of this string index.
557+
/// A textual representation of this instance, intended for debugging.
558+
///
559+
/// - Important: The contents of the returned string are not guaranteed to
560+
/// remain stable: they may arbitrarily change in any Swift release.
555561
@_alwaysEmitIntoClient
556-
@inline(never)
562+
@available(*, deprecated, renamed: "debugDescription")
557563
public var _debugDescription: String {
558-
/// Note: This would not make a good `debugDescription`; the current
559-
/// `description` is fine for that.
560-
var d = "String.Index("
561-
d += "offset: \(_encodedOffset)[\(_encodingDescription)]"
562-
if transcodedOffset != 0 {
563-
d += "+\(transcodedOffset)"
564-
}
565-
if _isCharacterAligned {
566-
d += ", aligned: character"
567-
} else if _isScalarAligned {
568-
d += ", aligned: scalar"
569-
}
570-
if let stride = characterStride {
571-
d += ", stride: \(stride)"
572-
}
573-
d += ")"
574-
return d
564+
debugDescription
575565
}
576566
}

test/stdlib/StringIndex.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,11 @@ if #available(SwiftStdlib 6.1, *) {
12401240
}
12411241
}
12421242

1243-
suite.test("String index description backdeployment") {
1243+
suite.test("String index debugDescription backdeployment") {
12441244
// Note: no availability check
12451245
let str = "i\u{308}"
1246-
expectEqual(str.startIndex.description, "0[any]")
1247-
expectEqual(str.endIndex.description, "3[utf8]")
1246+
expectEqual(str.startIndex.debugDescription, "0[any]")
1247+
expectEqual(str.endIndex.debugDescription, "3[utf8]")
12481248
}
12491249

12501250

0 commit comments

Comments
 (0)