Skip to content

Commit

Permalink
use IsMatch() instead of Matches()
Browse files Browse the repository at this point in the history
  • Loading branch information
anamnavi committed Dec 3, 2024
1 parent 80d568f commit 8e9e789
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions src/code/LocalServerApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,17 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu

// this regex pattern matches packageName followed by a version (4 digit or 3 with prerelease word)
string regexPattern = $"{packageName}" + @"(\.\d+){1,3}(?:[a-zA-Z0-9-.]+|.\d)?\.nupkg";
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
_cmdletPassedIn.WriteDebug($"package file name pattern to be searched for is: {regexPattern}");

foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath))
{
string packageFullName = Path.GetFileName(path);
MatchCollection matches = rx.Matches(packageFullName);
if (matches.Count == 0)
{
continue;
}

Match match = matches[0];

GroupCollection groups = match.Groups;
if (groups.Count == 0)
bool isMatch = Regex.IsMatch(packageFullName, regexPattern, RegexOptions.IgnoreCase);
if (!isMatch)
{
continue;
}

Capture group = groups[0];

NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord);
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'");

Expand Down Expand Up @@ -389,30 +378,19 @@ private FindResults FindVersionHelper(string packageName, string version, string

// this regex pattern matches packageName followed by the requested version
string regexPattern = $"{packageName}.{requiredVersion.ToNormalizedString()}" + @".nupkg";
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
_cmdletPassedIn.WriteDebug($"pattern is: {regexPattern}");
string pkgPath = String.Empty;
string actualPkgName = String.Empty;

foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath))
{
string packageFullName = Path.GetFileName(path);
MatchCollection matches = rx.Matches(packageFullName);
if (matches.Count == 0)
{
continue;
}

Match match = matches[0];

GroupCollection groups = match.Groups;
if (groups.Count == 0)
bool isMatch = Regex.IsMatch(packageFullName, regexPattern, RegexOptions.IgnoreCase);
if (!isMatch)
{
continue;
}

Capture group = groups[0];

NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord);
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'");

Expand Down

0 comments on commit 8e9e789

Please sign in to comment.