Skip to content

Commit 7d384dd

Browse files
committed
Handle Spaces in Makefile Parsing
In a Makefile, spaces can be escaped by a preceeding backslash. Rather than using string.split, iterate through the string keeping track of the previous character.
1 parent c045a1f commit 7d384dd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Sources/tibs/main.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,21 @@ func swiftDepsMerge(output: String, _ files: [String]) {
4242
exit(1)
4343
}
4444

45-
let deps = depStr.split(whereSeparator: { $0.isWhitespace })
45+
var deps: [Substring] = []
46+
var prev: Character = "."
47+
var it = depStr.startIndex
48+
var strStart = it
49+
while it != depStr.endIndex {
50+
let curr = depStr[it]
51+
if curr == " " && prev != "\\" {
52+
deps.append(depStr[strStart..<it])
53+
strStart = depStr.index(after: it)
54+
}
55+
prev = curr
56+
it = depStr.index(after: it)
57+
}
58+
deps.append(depStr[strStart..<it])
59+
4660
for dep in deps {
4761
allDeps.insert(dep)
4862
}

0 commit comments

Comments
 (0)