pub fn parse(uri: &'a str) -> Result<Self> {
        let uri = if uri.starts_with("x-") || uri.starts_with("p-") {
            &uri[2..]
        } else {
            uri
        };

        let uri = if uri.starts_with("cpe:/") {
            &uri[5..]
        } else {
            return Err(CpeError::InvalidPrefix {
                value: uri.to_owned(),
            });
        };

        let mut components = uri.split(':');

        let part = if let Some(part) = components.next() {
            CpeType::try_from(part)?
        } else {
            return Ok(Self::default());
        };

        macro_rules! parse_field {
            (parsed: $($parsed:ident),+) => {
                if let Some(c) = components.next() {
                    parse_uri_attribute(c)?
                } else {
                    return Ok(Self{ $($parsed, )* ..Default::default() });
                }
            }
        }

        let vendor = parse_field!(parsed: part);
        let product = parse_field!(parsed: part, vendor);
        let version = parse_field!(parsed: part, vendor, product);
        let update = parse_field!(parsed: part, vendor, product, version);

        let (edition, sw_edition, target_sw, target_hw, other) = components
            .next()
            .map(|edition| parse_packed_uri_attribute(edition))
            .transpose()?
            .unwrap_or_default();

        let language = if let Some(c) = components.next() {
            Language::Language(c.parse()?)
        } else {
            Language::Any
        };

        Ok(Uri {
            part,
            vendor,
            product,
            version,
            update,
            edition,
            language,
            sw_edition,
            target_sw,
            target_hw,
            other,
        })
    }
/// 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(uri: &'a str) -> Result<Self> {
        let uri = if uri.starts_with("x-") || uri.starts_with("p-") {
            &uri[2..]
        } else {
            uri
        };
        let uri = if uri.starts_with("cpe:/") {
            &uri[5..]
        } else {
            return Err(CpeError::InvalidPrefix {
                value: uri.to_owned(),
            });
        };
        let mut components = uri.split(':');
        let part = if let Some(part) = components.next() {
            CpeType::try_from(part)?
        } else {
            return Ok(Self::default());
        };
        macro_rules! parse_field {
            (parsed: $($parsed:ident),+) => {
                if let Some(c) = components.next() {
                    parse_uri_attribute(c)?
                } else {
                    return Ok(Self{ $($parsed, )* ..Default::default() });
                }
            }
        }
        let vendor = parse_field!(parsed: part);
        let product = parse_field!(parsed: part, vendor);
        let version = parse_field!(parsed: part, vendor, product);
        let update = parse_field!(parsed: part, vendor, product, version);
        let (edition, sw_edition, target_sw, target_hw, other) = components
            .next()
            .map(|edition| parse_packed_uri_attribute(edition))
            .transpose()?
            .unwrap_or_default();
        let language = if let Some(c) = components.next() {
            Language::Language(c.parse()?)
        } else {
            Language::Any
        };
        Ok(Uri {
            part,
            vendor,
            product,
            version,
            update,
            edition,
            language,
            sw_edition,
            target_sw,
            target_hw,
            other,
        })
    }
pub fn parse ( uri : & ' a str ) -> Result < Self > { let uri = if uri . starts_with ( " " ) || uri . starts_with ( " " ) { & uri [ 2 .. ] } else { uri } ; let uri = if uri . starts_with ( " " ) { & uri [ 5 .. ] } else { return Err ( CpeError :: InvalidPrefix { value : uri . to_owned ( ) , } ) ; } ; let mut components = uri . split ( ':' ) ; let part = if let Some ( part ) = components . next ( ) { CpeType :: try_from ( part ) ? } else { return Ok ( Self :: default ( ) ) ; } ; macro_rules! parse_field { ( parsed $ ( $parsed : ident ) + ) => { if let Some ( c ) components next ( ) { parse_uri_attribute ( c ) } else { return Ok ( Self { $ ( $parsed ) * Default default ( ) } ) } } } let vendor = parse_field ! ( parsed part ) ; let product = parse_field ! ( parsed part vendor ) ; let version = parse_field ! ( parsed part vendor product ) ; let update = parse_field ! ( parsed part vendor product version ) ; let ( edition , sw_edition , target_sw , target_hw , other ) = components . next ( ) . map ( | edition | parse_packed_uri_attribute ( edition ) ) . transpose ( ) ? . unwrap_or_default ( ) ; let language = if let Some ( c ) = components . next ( ) { Language :: Language ( c . parse ( ) ? ) } else { Language :: Any } ; Ok ( Uri { part , vendor , product , version , update , edition , language , sw_edition , target_sw , target_hw , other , } ) }
Parse a CPE URI string.
Parse a CPE URI string .
uri
&'a str
uri
&'a str