Skip to content

Commit 269a0ba

Browse files
authored
Merge pull request #453 from hamishknight/main-merge
2 parents 62fd560 + 64ccfc5 commit 269a0ba

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Sources/_RegexParser/Utility/TypeConstruction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public enum TypeConstruction {
6060
flags |= 0x10000
6161
}
6262

63-
let result = elementTypes.withContiguousStorageIfAvailable { elementTypesBuffer in
63+
let result = elementTypes.withContiguousStorageIfAvailable { elementTypesBuffer -> (value: Any.Type, state: Int) in
6464
if let labels = labels {
6565
return labels.withCString { labelsPtr in
6666
swift_getTupleTypeMetadata(

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ extension PrettyPrinter {
578578
extension String {
579579
// TODO: Escaping?
580580
fileprivate var _quoted: String {
581-
"\"\(self._replacing("\"", with: "\\\""))\""
581+
"\"\(self._replacing(#"\"#, with: #"\\"#)._replacing(#"""#, with: #"\""#))\""
582582
}
583583
}
584584

Tests/RegexTests/MatchTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,14 @@ extension RegexTests {
13051305
firstMatchTest(#"(?xx)[ \t]+"#, input: " \t \t", match: "\t")
13061306

13071307
firstMatchTest("(?xx)[ a && ab ]+", input: " aaba ", match: "aa")
1308+
1309+
// Preserve whitespace in quoted section inside extended syntax region
1310+
firstMatchTest(
1311+
#"(?x) a b \Q c d \E e f"#, input: "ab c d ef", match: "ab c d ef")
1312+
firstMatchTest(
1313+
#"(?x)[a b]+ _ [a\Q b\E]+"#, input: "aba_ a b a", match: "aba_ a b a")
1314+
firstMatchTest(
1315+
#"(?x)[a b]+ _ [a\Q b\E]+"#, input: "aba _ a b a", match: nil)
13081316
}
13091317

13101318
func testASCIIClasses() {

Tests/RegexTests/RenderDSLTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,12 @@ extension RenderDSLTests {
114114
""")
115115
}
116116
}
117+
118+
func testQuoting() throws {
119+
try testConversion(#"\\"a""#, #"""
120+
Regex {
121+
"\\\"a\""
122+
}
123+
"""#)
124+
}
117125
}

0 commit comments

Comments
 (0)