mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-25 12:55:24 +00:00
*Escape::with_preferred_quote
This commit is contained in:
parent
d6b6df5d1c
commit
99e108dd53
1 changed files with 20 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
pub enum Quote {
|
pub enum Quote {
|
||||||
Single,
|
Single,
|
||||||
Double,
|
Double,
|
||||||
|
@ -80,15 +80,21 @@ pub struct UnicodeEscape<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> UnicodeEscape<'a> {
|
impl<'a> UnicodeEscape<'a> {
|
||||||
|
#[inline]
|
||||||
pub fn with_forced_quote(source: &'a str, quote: Quote) -> Self {
|
pub fn with_forced_quote(source: &'a str, quote: Quote) -> Self {
|
||||||
let layout = EscapeLayout { quote, len: None };
|
let layout = EscapeLayout { quote, len: None };
|
||||||
Self { source, layout }
|
Self { source, layout }
|
||||||
}
|
}
|
||||||
pub fn new_repr(source: &'a str) -> Self {
|
#[inline]
|
||||||
let layout = Self::repr_layout(source, Quote::Single);
|
pub fn with_preferred_quote(source: &'a str, quote: Quote) -> Self {
|
||||||
|
let layout = Self::repr_layout(source, quote);
|
||||||
Self { source, layout }
|
Self { source, layout }
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn new_repr(source: &'a str) -> Self {
|
||||||
|
Self::with_preferred_quote(source, Quote::Single)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
pub fn str_repr<'r>(&'a self) -> StrRepr<'r, 'a> {
|
pub fn str_repr<'r>(&'a self) -> StrRepr<'r, 'a> {
|
||||||
StrRepr(self)
|
StrRepr(self)
|
||||||
}
|
}
|
||||||
|
@ -265,18 +271,25 @@ pub struct AsciiEscape<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsciiEscape<'a> {
|
impl<'a> AsciiEscape<'a> {
|
||||||
|
#[inline]
|
||||||
pub fn new(source: &'a [u8], layout: EscapeLayout) -> Self {
|
pub fn new(source: &'a [u8], layout: EscapeLayout) -> Self {
|
||||||
Self { source, layout }
|
Self { source, layout }
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
pub fn with_forced_quote(source: &'a [u8], quote: Quote) -> Self {
|
pub fn with_forced_quote(source: &'a [u8], quote: Quote) -> Self {
|
||||||
let layout = EscapeLayout { quote, len: None };
|
let layout = EscapeLayout { quote, len: None };
|
||||||
Self { source, layout }
|
Self { source, layout }
|
||||||
}
|
}
|
||||||
pub fn new_repr(source: &'a [u8]) -> Self {
|
#[inline]
|
||||||
let layout = Self::repr_layout(source, Quote::Single);
|
pub fn with_preferred_quote(source: &'a [u8], quote: Quote) -> Self {
|
||||||
|
let layout = Self::repr_layout(source, quote);
|
||||||
Self { source, layout }
|
Self { source, layout }
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn new_repr(source: &'a [u8]) -> Self {
|
||||||
|
Self::with_preferred_quote(source, Quote::Single)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
pub fn bytes_repr<'r>(&'a self) -> BytesRepr<'r, 'a> {
|
pub fn bytes_repr<'r>(&'a self) -> BytesRepr<'r, 'a> {
|
||||||
BytesRepr(self)
|
BytesRepr(self)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue