Skip to content

Commit

Permalink
Make conditions case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
trasch committed Sep 9, 2024
1 parent 06b8d19 commit b1734d6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Sources/MVTTools/QueryParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ public struct QueryParser {
// - and, or, not
// - ==, !=, >, >=, <, <=, =~
if isBeginningOfTerm {
let hasAnd = reader.peekString("and")
let hasOr = reader.peekString("or")
let hasNot = reader.peekString("not")
let hasAnd = reader.peekString("and", caseInsensitive: true)
let hasOr = reader.peekString("or", caseInsensitive: true)
let hasNot = reader.peekString("not", caseInsensitive: true)

if hasAnd || hasOr || hasNot {
pipeline?.append(contentsOf: terms)
Expand Down Expand Up @@ -354,11 +354,18 @@ public struct QueryParser {
return characters[index + offset]
}

func peekString(_ string: String) -> Bool {
func peekString(_ string: String, caseInsensitive: Bool) -> Bool {
guard index + string.count <= characters.endIndex else { return false }

for (offset, char) in string.utf8.enumerated() {
if characters[index + offset] != char { return false }
let peekString = caseInsensitive ? string.lowercased() : string

for (offset, char) in peekString.utf8.enumerated() {
var c = characters[index + offset]
if caseInsensitive, c >= 65, c <= 90 {
c += 32
}

if c != char { return false }
}

return true
Expand Down

0 comments on commit b1734d6

Please sign in to comment.