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:
Ilya Puchka
2018-05-13 01:06:38 +01:00
committed by GitHub
parent d935f65d56
commit 39ed9aa753
6 changed files with 32 additions and 11 deletions

View File

@@ -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