//!
//! 
//! This crate provides an `IriExtra` trait, `Iri`, `Namespace`, `Name`, and `QName`
//! types and associated errors.
//!
//! The primary reference for this crate is the [SPARQL](https://www.w3.org/TR/rdf-sparql-query/)
//! specification. The [Turtle](https://www.w3.org/TR/turtle/) language as well as the OWL
//! [Functional Syntax](https://www.w3.org/TR/owl2-syntax/) and
//! [Manchester Syntax](http://www.w3.org/TR/owl2-manchester-syntax/) reference the SPARQL
//! `PNAME_NS`, `PNAME_LN`, and `PrefixedName` productions.
//!
//! ## Specification Summary
//!
//! From [SPARQL](https://www.w3.org/TR/rdf-sparql-query/) ยง[A.8 Grammar](https://www.w3.org/TR/2008/REC-rdf-sparql-query-20080115/#sparqlGrammar):
//!
//! ```text
//! [68] PrefixedName ::= PNAME_LN | PNAME_NS
//!
//! [71] PNAME_NS ::= PN_PREFIX? ':'
//! [72] PNAME_LN ::= PNAME_NS PN_LOCAL
//! [95] PN_CHARS_BASE ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF]
//! | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F]
//! | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD]
//! | [#x10000-#xEFFFF]
//! [96] PN_CHARS_U ::= PN_CHARS_BASE | '_'
//!
//! [98] PN_CHARS ::= PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
//! [99] PN_PREFIX ::= PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)?
//! [100] PN_LOCAL ::= ( PN_CHARS_U | [0-9] ) ((PN_CHARS|'.')* PN_CHARS)?
//! /* Note that SPARQL local names allow leading digits while XML local names do not. */
//! ```
//!
//! Where the following table provides a mapping from the BNF above to types in this package.
//!
//! | Specification Name | Crate Type | Comments |
//! | ------------------ | ----------------------- | --------------------------------------------------------------- |
//! | `IRIRef` | [`iri::IriRef`] | An enum with `Iri` and `PrefixedName` variants. |
//! | `IRI_REF` | [`iri::Iri`] | A wrapper around the `Url` type from the `url` crate. |
//! | | [`iri::IriExtra`] | A trait implemented by `Iri` to add to the `Url` type. |
//! | `PrefixedName` | [`pname::PrefixedName`] | A tuple of `Namespace` and `Name`. |
//! | `PNAME_LN` | [`pname::Name`] | The name of the locally-defined *thing*. |
//! | `PNAME_NS` | [`pname::Namespace`] | The prefix name used to reference the namespace, including ':'. |
//!
//! ## The `Iri` Type
//!
//! The [`Iri`] type is a wrapper around the `url::Url` type, and as can be constructed in the
//! same manner.
//!
//! ### Examples
//!
//! ```rust
//! use rdftk_iri::Iri;
//! use std::str::FromStr;
//!
//! let result = Iri::from_str(
//! "https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top",
//! ).unwrap();
//! ```
//!
//! ### The [`IriExtra`] trait provides a number of additional methods useful to the IRI as a namespace
//! and namespaced-name identifier.
//!
//! ```rust
//! use rdftk_iri::{Iri, IriExtra as _, Name};
//! use std::str::FromStr;
//!
//! let namespace = Iri::from_str(
//! "https://example.org/ns/things#",
//! ).unwrap();
//! assert!(namespace.looks_like_namespace());
//!
//! let name = namespace.make_name(Name::from_str("ThisThing").unwrap()).unwrap();
//! assert_eq!(
//! name.to_string(),
//! "https://example.org/ns/things#ThisThing".to_string(),
//! );
//!
//! assert_eq!(
//! name.namespace(),
//! Some(namespace),
//! );
//!
//! assert_eq!(
//! name.name(),
//! Some(Name::from_str("ThisThing").unwrap()),
//! );
//! ```
//!
//! ### Curie
//!
//! Specification: <https://www.w3.org/TR/curie/>
//!
//! ```text
//! safe_curie := '[' curie ']'
//!
//! curie := [ [ prefix ] ':' ] reference
//!
//! prefix := NCName
//!
//! reference := irelative-ref (as defined in IRI)
//! ```
//!
//! Note that while the empty string matches the production for curie above, an empty string is NOT a
//! valid CURIE. The CURIE prefix '_' is reserved for use by languages that support RDF. For this
//! reason, the prefix '_' SHOULD be avoided by authors.
//!
//! ## The `Namespace` Type
//!
//! A [`Namespace`], `PNAME_NS` from the [SPARQL](https://www.w3.org/TR/rdf-sparql-query/)
//! specification, is a prefix string used to reference a namespace IRI in languages such as
//! OWL, Turtle, SPARQL and so forth.
//!
//! ```rust
//! use rdftk_iri::{LocalName, Name, Namespace};
//! use std::str::FromStr;
//!
//! let ns = Namespace::from_str(":").unwrap();
//! assert!(ns.is_default());
//!
//! let ns = Namespace::from_str("rdf:").unwrap();
//! assert!(!ns.is_default());
//!
//! let name: LocalName = ns.qualify(&Name::from_str("type").unwrap());
//! assert_eq!("rdf:type".to_string(), name.to_string());
//! ```
//!
//! ## `Name` Type
//!
//! A [`Name`], `PN_LOCAL` from the [SPARQL](https://www.w3.org/TR/rdf-sparql-query/)
//! specification, represents that portion of a [`LocalName`] that refers to the
//! locally defined or referenced *thing*.
//!
//! ```rust
//! use rdftk_iri::{LocalName, Name, Namespace};
//! use std::str::FromStr;
//!
//! assert!(Name::from_str("subClassOf").is_ok());
//!
//! assert!(Name::from_str("rdf:").is_err());
//!
//! let name = Name::from_str("type").unwrap();
//! let name: LocalName = name.qualify(&Namespace::from_str("rdf:").unwrap());
//! assert_eq!("rdf:type".to_string(), name.to_string());
//! ```
//!
//! ## The `LocalName` Type
//!
//! A [`LocalName`], `PNAME_LN` from the [SPARQL](https://www.w3.org/TR/rdf-sparql-query/)
//! specification, represents the tuple of [`Namespace`] and [`Name`], such that every
//! name is qualified with the namespace it is defined within.
//!
//! ### Example
//!
//! ```rust
//! use rdftk_iri::{LocalName, Name, Namespace};
//! use std::str::FromStr;
//!
//! let parsed_prefixed: LocalName = "prefix:name".parse().expect("parse error");
//! let constructed_prefixed: LocalName = LocalName::new(
//! Namespace::new_unchecked("prefix"),
//! Name::new_unchecked("name"),
//! );
//! assert_eq!(parsed_prefixed, constructed_prefixed);
//!
//! let parsed_default: LocalName = ":name".parse().expect("parse error");
//! let constructed_default: LocalName =
//! LocalName::new_in_default(Name::new_unchecked("name"));
//! assert_eq!(parsed_default, constructed_default);
//!
//! assert!(LocalName::from_str("").is_err());
//! assert!(LocalName::from_str("hello world").is_err());
//! ```
//!
//! ## Feature flags
#![doc = document_features::document_features!()]
//
// Support for no-std needs to be first here.
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]
extern crate alloc;
// ------------------------------------------------------------------------------------------------
// Modules
// ------------------------------------------------------------------------------------------------
pub mod error;
pub use error::Error;
pub mod iri;
pub use iri::{Iri, IriExtra, IriRef};
pub mod map;
pub use map::IriPrefixMap;
pub mod pname;
pub use pname::{LocalName, Name, Namespace, PrefixedName};
pub mod vocab;
pub use vocab::Vocabulary;