Skip to content

Commit

Permalink
Merge pull request #1132 from justinmeiners/quoted-performance
Browse files Browse the repository at this point in the history
Improve string quote performance
  • Loading branch information
jberkel authored Jun 16, 2022
2 parents 593a749 + b45781a commit 578be41
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Sources/SQLite/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ extension Optional: _OptionalType {
let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)

extension String {

func quote(_ mark: Character = "\"") -> String {
let escaped = reduce("") { string, character in
string + (character == mark ? "\(mark)\(mark)" : "\(character)")
var quoted = ""
quoted.append(mark)
for character in self {
quoted.append(character)
if character == mark {
quoted.append(character)
}
}
return "\(mark)\(escaped)\(mark)"
quoted.append(mark)
return quoted
}

func join(_ expressions: [Expressible]) -> Expressible {
Expand Down

0 comments on commit 578be41

Please sign in to comment.