mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fix raw string parsing bug
This commit is contained in:
@@ -542,6 +542,7 @@ extension Collection where Element == Token {
|
||||
extension UnicodeScalar {
|
||||
var isDigit: Bool { isdigit(Int32(value)) > 0 }
|
||||
var isHexDigit: Bool { isxdigit(Int32(value)) > 0 }
|
||||
var isLinebreak: Bool { "\n\r\u{000B}\u{000C}".unicodeScalars.contains(self) }
|
||||
var isSpace: Bool {
|
||||
switch value {
|
||||
case 0x0009, 0x0011, 0x0012, 0x0020,
|
||||
@@ -554,7 +555,7 @@ extension UnicodeScalar {
|
||||
}
|
||||
|
||||
var isSpaceOrLinebreak: Bool {
|
||||
isSpace || "\n\r\u{000B}\u{000C}".unicodeScalars.contains(self)
|
||||
isSpace || isLinebreak
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,7 +770,7 @@ private extension UnicodeScalarView {
|
||||
}
|
||||
let start = self
|
||||
if readString("\"\"") {
|
||||
if first != "#" {
|
||||
if first?.isLinebreak ?? true {
|
||||
return .startOfScope("\"\"\"")
|
||||
}
|
||||
self = start
|
||||
|
||||
@@ -610,6 +610,16 @@ class TokenizerTests: XCTestCase {
|
||||
XCTAssertEqual(tokenize(input), output)
|
||||
}
|
||||
|
||||
func testRawStringContainingJustTwoUnescapedQuotes() {
|
||||
let input = "#\"\"\"\"#"
|
||||
let output: [Token] = [
|
||||
.startOfScope("#\""),
|
||||
.stringBody("\"\""),
|
||||
.endOfScope("\"#"),
|
||||
]
|
||||
XCTAssertEqual(tokenize(input), output)
|
||||
}
|
||||
|
||||
func testRawStringContainingUnhashedBackslash() {
|
||||
let input = "#\"\\\"#"
|
||||
let output: [Token] = [
|
||||
|
||||
Reference in New Issue
Block a user