Skip to content

Commit

Permalink
Applied quality suggestions from Rider
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesalvo committed Feb 11, 2025
1 parent 72a4a66 commit 457b22f
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 88 deletions.
14 changes: 7 additions & 7 deletions RDFSharp/Model/RDFModelUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal static Uri GetUriFromString(string uriString)
// blank node detection and normalization
if (uriString?.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase) ?? false)
uriString = string.Concat("bnode:", uriString.Substring(6));
else if (uriString?.StartsWith("_:") ?? false)
else if (uriString?.StartsWith("_:", StringComparison.Ordinal) ?? false)
uriString = string.Concat("bnode:", uriString.Substring(2));

Uri.TryCreate(uriString, UriKind.Absolute, out Uri tempUri);
Expand Down Expand Up @@ -188,7 +188,7 @@ internal static string TrimEnd(this string source, string value)
{
if (string.IsNullOrEmpty(source)
|| string.IsNullOrEmpty(value)
|| !source.EndsWith(value))
|| !source.EndsWith(value, StringComparison.Ordinal))
return source;

return source.Remove(source.LastIndexOf(value, StringComparison.Ordinal));
Expand Down Expand Up @@ -527,13 +527,13 @@ internal static List<RDFNamespace> GetGraphNamespaces(RDFGraph graph)
: string.Empty;

//Resolve subject Uri
result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => subj.StartsWith(ns.ToString())));
result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => subj.StartsWith(ns.ToString(), StringComparison.Ordinal)));

//Resolve predicate Uri
result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => pred.StartsWith(ns.ToString())));
result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => pred.StartsWith(ns.ToString(), StringComparison.Ordinal)));

//Resolve object Uri
result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => obj.StartsWith(ns.ToString())));
result.AddRange(RDFNamespaceRegister.Instance.Register.Where(ns => obj.StartsWith(ns.ToString(), StringComparison.Ordinal)));
}
return result.Distinct().ToList();
}
Expand Down Expand Up @@ -593,8 +593,8 @@ internal static (bool,string) ValidateTypedLiteral(string literalValue, RDFModel
catch { return (false, literalValue); }

case RDFModelEnums.RDFDatatypes.RDF_JSON:
bool isValidJson = (literalValue.StartsWith("{") && literalValue.EndsWith("}"))
|| (literalValue.StartsWith("[") && literalValue.EndsWith("]"));
bool isValidJson = (literalValue.StartsWith("{", StringComparison.Ordinal) && literalValue.EndsWith("}", StringComparison.Ordinal))
|| (literalValue.StartsWith("[", StringComparison.Ordinal) && literalValue.EndsWith("]", StringComparison.Ordinal));
return (isValidJson, literalValue);

case RDFModelEnums.RDFDatatypes.XSD_ANYURI:
Expand Down
18 changes: 9 additions & 9 deletions RDFSharp/Model/Serializers/RDFNTriples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext)
ntriple = ntriple.Trim(trimmableChars);

//Skip empty or comment lines
if (ntriple == string.Empty || ntriple.StartsWith("#"))
if (ntriple == string.Empty || ntriple.StartsWith("#", StringComparison.Ordinal))
continue;

//Tokenizes the sanitized triple
Expand All @@ -244,9 +244,9 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext)
#endregion

#region object
if (tokens[2].StartsWith("<")
|| tokens[2].StartsWith("bnode:")
|| tokens[2].StartsWith("_:"))
if (tokens[2].StartsWith("<", StringComparison.Ordinal)
|| tokens[2].StartsWith("bnode:", StringComparison.OrdinalIgnoreCase)
|| tokens[2].StartsWith("_:", StringComparison.Ordinal))
{
string obj = tokens[2].TrimStart(openingBrackets)
.TrimEnd(closingBrackets)
Expand Down Expand Up @@ -274,13 +274,13 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext)

#region plain literal
if (!tokens[2].Contains("^^")
|| tokens[2].EndsWith("^^")
|| tokens[2].EndsWith("^^", StringComparison.Ordinal)
|| tokens[2].Substring(tokens[2].LastIndexOf("^^", StringComparison.Ordinal) + 2, 1) != "<")
{
if (regexLPL.Value.Match(tokens[2]).Success)
{
tokens[2] = tokens[2].Replace("\"@", "@");
int lastIndexOfLanguage = tokens[2].LastIndexOf("@", StringComparison.OrdinalIgnoreCase);
int lastIndexOfLanguage = tokens[2].LastIndexOf("@", StringComparison.Ordinal);
string pLitValue = tokens[2].Substring(0, lastIndexOfLanguage);
string pLitLang = tokens[2].Substring(lastIndexOfLanguage + 1);
L = new RDFPlainLiteral(HttpUtility.HtmlDecode(pLitValue), pLitLang);
Expand All @@ -294,7 +294,7 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext)
else
{
tokens[2] = tokens[2].Replace("\"^^", "^^");
int lastIndexOfDatatype = tokens[2].LastIndexOf("^^", StringComparison.OrdinalIgnoreCase);
int lastIndexOfDatatype = tokens[2].LastIndexOf("^^", StringComparison.Ordinal);
string tLitValue = tokens[2].Substring(0, lastIndexOfDatatype);
string tLitDatatype = tokens[2].Substring(lastIndexOfDatatype + 2)
.TrimStart('<')
Expand Down Expand Up @@ -332,13 +332,13 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext)
private static string[] TokenizeNTriple(string ntriple)
{
//A legal N-Triple starts with "_:" (blank) or "<" (uri)
if (!ntriple.StartsWith("_:") && !ntriple.StartsWith("<"))
if (!ntriple.StartsWith("_:", StringComparison.Ordinal) && !ntriple.StartsWith("<", StringComparison.Ordinal))
throw new Exception("found illegal N-Triple, must start with \"_:\" or with \"<\"");

string[] tokens = new string[3];

//S->-> triple
if (ntriple.StartsWith("<"))
if (ntriple.StartsWith("<", StringComparison.Ordinal))
{
//S->P->O
if (SPO.Value.Match(ntriple).Success)
Expand Down
4 changes: 2 additions & 2 deletions RDFSharp/Model/Serializers/RDFTriX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ internal static void ParseTriXTriple(RDFGraph result, XmlNode graphChild, Dictio
//Sanitize eventual blank node value
if (graphChild.ChildNodes[0].Name.Equals("id", StringComparison.Ordinal))
{
if (!graphChild.ChildNodes[0].InnerText.StartsWith("bnode:"))
if (!graphChild.ChildNodes[0].InnerText.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase))
graphChild.ChildNodes[0].InnerText = string.Concat("bnode:", graphChild.ChildNodes[0].InnerText.Replace("_:", string.Empty));
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ internal static void ParseTriXTriple(RDFGraph result, XmlNode graphChild, Dictio
//Sanitize eventual blank node value
if (graphChild.ChildNodes[2].Name.Equals("id", StringComparison.Ordinal))
{
if (!graphChild.ChildNodes[2].InnerText.StartsWith("bnode:"))
if (!graphChild.ChildNodes[2].InnerText.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase))
graphChild.ChildNodes[2].InnerText = string.Concat("bnode:", graphChild.ChildNodes[2].InnerText.Replace("_:", string.Empty));
}

Expand Down
12 changes: 6 additions & 6 deletions RDFSharp/Model/Serializers/RDFTurtle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,14 @@ internal static void ParseStatement(string turtleData, RDFTurtleContext turtleCo
} while (sb.Length < 8);

string directive = sb.ToString();
if (directive.StartsWith("@")
|| directive.Equals("prefix", StringComparison.InvariantCultureIgnoreCase)
|| directive.Equals("base", StringComparison.InvariantCultureIgnoreCase))
if (directive.StartsWith("@", StringComparison.Ordinal)
|| directive.Equals("prefix", StringComparison.OrdinalIgnoreCase)
|| directive.Equals("base", StringComparison.OrdinalIgnoreCase))
{
ParseDirective(turtleData, turtleContext, result, directive);
SkipWhitespace(turtleData, turtleContext);
// Turtle @base and @prefix directives MUST end with "."
if (directive.StartsWith("@"))
if (directive.StartsWith("@", StringComparison.Ordinal))
VerifyCharacterOrFail(turtleContext, ReadCodePoint(turtleData, turtleContext), ".");
// SPARQL BASE and PREFIX directives MUST NOT end with "."
else
Expand Down Expand Up @@ -963,8 +963,8 @@ internal static object ParseQNameOrBoolean(string turtleData, RDFTurtleContext t
{
// prefix may actually be a boolean value
string value = prefix.ToString();
if (value.Equals("true", StringComparison.InvariantCultureIgnoreCase)
|| value.Equals("false", StringComparison.InvariantCultureIgnoreCase))
if (value.Equals("true", StringComparison.OrdinalIgnoreCase)
|| value.Equals("false", StringComparison.OrdinalIgnoreCase))
{
UnreadCodePoint(turtleContext, bufChar);
return new RDFTypedLiteral(value, RDFModelEnums.RDFDatatypes.XSD_BOOLEAN);
Expand Down
25 changes: 13 additions & 12 deletions RDFSharp/Model/Serializers/RDFXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ internal static void Serialize(RDFGraph graph, Stream outputStream)
//<rdf:Description rdf:nodeID="blankID">
XmlAttribute subjNodeDesc;
XmlText subjNodeDescText;
if (triplesGroup.Key.StartsWith("bnode:", StringComparison.Ordinal))
if (triplesGroup.Key.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase))
{
subjNodeDescText = rdfDoc.CreateTextNode(triplesGroup.Key.Replace("bnode:", string.Empty));
subjNodeDesc = rdfDoc.CreateAttribute("rdf:nodeID", RDFVocabulary.RDF.BASE_URI);
Expand Down Expand Up @@ -250,7 +250,7 @@ internal static void Serialize(RDFGraph graph, Stream outputStream)
XmlNode collElementToAppend = rdfDoc.CreateNode(XmlNodeType.Element, "rdf:Description", RDFVocabulary.RDF.BASE_URI);
XmlAttribute collElementAttr;
XmlText collElementAttrText;
if (collElement.CollectionValue.ToString().StartsWith("bnode:", StringComparison.Ordinal))
if (collElement.CollectionValue.ToString().StartsWith("bnode:", StringComparison.OrdinalIgnoreCase))
{
collElementAttrText = rdfDoc.CreateTextNode(collElement.CollectionValue.ToString().Replace("bnode:", string.Empty));
collElementAttr = rdfDoc.CreateAttribute("rdf:nodeID", RDFVocabulary.RDF.BASE_URI);
Expand Down Expand Up @@ -280,7 +280,7 @@ internal static void Serialize(RDFGraph graph, Stream outputStream)
XmlAttribute predNodeDesc;
XmlText predNodeDescText;
// rdf:nodeID="blankID">
if (objString.StartsWith("bnode:"))
if (objString.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase))
{
predNodeDescText = rdfDoc.CreateTextNode(objString.Replace("bnode:", string.Empty));
predNodeDesc = rdfDoc.CreateAttribute("rdf:nodeID", RDFVocabulary.RDF.BASE_URI);
Expand Down Expand Up @@ -526,8 +526,9 @@ private static List<RDFResource> ParseNodeList(XmlNodeList nodeList, RDFGraph re
if (predNode.NamespaceURI == string.Empty)
pred = new RDFResource(string.Concat(xmlBase, predNode.LocalName), hashContext);
else
pred = predNode.LocalName.StartsWith("autoNS") ? new RDFResource(predNode.NamespaceURI, hashContext)
: new RDFResource(string.Concat(predNode.NamespaceURI, predNode.LocalName), hashContext);
pred = predNode.LocalName.StartsWith("autoNS", StringComparison.OrdinalIgnoreCase)
? new RDFResource(predNode.NamespaceURI, hashContext)
: new RDFResource(string.Concat(predNode.NamespaceURI, predNode.LocalName), hashContext);
#endregion

#region objList
Expand Down Expand Up @@ -760,7 +761,7 @@ private static List<RDFNamespace> GetAutomaticNamespaces(RDFGraph graph)
//Check if the predicate can be abbreviated to a valid QName
if (!string.Equals(nspace.NamespaceUri.ToString(), pred))
{
if (nspace.NamespacePrefix.StartsWith("autoNS") && !result.Contains(nspace))
if (nspace.NamespacePrefix.StartsWith("autoNS", StringComparison.OrdinalIgnoreCase) && !result.Contains(nspace))
result.Add(new RDFNamespace(string.Concat("autoNS", (result.Count + 1).ToString()), nspace.NamespaceUri.ToString()));
}
else
Expand Down Expand Up @@ -815,19 +816,19 @@ private static string ResolveRelativeNode(XmlAttribute attr, Uri xmlBase)
string xmlBaseString = xmlBase.ToString();

//Adjust corner case for clashes on namespace ending characters ("#", "/")
if (xmlBaseString.EndsWith("#") && attrValue.StartsWith("#"))
if (xmlBaseString.EndsWith("#", StringComparison.Ordinal) && attrValue.StartsWith("#", StringComparison.Ordinal))
attrValue = attrValue.TrimStart('#');
if (xmlBaseString.EndsWith("/") && attrValue.StartsWith("/"))
if (xmlBaseString.EndsWith("/", StringComparison.Ordinal) && attrValue.StartsWith("/", StringComparison.Ordinal))
attrValue = attrValue.TrimStart('/');

//"rdf:ID" relative Uri: must be resolved against the xmlBase namespace
if (string.Equals(attr.LocalName, "rdf:ID", StringComparison.OrdinalIgnoreCase)
|| string.Equals(attr.LocalName, "ID", StringComparison.OrdinalIgnoreCase))
{
//This kind of syntax requires the attribute value to start with "#"
if (!attrValue.StartsWith("#"))
if (!attrValue.StartsWith("#", StringComparison.Ordinal))
attrValue = string.Concat("#", attrValue);
if (xmlBaseString.EndsWith("#"))
if (xmlBaseString.EndsWith("#", StringComparison.Ordinal))
xmlBaseString = xmlBaseString.TrimEnd('#');
attrValue = RDFModelUtilities.GetUriFromString(string.Concat(xmlBaseString, attrValue)).ToString();
}
Expand All @@ -836,7 +837,7 @@ private static string ResolveRelativeNode(XmlAttribute attr, Uri xmlBase)
else if (string.Equals(attr.LocalName, "rdf:nodeID", StringComparison.OrdinalIgnoreCase)
|| string.Equals(attr.LocalName, "nodeID", StringComparison.OrdinalIgnoreCase))
{
if (!attrValue.StartsWith("bnode:"))
if (!attrValue.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase))
attrValue = string.Concat("bnode:", attrValue);
}

Expand Down Expand Up @@ -1090,7 +1091,7 @@ private static void ParseContainerElements(RDFModelEnums.RDFContainerTypes contT
//Sanitize eventual blank node value detected by presence of "nodeID" attribute
if (string.Equals(elemUri.LocalName, "nodeID", StringComparison.OrdinalIgnoreCase))
{
if (!elemUri.Value.StartsWith("bnode:"))
if (!elemUri.Value.StartsWith("bnode:", StringComparison.OrdinalIgnoreCase))
elemUri.Value = string.Concat("bnode:", elemUri.Value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class RDFBooleanExpression : RDFExpression
/// <summary>
/// Default-ctor to build a boolean expression with given arguments
/// </summary>
public RDFBooleanExpression(RDFExpression leftArgument, RDFExpression rightArgument)
protected RDFBooleanExpression(RDFExpression leftArgument, RDFExpression rightArgument)
: base(leftArgument, rightArgument)
{
#region Guards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public abstract class RDFDateTimeExpression : RDFExpression
/// <summary>
/// Default-ctor to build a datetime day expression with given arguments
/// </summary>
public RDFDateTimeExpression(RDFExpression leftArgument) : base(leftArgument, null as RDFExpression) { }
protected RDFDateTimeExpression(RDFExpression leftArgument) : base(leftArgument, null as RDFExpression) { }

/// <summary>
/// Default-ctor to build a datetime day expression with given arguments
/// </summary>
public RDFDateTimeExpression(RDFVariable leftArgument) : base(leftArgument, null as RDFExpression) { }
protected RDFDateTimeExpression(RDFVariable leftArgument) : base(leftArgument, null as RDFExpression) { }
#endregion

#region Interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public abstract class RDFGeoExpression : RDFExpression
/// <summary>
/// Default-ctor to build a geographic expression with given arguments
/// </summary>
public RDFGeoExpression(RDFExpressionArgument leftArgument, RDFExpressionArgument rightArgument)
protected RDFGeoExpression(RDFExpressionArgument leftArgument, RDFExpressionArgument rightArgument)
: base(leftArgument, rightArgument) { }
#endregion

Expand Down
Loading

0 comments on commit 457b22f

Please sign in to comment.