in Sources/SwiftSyntax/RawSyntax.swift [379:400]
func formLeadingTrivia() -> Trivia {
var newPieces: [TriviaPiece] = []
newPieces.reserveCapacity(leadingTriviaBuffer.count)
if fullTextBuffer.isEmpty {
// Fast path, there's no text in the buffer so no need to determine the
// trivia piece length.
for cpiece in leadingTriviaBuffer {
let newPiece = TriviaPiece.fromRawValue(cpiece, textBuffer: emptyStringBuffer)
newPieces.append(newPiece)
}
} else {
var textOffset = 0
for cpiece in leadingTriviaBuffer {
let len = Int(cpiece.length)
let textBuffer = getTextSlice(start: textOffset, length: len)
let newPiece = TriviaPiece.fromRawValue(cpiece, textBuffer: textBuffer)
newPieces.append(newPiece)
textOffset += len
}
}
return .init(pieces: newPieces)
}