-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Platforms>AnyCPU;x64</Platforms> | ||
<LangVersion>latest</LangVersion> | ||
<ServerGarbageCollection>true</ServerGarbageCollection> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<DefineConstants>TRACE;DEBUG</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<OutputPath>bin\$(Platform)\Debug\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<DefineConstants>TRACE;DEBUG</DefineConstants> | ||
<DebugType>full</DebugType> | ||
<OutputPath>bin\$(Platform)\Debug\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\$(Platform)\Release\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\$(Platform)\Release\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.8.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="CommandLineParser" Version="2.8.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\FASTER.server\FASTER.server.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\FASTER.server\FASTER.server.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
namespace FASTER.server | ||
{ | ||
/// <summary> | ||
/// Glob utils | ||
/// </summary> | ||
public static class GlobUtils | ||
{ | ||
/// <summary> | ||
/// Glob-style pattern matching | ||
/// </summary> | ||
/// <returns>Whether match was found</returns> | ||
public static unsafe bool Match(byte* pattern, int patternLen, byte* key, int stringLen, bool nocase = false) | ||
{ | ||
while (patternLen > 0 && stringLen > 0) | ||
{ | ||
switch (pattern[0]) | ||
{ | ||
case (byte)'*': | ||
while (patternLen > 0 && pattern[1] == '*') | ||
{ | ||
pattern++; | ||
patternLen--; | ||
} | ||
if (patternLen == 1) | ||
return true; /* match */ | ||
while (stringLen > 0) | ||
{ | ||
if (Match(pattern + 1, patternLen - 1, key, stringLen, nocase)) | ||
return true; /* match */ | ||
key++; | ||
stringLen--; | ||
} | ||
return false; /* no match */ | ||
|
||
case (byte)'?': | ||
key++; | ||
stringLen--; | ||
break; | ||
|
||
case (byte)'[': | ||
{ | ||
bool not, match; | ||
pattern++; | ||
patternLen--; | ||
not = (pattern[0] == '^'); | ||
if (not) | ||
{ | ||
pattern++; | ||
patternLen--; | ||
} | ||
match = false; | ||
while (true) | ||
{ | ||
if (pattern[0] == '\\' && patternLen >= 2) | ||
{ | ||
pattern++; | ||
patternLen--; | ||
if (pattern[0] == key[0]) | ||
match = true; | ||
} | ||
else if (pattern[0] == ']') | ||
{ | ||
break; | ||
} | ||
else if (patternLen == 0) | ||
{ | ||
pattern--; | ||
patternLen++; | ||
break; | ||
} | ||
else if (patternLen >= 3 && pattern[1] == '-') | ||
{ | ||
int start = pattern[0]; | ||
int end = pattern[2]; | ||
int c = key[0]; | ||
if (start > end) | ||
{ | ||
int t = start; | ||
start = end; | ||
end = t; | ||
} | ||
if (nocase) | ||
{ | ||
start = char.ToLower((char)start); | ||
end = char.ToLower((char)end); | ||
c = char.ToLower((char)c); | ||
} | ||
pattern += 2; | ||
patternLen -= 2; | ||
if (c >= start && c <= end) | ||
match = true; | ||
} | ||
else | ||
{ | ||
if (!nocase) | ||
{ | ||
if (pattern[0] == key[0]) | ||
match = true; | ||
} | ||
else | ||
{ | ||
if (char.ToLower((char)pattern[0]) == char.ToLower((char)key[0])) | ||
match = true; | ||
} | ||
} | ||
pattern++; | ||
patternLen--; | ||
} | ||
|
||
if (not) | ||
match = !match; | ||
if (!match) | ||
return false; /* no match */ | ||
key++; | ||
stringLen--; | ||
break; | ||
} | ||
|
||
case (byte)'\\': | ||
if (patternLen >= 2) | ||
{ | ||
pattern++; | ||
patternLen--; | ||
} | ||
goto default; | ||
|
||
/* fall through */ | ||
default: | ||
if (!nocase) | ||
{ | ||
if (pattern[0] != key[0]) | ||
return false; /* no match */ | ||
} | ||
else | ||
{ | ||
if (char.ToLower((char)pattern[0]) != char.ToLower((char)key[0])) | ||
return false; /* no match */ | ||
} | ||
key++; | ||
stringLen--; | ||
break; | ||
} | ||
pattern++; | ||
patternLen--; | ||
if (stringLen == 0) | ||
{ | ||
while (*pattern == '*') | ||
{ | ||
pattern++; | ||
patternLen--; | ||
} | ||
break; | ||
} | ||
} | ||
if (patternLen == 0 && stringLen == 0) | ||
return true; | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.