From bdf342b825a3251bdf2935ce99a4d52dde2ed476 Mon Sep 17 00:00:00 2001 From: Tpt Date: Sun, 2 Jan 2022 17:07:42 +0100 Subject: [PATCH] Makes oxrdf independent from rio_api --- Cargo.lock | 1 - lib/oxrdf/Cargo.toml | 3 +-- lib/oxrdf/src/blank_node.rs | 3 +-- lib/oxrdf/src/literal.rs | 33 +++++++++++++++++++++++---------- lib/oxrdf/src/named_node.rs | 3 +-- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index acfe722f..3e0acf32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -917,7 +917,6 @@ dependencies = [ "oxilangtag", "oxiri", "rand", - "rio_api", "sophia_api", ] diff --git a/lib/oxrdf/Cargo.toml b/lib/oxrdf/Cargo.toml index d3d86f31..23405d72 100644 --- a/lib/oxrdf/Cargo.toml +++ b/lib/oxrdf/Cargo.toml @@ -20,8 +20,7 @@ rdf-star = [] rand = "0.8" oxilangtag = "0.1" oxiri = "0.1" -rio_api = "0.6" -lasso = {version="0.6", features=["multi-threaded", "inline-more"]} +lasso = { version="0.6", features = ["multi-threaded", "inline-more"] } sophia_api = { version = "0.7", optional = true } [package.metadata.docs.rs] diff --git a/lib/oxrdf/src/blank_node.rs b/lib/oxrdf/src/blank_node.rs index 08f9de57..f9e2e730 100644 --- a/lib/oxrdf/src/blank_node.rs +++ b/lib/oxrdf/src/blank_node.rs @@ -1,5 +1,4 @@ use rand::random; -use rio_api::model as rio; use std::error::Error; use std::fmt; use std::io::Write; @@ -211,7 +210,7 @@ impl<'a> BlankNodeRef<'a> { impl fmt::Display for BlankNodeRef<'_> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - rio::BlankNode { id: self.as_str() }.fmt(f) + write!(f, "_:{}", self.as_str()) } } diff --git a/lib/oxrdf/src/literal.rs b/lib/oxrdf/src/literal.rs index e65fc71b..47ed8d07 100644 --- a/lib/oxrdf/src/literal.rs +++ b/lib/oxrdf/src/literal.rs @@ -3,9 +3,9 @@ use crate::vocab::rdf; use crate::vocab::xsd; use crate::NamedNodeRef; use oxilangtag::{LanguageTag, LanguageTagParseError}; -use rio_api::model as rio; use std::borrow::Cow; use std::fmt; +use std::fmt::Write; use std::option::Option; /// An owned RDF [literal](https://www.w3.org/TR/rdf11-concepts/#dfn-literal) @@ -437,18 +437,16 @@ impl fmt::Display for LiteralRef<'_> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { - LiteralRefContent::String(value) => rio::Literal::Simple { value }, + LiteralRefContent::String(value) => print_quoted_str(value, f), LiteralRefContent::LanguageTaggedString { value, language } => { - rio::Literal::LanguageTaggedString { value, language } + print_quoted_str(value, f)?; + write!(f, "@{}", language) + } + LiteralRefContent::TypedLiteral { value, datatype } => { + print_quoted_str(value, f)?; + write!(f, "^^{}", datatype) } - LiteralRefContent::TypedLiteral { value, datatype } => rio::Literal::Typed { - value, - datatype: rio::NamedNode { - iri: datatype.as_str(), - }, - }, } - .fmt(f) } } @@ -487,6 +485,21 @@ impl PartialEq> for Literal { } } +#[inline] +pub(crate) fn print_quoted_str(string: &str, f: &mut impl Write) -> fmt::Result { + f.write_char('"')?; + for c in string.chars() { + match c { + '\n' => f.write_str("\\n"), + '\r' => f.write_str("\\r"), + '"' => f.write_str("\\\""), + '\\' => f.write_str("\\\\"), + c => f.write_char(c), + }?; + } + f.write_char('"') +} + #[cfg(test)] mod tests { use super::*; diff --git a/lib/oxrdf/src/named_node.rs b/lib/oxrdf/src/named_node.rs index 51d98975..d81bee15 100644 --- a/lib/oxrdf/src/named_node.rs +++ b/lib/oxrdf/src/named_node.rs @@ -1,5 +1,4 @@ use oxiri::{Iri, IriParseError}; -use rio_api::model as rio; use std::fmt; /// An owned RDF [IRI](https://www.w3.org/TR/rdf11-concepts/#dfn-iri) @@ -143,7 +142,7 @@ impl<'a> NamedNodeRef<'a> { impl fmt::Display for NamedNodeRef<'_> { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - rio::NamedNode { iri: self.as_str() }.fmt(f) + write!(f, "<{}>", self.as_str()) } }