pub use self::{
absolute::RiAbsoluteStr, fragment::RiFragmentStr, normal::RiStr, query::RiQueryStr,
reference::RiReferenceStr, relative::RiRelativeStr,
};
#[cfg(feature = "alloc")]
pub use self::{
absolute::RiAbsoluteString, error::CreationError, fragment::RiFragmentString, normal::RiString,
query::RiQueryString, reference::RiReferenceString, relative::RiRelativeString,
};
#[macro_use]
mod macros;
mod absolute;
#[cfg(feature = "alloc")]
mod error;
mod fragment;
mod normal;
mod query;
mod reference;
mod relative;
#[cfg(feature = "alloc")]
fn replace_domain_impl<S: crate::spec::Spec>(
iri_ref: &mut alloc::string::String,
new_host: &str,
replace_only_reg_name: bool,
) -> Result<Option<core::ops::Range<usize>>, alloc::collections::TryReserveError> {
use crate::components::AuthorityComponents;
use crate::parser::trusted as trusted_parser;
use crate::parser::validate::validate_host;
let (old_host, host_start) = match AuthorityComponents::from_iri_get_offset(iri_ref) {
Some((authority, offset)) => (authority.host(), offset + authority.host_start),
None => return Ok(None),
};
let old_host_end = host_start + old_host.len();
if validate_host::<S>(new_host).is_err() {
return Ok(None);
}
if replace_only_reg_name && !trusted_parser::authority::is_host_reg_name(old_host) {
return Ok(None);
}
if let Some(additional) = new_host.len().checked_sub(old_host.len()) {
iri_ref.try_reserve(additional)?;
}
iri_ref.replace_range(host_start..old_host_end, new_host);
let new_host_end = host_start + new_host.len();
Ok(Some(host_start..new_host_end))
}