Makes oxrdf independent from rio_api

pull/190/head
Tpt 3 years ago
parent a16a4108b8
commit bdf342b825
  1. 1
      Cargo.lock
  2. 3
      lib/oxrdf/Cargo.toml
  3. 3
      lib/oxrdf/src/blank_node.rs
  4. 33
      lib/oxrdf/src/literal.rs
  5. 3
      lib/oxrdf/src/named_node.rs

1
Cargo.lock generated

@ -917,7 +917,6 @@ dependencies = [
"oxilangtag",
"oxiri",
"rand",
"rio_api",
"sophia_api",
]

@ -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]

@ -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())
}
}

@ -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<LiteralRef<'_>> 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::*;

@ -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())
}
}

Loading…
Cancel
Save