File tree 1 file changed +9
-10
lines changed
Sources/SwiftFormat/PrettyPrint
1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -122,17 +122,16 @@ struct PrettyPrintBuffer {
122
122
// In case of comments, we may get a multi-line string.
123
123
// To account for that case, we need to correct the lineNumber count.
124
124
// The new column is only the position within the last line.
125
- var lastLength = 0
126
- // We are only interested in "\n" we can use the UTF8 view and skip the grapheme clustering.
127
- for element in text . utf8 {
128
- if element == UInt8 ( ascii : " \n " ) {
129
- lineNumber += 1
130
- lastLength = 0
131
- } else {
132
- lastLength += 1
133
- }
125
+ let lines = text . split ( separator : " \n " )
126
+ lineNumber += lines . count - 1
127
+ if lines . count > 1 {
128
+ // in case we have inserted new lines, we need to reset the column
129
+ column = lines . last ? . count ?? 0
130
+ } else {
131
+ // in case it is an end of line comment or a single line comment,
132
+ // we just add to the current column
133
+ column += lines . last ? . count ?? 0
134
134
}
135
- column += lastLength
136
135
}
137
136
138
137
/// Request that the given number of spaces be printed out before the next text token.
You can’t perform that action at this time.
0 commit comments