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

a unquotable character (all CTLs expect "\t")

either '"' or '\'

a rfc2045 token character

a rfc2045 tspecial character (except '"' and '\')

a allowed white space character (either '\t' or ' ')

a non us-ascii character

Trait Implementations

impl Debug for CharType
[src]

[src]

Formats the value using the given formatter.

impl Eq for CharType
[src]

impl PartialEq for CharType
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl Ord for CharType
[src]

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

impl PartialOrd for CharType
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Copy for CharType
[src]

impl Clone for CharType
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq<u8> for CharType
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl From<char> for CharType
[src]

[src]

Performs the conversion.