pub fn parse(value: &'a str) -> Result<Self> {
        let offset = if value.starts_with("wfn:[") {
            5
        } else {
            return Err(CpeError::InvalidPrefix {
                value: value.to_owned(),
            });
        };

        let mut wfn = Self::new();

        let remainder = &value[offset..value.len() - 1];

        let mut set_part = false;
        let mut set_vendor = false;
        let mut set_product = false;
        let mut set_version = false;
        let mut set_update = false;
        let mut set_edition = false;
        let mut set_language = false;
        let mut set_sw_edition = false;
        let mut set_target_sw = false;
        let mut set_target_hw = false;
        let mut set_other = false;

        let parts = split_unescaped_comma(remainder);
        eprintln!("{:?}", parts);
        for part in parts {
            let (attribute, value) = {
                let mut parts = part.splitn(2, '=');
                let att = parts
                    .next()
                    .ok_or_else(|| CpeError::InvalidWfn {
                        value: value.to_owned(),
                        expected: format!("malformed attribute value pair `{}`", part),
                    })?
                    .to_lowercase();
                let val = parts
                    .next()
                    .ok_or_else(|| CpeError::InvalidWfn {
                        value: value.to_owned(),
                        expected: format!("malformed attribute value pair `{}`", part),
                    })?
                    .trim_start_matches('"')
                    .trim_end_matches('"');
                (att, val)
            };

            macro_rules! set_field {
                ($name:literal, $check:ident) => {
                    if $check {
                        return Err(CpeError::DuplicateAttribute {
                            value: value.to_owned(),
                            name: $name,
                        });
                    } else {
                        $check = true;
                        wfn.$check(value)?;
                    }
                };
            }

            match attribute.as_str() {
                "part" => set_field!("part", set_part),
                "language" => set_field!("language", set_language),
                "vendor" => set_field!("vendor", set_vendor),
                "product" => set_field!("product", set_product),
                "version" => set_field!("version", set_version),
                "update" => set_field!("update", set_update),
                "edition" => set_field!("edition", set_edition),
                "sw_edition" => set_field!("sw_edition", set_sw_edition),
                "target_sw" => set_field!("target_sw", set_target_sw),
                "target_hw" => set_field!("target_hw", set_target_hw),
                "other" => set_field!("other", set_other),
                _ => {
                    return Err(CpeError::InvalidWfn {
                        value: value.to_owned(),
                        expected: format!("invalid attribute `{}`", attribute),
                    })
                }
            }
        }

        Ok(wfn)
    }
/// Parse a CPE URI string.
///
/// This function will decode percent encodings and special characters to their
/// semantic meaning.
Parse a CPE URI string.
This function will decode percent encodings and special characters to their
semantic meaning.
Parse a CPE URI string . This function will decode percent encodings and special characters to their semantic meaning .
pub fn parse(value: &'a str) -> Result<Self> {
        let offset = if value.starts_with("wfn:[") {
            5
        } else {
            return Err(CpeError::InvalidPrefix {
                value: value.to_owned(),
            });
        };
        let mut wfn = Self::new();
        let remainder = &value[offset..value.len() - 1];
        let mut set_part = false;
        let mut set_vendor = false;
        let mut set_product = false;
        let mut set_version = false;
        let mut set_update = false;
        let mut set_edition = false;
        let mut set_language = false;
        let mut set_sw_edition = false;
        let mut set_target_sw = false;
        let mut set_target_hw = false;
        let mut set_other = false;
        let parts = split_unescaped_comma(remainder);
        eprintln!("{:?}", parts);
        for part in parts {
            let (attribute, value) = {
                let mut parts = part.splitn(2, '=');
                let att = parts
                    .next()
                    .ok_or_else(|| CpeError::InvalidWfn {
                        value: value.to_owned(),
                        expected: format!("malformed attribute value pair `{}`", part),
                    })?
                    .to_lowercase();
                let val = parts
                    .next()
                    .ok_or_else(|| CpeError::InvalidWfn {
                        value: value.to_owned(),
                        expected: format!("malformed attribute value pair `{}`", part),
                    })?
                    .trim_start_matches('"')
                    .trim_end_matches('"');
                (att, val)
            };
            macro_rules! set_field {
                ($name:literal, $check:ident) => {
                    if $check {
                        return Err(CpeError::DuplicateAttribute {
                            value: value.to_owned(),
                            name: $name,
                        });
                    } else {
                        $check = true;
                        wfn.$check(value)?;
                    }
                };
            }
            match attribute.as_str() {
                "part" => set_field!("part", set_part),
                "language" => set_field!("language", set_language),
                "vendor" => set_field!("vendor", set_vendor),
                "product" => set_field!("product", set_product),
                "version" => set_field!("version", set_version),
                "update" => set_field!("update", set_update),
                "edition" => set_field!("edition", set_edition),
                "sw_edition" => set_field!("sw_edition", set_sw_edition),
                "target_sw" => set_field!("target_sw", set_target_sw),
                "target_hw" => set_field!("target_hw", set_target_hw),
                "other" => set_field!("other", set_other),
                _ => {
                    return Err(CpeError::InvalidWfn {
                        value: value.to_owned(),
                        expected: format!("invalid attribute `{}`", attribute),
                    })
                }
            }
        }
        Ok(wfn)
    }
pub fn parse ( value : & ' a str ) -> Result < Self > { let offset = if value . starts_with ( " " ) { 5 } else { return Err ( CpeError :: InvalidPrefix { value : value . to_owned ( ) , } ) ; } ; let mut wfn = Self :: new ( ) ; let remainder = & value [ offset .. value . len ( ) - 1 ] ; let mut set_part = false ; let mut set_vendor = false ; let mut set_product = false ; let mut set_version = false ; let mut set_update = false ; let mut set_edition = false ; let mut set_language = false ; let mut set_sw_edition = false ; let mut set_target_sw = false ; let mut set_target_hw = false ; let mut set_other = false ; let parts = split_unescaped_comma ( remainder ) ; eprintln ! ( " " parts ) ; for part in parts { let ( attribute , value ) = { let mut parts = part . splitn ( 2 , '=' ) ; let att = parts . next ( ) . ok_or_else ( | | CpeError :: InvalidWfn { value : value . to_owned ( ) , expected : format ! ( " " part ) , } ) ? . to_lowercase ( ) ; let val = parts . next ( ) . ok_or_else ( | | CpeError :: InvalidWfn { value : value . to_owned ( ) , expected : format ! ( " " part ) , } ) ? . trim_start_matches ( '"' ) . trim_end_matches ( '"' ) ; ( att , val ) } ; macro_rules! set_field { ( $name : literal $check : ident ) => { if $check { return Err ( CpeError DuplicateAttribute { value value to_owned ( ) name $name } ) } else { $check true wfn $check ( value ) } } ; } match attribute . as_str ( ) { " " => set_field ! ( " " set_part ) , " " => set_field ! ( " " set_language ) , " " => set_field ! ( " " set_vendor ) , " " => set_field ! ( " " set_product ) , " " => set_field ! ( " " set_version ) , " " => set_field ! ( " " set_update ) , " " => set_field ! ( " " set_edition ) , " " => set_field ! ( " " set_sw_edition ) , " " => set_field ! ( " " set_target_sw ) , " " => set_field ! ( " " set_target_hw ) , " " => set_field ! ( " " set_other ) , _ => { return Err ( CpeError :: InvalidWfn { value : value . to_owned ( ) , expected : format ! ( " " attribute ) , } ) } } } Ok ( wfn ) }
Parse a CPE URI string.
Parse a CPE URI string .
value
&'a str
value
&'a str