Fixed using spaces in filter expressions and variables lists (#178)
* fixed using spaces in filter expression * fixed breaking variables lists and filters by spaces * simplified smartJoin * avoid force unwrap
This commit is contained in:
@@ -24,7 +24,7 @@ class ForNode : NodeType {
|
||||
let loopVariables = components[1].characters
|
||||
.split(separator: ",")
|
||||
.map(String.init)
|
||||
.map { $0.trimmingCharacters(in: CharacterSet.whitespaces) }
|
||||
.map { $0.trim(character: " ") }
|
||||
|
||||
var emptyNodes = [NodeType]()
|
||||
|
||||
|
||||
@@ -10,6 +10,21 @@ extension String {
|
||||
var singleQuoteCount = 0
|
||||
var doubleQuoteCount = 0
|
||||
|
||||
let specialCharacters = ",|:"
|
||||
func appendWord(_ word: String) {
|
||||
if components.count > 0 {
|
||||
if let precedingChar = components.last?.characters.last, specialCharacters.characters.contains(precedingChar) {
|
||||
components[components.count-1] += word
|
||||
} else if specialCharacters.contains(word) {
|
||||
components[components.count-1] += word
|
||||
} else {
|
||||
components.append(word)
|
||||
}
|
||||
} else {
|
||||
components.append(word)
|
||||
}
|
||||
}
|
||||
|
||||
for character in self.characters {
|
||||
if character == "'" { singleQuoteCount += 1 }
|
||||
else if character == "\"" { doubleQuoteCount += 1 }
|
||||
@@ -19,7 +34,7 @@ extension String {
|
||||
if separate != separator {
|
||||
word.append(separate)
|
||||
} else if (singleQuoteCount % 2 == 0 || doubleQuoteCount % 2 == 0) && !word.isEmpty {
|
||||
components.append(word)
|
||||
appendWord(word)
|
||||
word = ""
|
||||
}
|
||||
|
||||
@@ -33,7 +48,7 @@ extension String {
|
||||
}
|
||||
|
||||
if !word.isEmpty {
|
||||
components.append(word)
|
||||
appendWord(word)
|
||||
}
|
||||
|
||||
return components
|
||||
|
||||
@@ -209,11 +209,11 @@ extension Dictionary : Normalizable {
|
||||
|
||||
func parseFilterComponents(token: String) -> (String, [Variable]) {
|
||||
var components = token.smartSplit(separator: ":")
|
||||
let name = components.removeFirst()
|
||||
let name = components.removeFirst().trim(character: " ")
|
||||
let variables = components
|
||||
.joined(separator: ":")
|
||||
.smartSplit(separator: ",")
|
||||
.map { Variable($0) }
|
||||
.map { Variable($0.trim(character: " ")) }
|
||||
return (name, variables)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user