Skip to content

Commit 8849097

Browse files
Refactor
1 parent 960b2de commit 8849097

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

Resources/branch_main/Sources/parser/TokenVisitor.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,19 @@ final class TokenVisitor: SyntaxRewriter {
146146
.text
147147
.htmlEscaped()
148148
.substituteInvisibles()
149-
.replacingOccurrences(of: " ", with: "")
150-
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
149+
.transformWhitespaces()
151150
current.token = Token(kind: "\(token.tokenKind)", leadingTrivia: "", trailingTrivia: "")
152151

153152
token.leadingTrivia.forEach { (piece) in
154153
let trivia = processTriviaPiece(piece)
155154
list.append(trivia)
156-
current.token?.leadingTrivia += replaceSymbols(text: trivia)
155+
current.token?.leadingTrivia += trivia.transformWhitespaces()
157156
}
158157
processToken(token)
159158
token.trailingTrivia.forEach { (piece) in
160159
let trivia = processTriviaPiece(piece)
161160
list.append(trivia)
162-
current.token?.trailingTrivia += replaceSymbols(text: trivia)
161+
current.token?.trailingTrivia += trivia.transformWhitespaces()
163162
}
164163

165164
return token
@@ -234,12 +233,6 @@ final class TokenVisitor: SyntaxRewriter {
234233
}
235234
return trivia
236235
}
237-
238-
private func replaceSymbols(text: String) -> String {
239-
text
240-
.replacingOccurrences(of: "&nbsp;", with: "")
241-
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
242-
}
243236
}
244237

245238
private extension String {
@@ -269,4 +262,10 @@ private extension String {
269262
.replacingOccurrences(of: " ", with: "")
270263
.replacingOccurrences(of: "\n", with: "")
271264
}
265+
266+
func transformWhitespaces() -> String {
267+
self
268+
.replacingOccurrences(of: "&nbsp;", with: "")
269+
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
270+
}
272271
}

Resources/branch_release-5.9/Sources/parser/TokenVisitor.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,19 @@ final class TokenVisitor: SyntaxRewriter {
146146
.text
147147
.htmlEscaped()
148148
.substituteInvisibles()
149-
.replacingOccurrences(of: "&nbsp;", with: "")
150-
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
149+
.transformWhitespaces()
151150
current.token = Token(kind: "\(token.tokenKind)", leadingTrivia: "", trailingTrivia: "")
152151

153152
token.leadingTrivia.forEach { (piece) in
154153
let trivia = processTriviaPiece(piece)
155154
list.append(trivia)
156-
current.token?.leadingTrivia += replaceSymbols(text: trivia)
155+
current.token?.leadingTrivia += trivia.transformWhitespaces()
157156
}
158157
processToken(token)
159158
token.trailingTrivia.forEach { (piece) in
160159
let trivia = processTriviaPiece(piece)
161160
list.append(trivia)
162-
current.token?.trailingTrivia += replaceSymbols(text: trivia)
161+
current.token?.trailingTrivia += trivia.transformWhitespaces()
163162
}
164163

165164
return token
@@ -234,12 +233,6 @@ final class TokenVisitor: SyntaxRewriter {
234233
}
235234
return trivia
236235
}
237-
238-
private func replaceSymbols(text: String) -> String {
239-
text
240-
.replacingOccurrences(of: "&nbsp;", with: "")
241-
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
242-
}
243236
}
244237

245238
private extension String {
@@ -269,4 +262,10 @@ private extension String {
269262
.replacingOccurrences(of: " ", with: "")
270263
.replacingOccurrences(of: "\n", with: "")
271264
}
265+
266+
func transformWhitespaces() -> String {
267+
self
268+
.replacingOccurrences(of: "&nbsp;", with: "")
269+
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
270+
}
272271
}

Sources/App/Controllers/TokenVisitor.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,19 @@ final class TokenVisitor: SyntaxRewriter {
133133
.text
134134
.htmlEscaped()
135135
.substituteInvisibles()
136-
.replacingOccurrences(of: "&nbsp;", with: "")
137-
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
136+
.transformWhitespaces()
138137
current.token = Token(kind: "\(token.tokenKind)", leadingTrivia: "", trailingTrivia: "")
139138

140139
token.leadingTrivia.forEach { (piece) in
141140
let trivia = processTriviaPiece(piece)
142141
list.append(trivia)
143-
current.token?.leadingTrivia += replaceSymbols(text: trivia)
142+
current.token?.leadingTrivia += trivia.transformWhitespaces()
144143
}
145144
processToken(token)
146145
token.trailingTrivia.forEach { (piece) in
147146
let trivia = processTriviaPiece(piece)
148147
list.append(trivia)
149-
current.token?.trailingTrivia += replaceSymbols(text: trivia)
148+
current.token?.trailingTrivia += trivia.transformWhitespaces()
150149
}
151150

152151
return token
@@ -221,12 +220,6 @@ final class TokenVisitor: SyntaxRewriter {
221220
}
222221
return trivia
223222
}
224-
225-
private func replaceSymbols(text: String) -> String {
226-
text
227-
.replacingOccurrences(of: "&nbsp;", with: "")
228-
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
229-
}
230223
}
231224

232225
private extension String {
@@ -256,4 +249,10 @@ private extension String {
256249
.replacingOccurrences(of: " ", with: "")
257250
.replacingOccurrences(of: "\n", with: "")
258251
}
252+
253+
func transformWhitespaces() -> String {
254+
self
255+
.replacingOccurrences(of: "&nbsp;", with: "")
256+
.replacingOccurrences(of: "<br/>", with: "↲<br/>")
257+
}
259258
}

0 commit comments

Comments
 (0)