chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
use iri_string::types::IriReferenceStr;
fn main() {
for _ in 0..1000000 {
let s = concat!(
"scheme://user:pw@sub.example.com:8080/a/b/c/%30/%31/%32%33%34",
"/foo/foo/../../../foo.foo/foo/foo/././././//////foo",
"/\u{03B1}\u{03B2}\u{03B3}/\u{03B1}\u{03B2}\u{03B3}/\u{03B1}\u{03B2}\u{03B3}",
"?k1=v1&k2=v2&k3=v3#fragment"
);
let domain = "scheme://sub.sub.sub.example.com:8080/a/b/c";
let v4 = "scheme://198.51.100.23:8080/a/b/c";
let v6 = "scheme://[2001:db8:0123::cafe]:8080/a/b/c";
let v6v4 = "scheme://[2001:db8::198.51.100.23]:8080/a/b/c";
let vfuture = "scheme://[v2.ipv2-does-not-exist]:8080/a/b/c";
let _ = (
IriReferenceStr::new(s),
IriReferenceStr::new(domain),
IriReferenceStr::new(v4),
IriReferenceStr::new(v6),
IriReferenceStr::new(v6v4),
IriReferenceStr::new(vfuture),
);
}
}

View File

@@ -0,0 +1,17 @@
#![cfg(feature = "alloc")]
use iri_string::format::ToDedicatedString;
use iri_string::types::{IriAbsoluteStr, IriReferenceStr};
fn main() {
let base = IriAbsoluteStr::new("https://sub.example.com/foo1/foo2/foo3/foo4/foo5")
.expect("should be valid IRI");
let rel = IriReferenceStr::new(concat!(
"bar1/bar2/bar3/../bar4/../../bar5/bar6/bar7/../../../../..",
"/bar8/../../../bar9/././././././bar10/bar11",
))
.expect("should be valid IRI");
for _ in 0..1000000 {
let resolved = rel.resolve_against(base).to_dedicated_string();
drop(resolved);
}
}

145
vendor/iri-string/examples/normalize.rs vendored Normal file
View File

@@ -0,0 +1,145 @@
//! An example to normalize an IRI from the CLI argument.
use iri_string::format::ToDedicatedString;
use iri_string::types::{RiStr, RiString};
const USAGE: &str = "\
USAGE:
normalize [FLAGS] [--] IRI
FLAGS:
-h, --help Prints this help
-i, --iri Handle the input as an IRI (RFC 3987)
-u, --uri Handle the input as an URI (RFC 3986)
-a, --ascii Converts the output to an URI (RFC 3986)
-w, --whatwg Serialize normalization result according to WHATWG URL Standard.
ARGS:
<IRI> IRI
";
fn print_help() {
eprintln!("{USAGE}");
}
fn help_and_exit() -> ! {
print_help();
std::process::exit(1);
}
fn die(msg: impl std::fmt::Display) -> ! {
eprintln!("ERROR: {msg}");
eprintln!();
print_help();
std::process::exit(1);
}
/// Syntax specification.
#[derive(Debug, Clone, Copy)]
enum Spec {
/// RFC 3986 URI.
Uri,
/// RFC 3987 IRI.
Iri,
}
impl Default for Spec {
#[inline]
fn default() -> Self {
Self::Iri
}
}
/// CLI options.
#[derive(Default, Debug, Clone)]
struct CliOpt {
/// IRI.
iri: String,
/// Syntax spec.
spec: Spec,
/// Whether to convert output to ASCII URI or not.
output_ascii: bool,
/// Whether to serialize in WHATWG URL Standard way.
whatwg_serialization: bool,
}
impl CliOpt {
fn parse() -> Self {
let mut args = std::env::args();
// Skip `argv[0]`.
args.next();
let mut iri = None;
let mut spec = None;
let mut output_ascii = false;
let mut whatwg_serialization = false;
for arg in args.by_ref() {
match arg.as_str() {
"--ascii" | "-a" => output_ascii = true,
"--iri" | "-i" => spec = Some(Spec::Iri),
"--uri" | "-u" => spec = Some(Spec::Uri),
"--whatwg" | "-w" => whatwg_serialization = true,
"--help" | "-h" => help_and_exit(),
opt if opt.starts_with('-') => die(format_args!("Unknown option: {opt}")),
_ => {
if iri.replace(arg).is_some() {
die("IRI can be specified at most once");
}
}
}
}
for arg in args {
if iri.replace(arg).is_some() {
eprintln!("ERROR: IRI can be specified at most once");
}
}
let iri = iri.unwrap_or_else(|| die("IRI should be specified"));
let spec = spec.unwrap_or_default();
Self {
iri,
spec,
output_ascii,
whatwg_serialization,
}
}
}
fn main() {
let opt = CliOpt::parse();
match opt.spec {
Spec::Iri => process_iri(&opt),
Spec::Uri => process_uri(&opt),
}
}
fn process_iri(opt: &CliOpt) {
let mut normalized = normalize::<iri_string::spec::IriSpec>(opt);
if opt.output_ascii {
normalized.encode_to_uri_inline();
}
println!("{normalized}");
}
fn process_uri(opt: &CliOpt) {
let normalized = normalize::<iri_string::spec::UriSpec>(opt);
println!("{normalized}");
}
fn normalize<S: iri_string::spec::Spec>(opt: &CliOpt) -> RiString<S> {
let raw = &opt.iri.as_str();
let iri = match RiStr::<S>::new(raw) {
Ok(v) => v,
Err(e) => die(format_args!("Failed to parse {raw:?}: {e:?}")),
};
let normalized = iri.normalize();
if !opt.whatwg_serialization {
if let Err(e) = normalized.ensure_rfc3986_normalizable() {
die(format_args!("Failed to normalize: {e:?}"));
}
}
normalized.to_dedicated_string()
}

159
vendor/iri-string/examples/parse.rs vendored Normal file
View File

@@ -0,0 +1,159 @@
//! An example to parse IRI from the CLI argument.
use iri_string::types::{IriStr, RiReferenceStr, RiStr};
const USAGE: &str = "\
USAGE:
parse [FLAGS] [--] IRI
FLAGS:
-h, --help Prints this help
-i, --iri Handle the input as an IRI (RFC 3987)
-u, --uri Handle the input as an URI (RFC 3986)
ARGS:
<IRI> IRI or URI
";
fn print_help() {
eprintln!("{}", USAGE);
}
fn help_and_exit() -> ! {
print_help();
std::process::exit(1);
}
fn die(msg: impl std::fmt::Display) -> ! {
eprintln!("ERROR: {}", msg);
eprintln!();
print_help();
std::process::exit(1);
}
/// Syntax specification.
#[derive(Debug, Clone, Copy)]
enum Spec {
/// RFC 3986 URI.
Uri,
/// RFC 3987 IRI.
Iri,
}
impl Default for Spec {
#[inline]
fn default() -> Self {
Self::Iri
}
}
/// CLI options.
#[derive(Default, Debug, Clone)]
struct CliOpt {
/// IRI.
iri: String,
/// Syntax spec.
spec: Spec,
}
impl CliOpt {
fn parse() -> Self {
let mut args = std::env::args();
// Skip `argv[0]`.
args.next();
let mut iri = None;
let mut spec = None;
for arg in args.by_ref() {
match arg.as_str() {
"--iri" | "-i" => spec = Some(Spec::Iri),
"--uri" | "-u" => spec = Some(Spec::Uri),
"--help" | "-h" => help_and_exit(),
opt if opt.starts_with('-') => die(format_args!("Unknown option: {}", opt)),
_ => {
if iri.replace(arg).is_some() {
die("IRI can be specified at most once");
}
}
}
}
for arg in args {
if iri.replace(arg).is_some() {
eprintln!("ERROR: IRI can be specified at most once");
}
}
let iri = iri.unwrap_or_else(|| die("IRI should be specified"));
let spec = spec.unwrap_or_default();
Self { iri, spec }
}
}
fn main() {
let opt = CliOpt::parse();
match opt.spec {
Spec::Iri => parse_iri(&opt),
Spec::Uri => parse_uri(&opt),
}
}
fn parse_iri(opt: &CliOpt) {
let iri = parse::<iri_string::spec::IriSpec>(opt);
let uri = iri.encode_to_uri();
println!("ASCII: {:?}", uri);
}
fn parse_uri(opt: &CliOpt) {
let iri = parse::<iri_string::spec::UriSpec>(opt);
println!("ASCII: {:?}", iri);
}
fn parse<S: iri_string::spec::Spec>(opt: &CliOpt) -> &RiReferenceStr<S>
where
RiStr<S>: AsRef<RiStr<iri_string::spec::IriSpec>>,
{
let raw = &opt.iri.as_str();
let iri = match RiReferenceStr::<S>::new(raw) {
Ok(v) => v,
Err(e) => die(format_args!("Failed to parse {:?}: {}", raw, e)),
};
println!("Successfully parsed: {:?}", iri);
let absolute = iri.to_iri().ok();
match absolute {
Some(_) => println!("IRI is ablolute."),
None => println!("IRI is relative."),
}
print_components(iri);
if let Some(absolute) = absolute {
print_normalized(absolute.as_ref());
}
iri
}
fn print_components<S: iri_string::spec::Spec>(iri: &RiReferenceStr<S>) {
println!("scheme: {:?}", iri.scheme_str());
println!("authority: {:?}", iri.authority_str());
if let Some(components) = iri.authority_components() {
println!(" userinfo: {:?}", components.userinfo());
println!(" host: {:?}", components.host());
println!(" port: {:?}", components.port());
}
println!("path: {:?}", iri.path_str());
println!("query: {:?}", iri.query_str());
println!("fragment: {:?}", iri.fragment());
}
pub fn print_normalized(iri: &IriStr) {
println!("is_normalized_rfc3986: {}", iri.is_normalized_rfc3986());
println!(
"is_normalized_but_authorityless_relative_path_preserved: {}",
iri.is_normalized_but_authorityless_relative_path_preserved()
);
println!("normalized: {}", iri.normalize());
}

154
vendor/iri-string/examples/resolve.rs vendored Normal file
View File

@@ -0,0 +1,154 @@
//! An example to parse IRI from the CLI argument.
use iri_string::types::{RiAbsoluteStr, RiReferenceStr};
const USAGE: &str = "\
USAGE:
resolve [FLAGS] [--] BASE REFERENCE
FLAGS:
-h, --help Prints this help
-i, --iri Handle the input as an IRI (RFC 3987)
-u, --uri Handle the input as an URI (RFC 3986)
-w, --whatwg Serialize normalization result according to WHATWG URL Standard.
ARGS:
<BASE> Base IRI or URI to resolve REFERENCE against
<REFERENCE> IRI or URI to resolve
";
fn print_help() {
eprintln!("{}", USAGE);
}
fn help_and_exit() -> ! {
print_help();
std::process::exit(1);
}
fn die(msg: impl std::fmt::Display) -> ! {
eprintln!("ERROR: {}", msg);
eprintln!();
print_help();
std::process::exit(1);
}
/// Syntax specification.
#[derive(Debug, Clone, Copy)]
enum Spec {
/// RFC 3986 URI.
Uri,
/// RFC 3987 IRI.
Iri,
}
impl Default for Spec {
#[inline]
fn default() -> Self {
Self::Iri
}
}
/// CLI options.
#[derive(Default, Debug, Clone)]
struct CliOpt {
/// Base IRI.
base: String,
/// Reference IRI.
reference: String,
/// Syntax spec.
spec: Spec,
/// Whether to serialize in WHATWG URL Standard way.
whatwg_serialization: bool,
}
impl CliOpt {
fn parse() -> Self {
let mut args = std::env::args();
// Skip `argv[0]`.
args.next();
let mut base = None;
let mut reference = None;
let mut spec = None;
let mut whatwg_serialization = false;
for arg in args.by_ref() {
match arg.as_str() {
"--iri" | "-i" => spec = Some(Spec::Iri),
"--uri" | "-u" => spec = Some(Spec::Uri),
"--whatwg" | "-w" => whatwg_serialization = true,
"--help" | "-h" => help_and_exit(),
opt if opt.starts_with('-') => die(format_args!("Unknown option: {}", opt)),
_ => {
if base.is_none() {
base = Some(arg);
} else if reference.is_none() {
reference = Some(arg);
} else {
die("IRI can be specified at most twice");
}
}
}
}
for arg in args {
if base.is_none() {
base = Some(arg);
} else if reference.is_none() {
reference = Some(arg);
} else {
die("IRI can be specified at most twice");
}
}
let base = base.unwrap_or_else(|| die("Base IRI should be specified"));
let reference = reference.unwrap_or_else(|| die("Reference IRI should be specified"));
let spec = spec.unwrap_or_default();
Self {
base,
reference,
spec,
whatwg_serialization,
}
}
}
fn main() {
let opt = CliOpt::parse();
match opt.spec {
Spec::Iri => parse::<iri_string::spec::IriSpec>(&opt),
Spec::Uri => parse::<iri_string::spec::UriSpec>(&opt),
}
}
fn parse<S: iri_string::spec::Spec>(opt: &CliOpt) {
let base_raw = &opt.base.as_str();
let reference_raw = &opt.reference.as_str();
let base = match RiAbsoluteStr::<S>::new(base_raw) {
Ok(v) => v,
Err(e) => die(format_args!(
"Failed to parse {:?} as an IRI (without fragment): {}",
reference_raw, e
)),
};
let reference = match RiReferenceStr::<S>::new(reference_raw) {
Ok(v) => v,
Err(e) => die(format_args!(
"Failed to parse {:?} as an IRI reference: {}",
reference_raw, e
)),
};
let resolved = reference.resolve_against(base);
if !opt.whatwg_serialization {
if let Err(e) = resolved.ensure_rfc3986_normalizable() {
die(format_args!(
"Failed to resolve {:?} against {:?}: {}",
reference_raw, base_raw, e
));
}
}
println!("{}", resolved);
}