Format strings with ’
single quotes if string does not contain any ’
characters
This commit is contained in:
parent
227bb0a3ce
commit
f0b30e9526
1 changed files with 7 additions and 1 deletions
|
@ -2,6 +2,8 @@ use crate::sql::common::val_u8;
|
||||||
use nom::character::is_digit;
|
use nom::character::is_digit;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
const SINGLE: char = '\'';
|
||||||
|
|
||||||
const BRACKETL: char = '⟨';
|
const BRACKETL: char = '⟨';
|
||||||
const BRACKETR: char = '⟩';
|
const BRACKETR: char = '⟩';
|
||||||
const BRACKET_ESC: &str = r#"\⟩"#;
|
const BRACKET_ESC: &str = r#"\⟩"#;
|
||||||
|
@ -14,7 +16,11 @@ const BACKTICK_ESC: &str = r#"\`"#;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn escape_str(s: &str) -> String {
|
pub fn escape_str(s: &str) -> String {
|
||||||
format!("{}{}{}", DOUBLE, s, DOUBLE)
|
if s.contains(SINGLE) {
|
||||||
|
format!("{}{}{}", DOUBLE, s, DOUBLE)
|
||||||
|
} else {
|
||||||
|
format!("{}{}{}", SINGLE, s, SINGLE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in a new issue