Enum quoted_string::CharType
[−]
[src]
#[repr(u8)]pub enum CharType { Unquotable, NeedsQuoting, Token, TSpecial, Ws, NonAscii, }
A enum for usage in combination with the QTEXT_INFO lookup table
To see if a character is valid inside a quoted string
use char_type > 1
which means any token, tspecial (except '"' and '\')
ws and non us-ascii character is included.
To see if a character needs to be represented as a quoted-pair in
a quoted string use char_type == NeedsQuoting
.
Example
use quoted_string::CharType::{self, Unquotable, NeedsQuoting, Token}; fn simple_quote(s: &str) -> String { let mut buffer = String::new(); buffer.push('"'); for ch in s.chars() { match CharType::from(ch) { Unquotable => panic!("can not quote: {:?}", ch), NeedsQuoting => { buffer.push('\\'); buffer.push(ch); }, _ => buffer.push(ch) } } buffer.push('"'); buffer } fn is_token(s: &str) -> bool { s.chars().all(|ch| CharType::from(ch) == Token) } let x = "hallo\"there"; let y = "abc"; assert!(!is_token(x)); assert!(is_token(y)); let quoted_x = simple_quote(x); assert_eq!(quoted_x, "\"hallo\\\"there\"");
Variants
Unquotable
a unquotable character (all CTLs expect "\t")
NeedsQuoting
either '"' or '\'
Token
a rfc2045 token character
TSpecial
a rfc2045 tspecial character (except '"' and '\')
Ws
a allowed white space character (either '\t' or ' ')
NonAscii
a non us-ascii character
Trait Implementations
impl Debug for CharType
[src]
impl Eq for CharType
[src]
impl PartialEq for CharType
[src]
fn eq(&self, __arg_0: &CharType) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Ord for CharType
[src]
fn cmp(&self, __arg_0: &CharType) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl PartialOrd for CharType
[src]
fn partial_cmp(&self, __arg_0: &CharType) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Hash for CharType
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Copy for CharType
[src]
impl Clone for CharType
[src]
fn clone(&self) -> CharType
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq<u8> for CharType
[src]
fn eq(&self, other: &u8) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.