Skip to main content

iri_content_defect

Function iri_content_defect 

Source
pub fn iri_content_defect(s: &str) -> Option<IriDefect>
Expand description

Classify the content of an IRIREF — what sits between < and > — returning None when it is a valid absolute IRI, and otherwise the class that says what can be done about it.

Validity is the parser’s call, not the taxonomy’s. The order is:

  1. the cheap shape_defect scan, which settles the IRIREF character set and names a repair when it recognises one;
  2. a repairable shape is only reported as repairable when escaping it verifiably lands an IRI the parser accepts — otherwise the IRI carries a second defect no class names, and calling it Bracket would have the sanitizer claim a fix it did not make;
  3. anything the scan finds nothing wrong with still has to satisfy RFC 3987, and IriDefect::Unclassified is what a rejection with no known shape is called. It is counted, it is unrepairable, and it blocks.

The common case — a valid IRI — costs one byte scan plus one oxiri parse, with no allocation. Measured over 2,000,000 distinct real IRIs (104 MB, 52 bytes mean) from a published dump: 224 ns each, 4.5 M IRI/s, of which the parser is 190 ns and walking the bytes at all is 101 ns. The parser is therefore roughly a doubling of a check that was already far cheaper than the sort and the I/O around it. The re-escape in step 2 runs only for an IRI already known to be broken, which is the rare case by construction.