diff --git a/RDFSharp/Model/Serializers/RDFNTriples.cs b/RDFSharp/Model/Serializers/RDFNTriples.cs index 5261fa7f..f5303cdc 100644 --- a/RDFSharp/Model/Serializers/RDFNTriples.cs +++ b/RDFSharp/Model/Serializers/RDFNTriples.cs @@ -151,9 +151,9 @@ internal static void Serialize(RDFGraph graph, Stream outputStream) .Replace("\r", "\\r"); #region plain literal - if (t.Object is RDFPlainLiteral) - tripleTemplate = ((RDFPlainLiteral)t.Object).HasLanguage() ? tripleTemplate.Replace("{LANG}", ((RDFPlainLiteral)t.Object).Language) - : tripleTemplate.Replace("@{LANG}", string.Empty); + if (t.Object is RDFPlainLiteral plitObj) + tripleTemplate = plitObj.HasLanguage() ? tripleTemplate.Replace("{LANG}", plitObj.Language) + : tripleTemplate.Replace("@{LANG}", string.Empty); #endregion #region typed literal @@ -273,8 +273,8 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext) #region plain literal if (!tokens[2].Contains("^^") - || tokens[2].EndsWith("^^") - || tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<") + || tokens[2].EndsWith("^^") + || tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<") { if (regexLPL.Value.Match(tokens[2]).Success) { @@ -285,9 +285,7 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext) L = new RDFPlainLiteral(HttpUtility.HtmlDecode(pLitValue), pLitLang); } else - { L = new RDFPlainLiteral(HttpUtility.HtmlDecode(tokens[2])); - } } #endregion diff --git a/RDFSharp/Query/RDFQueryUtilities.cs b/RDFSharp/Query/RDFQueryUtilities.cs index a75c8df9..0690aaf4 100644 --- a/RDFSharp/Query/RDFQueryUtilities.cs +++ b/RDFSharp/Query/RDFQueryUtilities.cs @@ -47,10 +47,10 @@ public static RDFPatternMember ParseRDFPatternMember(string pMember) #region Plain Literal int lastIndexOfDatatype = pMember.LastIndexOf("^^", StringComparison.OrdinalIgnoreCase); if (!pMember.Contains("^^") - || pMember.EndsWith("^^") - || RDFModelUtilities.GetUriFromString(pMember.Substring(lastIndexOfDatatype + 2)) == null) + || pMember.EndsWith("^^") + || RDFModelUtilities.GetUriFromString(pMember.Substring(lastIndexOfDatatype + 2)) == null) { - RDFPlainLiteral pLit = null; + RDFPlainLiteral pLit; if (RDFNTriples.regexLPL.Value.Match(pMember).Success) { int lastIndexOfLanguage = pMember.LastIndexOf("@", StringComparison.OrdinalIgnoreCase); @@ -59,9 +59,7 @@ public static RDFPatternMember ParseRDFPatternMember(string pMember) pLit = new RDFPlainLiteral(pLitVal, pLitLng); } else - { pLit = new RDFPlainLiteral(pMember); - } return pLit; } #endregion diff --git a/RDFSharp/Store/RDFStoreUtilities.cs b/RDFSharp/Store/RDFStoreUtilities.cs index 44de1fe3..9a157502 100644 --- a/RDFSharp/Store/RDFStoreUtilities.cs +++ b/RDFSharp/Store/RDFStoreUtilities.cs @@ -54,10 +54,10 @@ public static RDFQuadruple ParseQuadruple(IDataReader fetchedQuadruples) //PlainLiteral int lastIndexOfDatatype = literal.LastIndexOf("^^", StringComparison.OrdinalIgnoreCase); if (!literal.Contains("^^") - || literal.EndsWith("^^") - || RDFModelUtilities.GetUriFromString(literal.Substring(lastIndexOfDatatype + 2)) == null) + || literal.EndsWith("^^") + || RDFModelUtilities.GetUriFromString(literal.Substring(lastIndexOfDatatype + 2)) == null) { - RDFPlainLiteral pLit = null; + RDFPlainLiteral pLit; if (RDFNTriples.regexLPL.Value.Match(literal).Success) { int lastIndexOfLanguage = literal.LastIndexOf("@", StringComparison.OrdinalIgnoreCase); diff --git a/RDFSharp/Store/Serializers/RDFNQuads.cs b/RDFSharp/Store/Serializers/RDFNQuads.cs index cf2081a6..9fca10c6 100644 --- a/RDFSharp/Store/Serializers/RDFNQuads.cs +++ b/RDFSharp/Store/Serializers/RDFNQuads.cs @@ -145,20 +145,14 @@ internal static void Serialize(RDFStore store, Stream outputStream) .Replace("\r", "\\r"); #region plain literal - if (q.Object is RDFPlainLiteral) - { - if (((RDFPlainLiteral)q.Object).Language != string.Empty) - quadrupleTemplate = quadrupleTemplate.Replace("{LANG}", ((RDFPlainLiteral)q.Object).Language); - else - quadrupleTemplate = quadrupleTemplate.Replace("@{LANG}", string.Empty); - } + if (q.Object is RDFPlainLiteral plitObj) + quadrupleTemplate = plitObj.HasLanguage() ? quadrupleTemplate.Replace("{LANG}", plitObj.Language) + : quadrupleTemplate.Replace("@{LANG}", string.Empty); #endregion #region typed literal else - { quadrupleTemplate = quadrupleTemplate.Replace("{DTYPE}", RDFModelUtilities.GetDatatypeFromEnum(((RDFTypedLiteral)q.Object).Datatype)); - } #endregion } #endregion @@ -275,8 +269,8 @@ internal static RDFMemoryStore Deserialize(Stream inputStream) #region plain literal if (!tokens[2].Contains("^^") - || tokens[2].EndsWith("^^") - || tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<") + || tokens[2].EndsWith("^^") + || tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<") { if (RDFNTriples.regexLPL.Value.Match(tokens[2]).Success) { @@ -287,9 +281,7 @@ internal static RDFMemoryStore Deserialize(Stream inputStream) L = new RDFPlainLiteral(HttpUtility.HtmlDecode(pLitValue), pLitLang); } else - { L = new RDFPlainLiteral(HttpUtility.HtmlDecode(tokens[2])); - } } #endregion