mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
- For CustomStringConvertible, `description` should print elements using `String(reflecting:)` rather than `String(describing:)`, to avoid element output from interfering with syntactically relevant punctuation within structured list displays. - To make this work without making displays overly verbose, make `debugDescription` mostly the same as `description`, except for escaping raw string displays when and if needed. - Avoid printing type names in `debugDescription` — it is generally not helpful, as the type is already easily accessible elsewhere. Including it makes for overly verbose displays when the type serves as an Element of a collection. - Avoid having `debugDescription` return the empty string — it can be confusing when such a description appears in list displays. Resolves #301.
29 lines
853 B
Swift
29 lines
853 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2022 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension BitSet: CustomDebugStringConvertible {
|
|
/// A textual representation of this instance, suitable for debugging.
|
|
public var debugDescription: String {
|
|
var result = "["
|
|
var first = true
|
|
for item in self {
|
|
if first {
|
|
first = false
|
|
} else {
|
|
result += ", "
|
|
}
|
|
debugPrint(item, terminator: "", to: &result)
|
|
}
|
|
result += "]"
|
|
return result
|
|
}
|
|
}
|