pub fn national_number<'a>(meta: &Metadata, mut number: Number<'a>) -> Number<'a> {
	let transform = meta.national_prefix_transform_rule.as_ref();
	let parsing   = if let Some(re) = meta.national_prefix_for_parsing.as_ref() {
		re
	}
	else {
		if let Some(prefix) = meta.national_prefix.as_ref() {
			if number.national.starts_with(prefix) {
				number.national = trim(number.national, prefix.len());
			}
		}

		return number;
	};

	let index = parsing.find(&number.national)
		.map(|m| (m.start(), m.end()));

	if index.is_none() {
		return number;
	}

	let (start, end) = index.unwrap();
	if start != 0 {
		return number;
	}

	let viable = meta.descriptors.general.is_match(&number.national);
	let groups = parsing.captures_len();

	let (first, last) = parsing.captures(&number.national).map(|c| {
		(c.get(1).map(|m| m.as_str().to_owned()),
		 c.get(c.len() - 1).map(|m| m.as_str().to_owned()))
	}).unwrap();

	if transform.is_none() || last.is_none() {
		if viable && !meta.descriptors.general.is_match(&number.national[start ..]) {
			return number;
		}

		if groups > 0 && last.is_some() {
			number.carrier = Some(last.unwrap().into());
		}

		number.national = trim(number.national, end);
	}
	else {
		let transformed = parsing.replace(&number.national, &**transform.unwrap()).into_owned();

		if viable && !meta.descriptors.general.is_match(&transformed) {
			return number;
		}

		number.carrier  = Some(first.unwrap().into());
		number.national = transformed.into();
	}

	number
}
/// Strip national prefix and extract carrier.
Strip national prefix and extract carrier.
Strip national prefix and extract carrier .
pub fn national_number<'a>(meta: &Metadata, mut number: Number<'a>) -> Number<'a> {
	let transform = meta.national_prefix_transform_rule.as_ref();
	let parsing   = if let Some(re) = meta.national_prefix_for_parsing.as_ref() {
		re
	}
	else {
		if let Some(prefix) = meta.national_prefix.as_ref() {
			if number.national.starts_with(prefix) {
				number.national = trim(number.national, prefix.len());
			}
		}
		return number;
	};
	let index = parsing.find(&number.national)
		.map(|m| (m.start(), m.end()));
	if index.is_none() {
		return number;
	}
	let (start, end) = index.unwrap();
	if start != 0 {
		return number;
	}
	let viable = meta.descriptors.general.is_match(&number.national);
	let groups = parsing.captures_len();
	let (first, last) = parsing.captures(&number.national).map(|c| {
		(c.get(1).map(|m| m.as_str().to_owned()),
		 c.get(c.len() - 1).map(|m| m.as_str().to_owned()))
	}).unwrap();
	if transform.is_none() || last.is_none() {
		if viable && !meta.descriptors.general.is_match(&number.national[start ..]) {
			return number;
		}
		if groups > 0 && last.is_some() {
			number.carrier = Some(last.unwrap().into());
		}
		number.national = trim(number.national, end);
	}
	else {
		let transformed = parsing.replace(&number.national, &**transform.unwrap()).into_owned();
		if viable && !meta.descriptors.general.is_match(&transformed) {
			return number;
		}
		number.carrier  = Some(first.unwrap().into());
		number.national = transformed.into();
	}
	number
}
pub fn national_number < ' a > ( meta : & Metadata , mut number : Number < ' a > ) -> Number < ' a > { let transform = meta . national_prefix_transform_rule . as_ref ( ) ; let parsing = if let Some ( re ) = meta . national_prefix_for_parsing . as_ref ( ) { re } else { if let Some ( prefix ) = meta . national_prefix . as_ref ( ) { if number . national . starts_with ( prefix ) { number . national = trim ( number . national , prefix . len ( ) ) ; } } return number ; } ; let index = parsing . find ( & number . national ) . map ( | m | ( m . start ( ) , m . end ( ) ) ) ; if index . is_none ( ) { return number ; } let ( start , end ) = index . unwrap ( ) ; if start != 0 { return number ; } let viable = meta . descriptors . general . is_match ( & number . national ) ; let groups = parsing . captures_len ( ) ; let ( first , last ) = parsing . captures ( & number . national ) . map ( | c | { ( c . get ( 1 ) . map ( | m | m . as_str ( ) . to_owned ( ) ) , c . get ( c . len ( ) - 1 ) . map ( | m | m . as_str ( ) . to_owned ( ) ) ) } ) . unwrap ( ) ; if transform . is_none ( ) || last . is_none ( ) { if viable && ! meta . descriptors . general . is_match ( & number . national [ start .. ] ) { return number ; } if groups > 0 && last . is_some ( ) { number . carrier = Some ( last . unwrap ( ) . into ( ) ) ; } number . national = trim ( number . national , end ) ; } else { let transformed = parsing . replace ( & number . national , & * * transform . unwrap ( ) ) . into_owned ( ) ; if viable && ! meta . descriptors . general . is_match ( & transformed ) { return number ; } number . carrier = Some ( first . unwrap ( ) . into ( ) ) ; number . national = transformed . into ( ) ; } number }
Strip national prefix and extract carrier.
Strip national prefix and extract carrier .
meta
&Metadata
number
Number<'a>