use ::lazy_static::lazy_static;
use ::regex::Regex;
use crate::util::strslice::char_ops::CharOps;
lazy_static! {
pub static ref SINGLE_QUOTE_RE: Regex = Regex::new(r"^(?:''|'[^\n\r]*?[^\\]')").unwrap();
}
pub fn parse_single_quote(text: &str) -> String {
debug_assert!(text.starts_with("'"));
debug_assert!(text.ends_with("'"));
let unquoted = &text[1 .. text.len() - 1];
unquoted.to_owned()
}
#[cfg(test)]
mod single_quoted {
use super::parse_single_quote;
#[test]
fn no_content() {
assert_eq!(&parse_single_quote("''"), "");
}
#[test]
fn simple() {
assert_eq!(&parse_single_quote("'x'"), "x");
assert_eq!(&parse_single_quote("'hello world!'"), "hello world!");
}
#[test]
fn double_quotes() {
assert_eq!(&parse_single_quote("'\"\"'"), "\"\"");
}
fn escaped() {
assert_eq!(&parse_single_quote("'\\''"), "'");
}
#[test]
fn escape_escaped() {
assert_eq!(&parse_single_quote("'\\\\'"), "\\\\");
}
}