in Sources/SwiftSyntax/SourceLocation.swift [423:459]
func forEachLineLength(
prefix: SourceLength = .zero, body: (SourceLength) -> ()
) -> SourceLength {
var lineLength = prefix
switch self {
case let .spaces(count),
let .tabs(count),
let .verticalTabs(count),
let .formfeeds(count):
lineLength += SourceLength(utf8Length: count)
case let .newlines(count),
let .carriageReturns(count):
let newLineLength = SourceLength(utf8Length: 1)
body(lineLength + newLineLength)
for _ in 1..<count {
body(newLineLength)
}
lineLength = .zero
case let .carriageReturnLineFeeds(count):
let carriageReturnLineLength = SourceLength(utf8Length: 2)
body(lineLength + carriageReturnLineLength)
for _ in 1..<count {
body(carriageReturnLineLength)
}
lineLength = .zero
case let .lineComment(text),
let .docLineComment(text):
// Line comments are not supposed to contain newlines.
assert(!text.containsSwiftNewline(), "line comment created that contained a new-line character")
lineLength += SourceLength(utf8Length: text.utf8.count)
case let .blockComment(text),
let .docBlockComment(text),
let .garbageText(text):
lineLength = text.forEachLineLength(prefix: lineLength, body: body)
}
return lineLength
}