Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use char base startswith and endswith #10341

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Docfx.Build.OverwriteDocuments/OverwriteUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static List<OPathSegment> ParseOPath(string OPathString)
throw new ArgumentException("OPathString cannot be null or empty.", nameof(OPathString));
}

if (OPathString.EndsWith("/", StringComparison.Ordinal))
if (OPathString.EndsWith('/'))
{
throw new ArgumentException($"{OPathString} is not a valid OPath");
}
Expand All @@ -39,7 +39,7 @@ public static List<OPathSegment> ParseOPath(string OPathString)
throw new ArgumentException($"{OPathString} is not a valid OPath");
}

if (!match.Value.EndsWith("/", StringComparison.Ordinal) && match.Groups["key"].Success)
if (!match.Value.EndsWith('/') && match.Groups["key"].Success)
{
throw new ArgumentException($"{OPathString} is not a valid OPath");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.RestApi/RestApiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static SwaggerFormattedReference FormatReferenceFullPath(string reference
}

// Not decode for JSON String Representation
if (reference.StartsWith("/", StringComparison.Ordinal))
if (reference.StartsWith('/'))
{
return new SwaggerFormattedReference
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build.SchemaDriven/Processors/HrefInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public object Interpret(BaseSchema schema, object value, IProcessContext context
}

// "/" is also considered as absolute to us
if (uri.IsAbsoluteUri || val.StartsWith("/", StringComparison.Ordinal))
if (uri.IsAbsoluteUri || val.StartsWith('/'))
{
return Helper.RemoveHostName(val, _siteHostName);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build/DocumentBuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ from u in parameters.XRefMaps
if (!string.IsNullOrEmpty(versionDir))
{
versionDir = versionDir.Replace('\\', '/');
if (!versionDir.EndsWith("/", StringComparison.Ordinal))
if (!versionDir.EndsWith('/'))
{
versionDir += "/";
}
Expand Down Expand Up @@ -95,7 +95,7 @@ from u in xrefMaps
if (!string.IsNullOrEmpty(versionFolder))
{
versionFolder = versionFolder.Replace('\\', '/');
if (!versionFolder.EndsWith("/", StringComparison.Ordinal))
if (!versionFolder.EndsWith('/'))
{
versionFolder += "/";
}
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build/FileCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public void Add(DocumentType type, string baseDir, IEnumerable<string> files, st
throw new ArgumentException("DestinationDir must start with BaseDir, or relative path.", nameof(destinationDir));
}
}
if (!string.IsNullOrEmpty(sourceDir) && !sourceDir.EndsWith("/", StringComparison.Ordinal))
if (!string.IsNullOrEmpty(sourceDir) && !sourceDir.EndsWith('/'))
{
sourceDir += "/";
}
if (!string.IsNullOrEmpty(destinationDir) && !destinationDir.EndsWith("/", StringComparison.Ordinal))
if (!string.IsNullOrEmpty(destinationDir) && !destinationDir.EndsWith('/'))
{
destinationDir += "/";
}
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build/PostProcessors/SitemapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Manifest Process(Manifest manifest, string outputFolder, CancellationToke
return manifest;
}

if (!manifest.Sitemap.BaseUrl.EndsWith("/", StringComparison.Ordinal))
if (!manifest.Sitemap.BaseUrl.EndsWith('/'))
{
manifest.Sitemap.BaseUrl += '/';
}
Expand Down Expand Up @@ -105,7 +105,7 @@ private static SitemapElementOptions GetOptions(SitemapOptions rootOptions, stri
}
else
{
if (!options.BaseUrl.EndsWith("/", StringComparison.Ordinal))
if (!options.BaseUrl.EndsWith('/'))
{
options.BaseUrl += '/';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Common/FileAbstractLayer/RealFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public RealFileReader(string inputFolder)
throw new DirectoryNotFoundException($"Directory ({inputFolder}) not found.");
}
if (inputFolder.Length > 0 &&
!inputFolder.EndsWith("\\", StringComparison.Ordinal) &&
!inputFolder.EndsWith("/", StringComparison.Ordinal))
!inputFolder.EndsWith('\\') &&
!inputFolder.EndsWith('/'))
{
inputFolder += "/";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Common/YamlMime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class YamlMime
ArgumentNullException.ThrowIfNull(reader);

var line = reader.ReadLine();
if (line == null || !line.StartsWith("#", StringComparison.Ordinal))
if (line == null || !line.StartsWith('#'))
{
return null;
}
Expand Down
15 changes: 5 additions & 10 deletions src/Docfx.Glob/GlobMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static IEnumerable<string> Split(string path, params char[] splitter)
yield return parts[i] + "/";
}

yield return path.EndsWith("/", StringComparison.Ordinal) ? parts[parts.Length - 1] + "/" : parts[parts.Length - 1];
yield return path.EndsWith('/') ? parts[parts.Length - 1] + "/" : parts[parts.Length - 1];
}

private string ConvertSingleGlob(IEnumerable<GlobRegexItem> regexItems)
Expand All @@ -148,7 +148,7 @@ private string ConvertSingleGlob(IEnumerable<GlobRegexItem> regexItems)

private static bool IsFolderPath(string path)
{
return path.EndsWith("/", StringComparison.Ordinal);
return path.EndsWith('/');
}

/// <summary>
Expand Down Expand Up @@ -406,14 +406,9 @@ private bool MatchOne(string[] fileParts, GlobRegexItem[] globParts, bool matchP

private bool DisallowedMatchExists(string filePart)
{
if (filePart == "."
|| filePart == ".."
|| (!_allowDotMatch && filePart.StartsWith(".", StringComparison.Ordinal)))
{
return true;
}

return false;
return filePart == "."
|| filePart == ".."
|| (!_allowDotMatch && filePart.StartsWith('.'));
}

private static string UnescapeGlob(string s)
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.MarkdigEngine/MarkdigMarkdownService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private MarkdownPipeline CreateMarkdownPipeline(bool isInline, bool multipleYaml

private static string GetLink(string path, MarkdownObject origin)
{
if (InclusionContext.IsInclude && RelativePath.IsRelativePath(path) && PathUtility.IsRelativePath(path) && !RelativePath.IsPathFromWorkingFolder(path) && !path.StartsWith("#", StringComparison.Ordinal))
if (InclusionContext.IsInclude && RelativePath.IsRelativePath(path) && PathUtility.IsRelativePath(path) && !RelativePath.IsPathFromWorkingFolder(path) && !path.StartsWith('#'))
{
return ((RelativePath)InclusionContext.File + (RelativePath)path).GetPathFromWorkingFolder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ static bool NeedQuote(object val)
|| Regexes.NullLike.IsMatch(s)
|| Regexes.IntegerLike.IsMatch(s)
|| Regexes.FloatLike.IsMatch(s)
|| s.StartsWith("'", StringComparison.Ordinal)
|| s.StartsWith("\"", StringComparison.Ordinal)
|| s.StartsWith('\'')
|| s.StartsWith('"')
|| s.Length > 0 && char.IsWhiteSpace(s[0]);
}
}
Expand Down