in Sources/SwiftSyntax/RawSyntax.swift [402:426]
func formTrailingTrivia() -> Trivia {
var newPieces: [TriviaPiece] = []
newPieces.reserveCapacity(trailingTriviaBuffer.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 trailingTriviaBuffer {
let newPiece = TriviaPiece.fromRawValue(cpiece, textBuffer: emptyStringBuffer)
newPieces.append(newPiece)
}
} else {
let leadingTriviaLength = self.getLeadingTriviaLength()
let trailingTriviaLength = self.getTrailingTriviaLength()
let tokenLength = Int(length) - (leadingTriviaLength + trailingTriviaLength)
var textOffset = leadingTriviaLength + tokenLength
for cpiece in trailingTriviaBuffer {
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)
}