Skip to content
Draft
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
26 changes: 26 additions & 0 deletions THIRD-PARTY-NOTICES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -1697,3 +1697,29 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License notice for Touki
------------------------

https://github.com/JeremyKuhne/touki/tree/74f6739ce8e70b760814e792c79a83fd5065c9d7

MIT License

Copyright (c) 2025 Jeremy W. Kuhne and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<_Net8TargetFramework Condition="'$(NetCoreAppCurrent)' != 'net8.0' and '$(NetCoreAppPrevious)' != 'net8.0' and '$(NetCoreAppMinimum)' != 'net8.0'">net8.0;</_Net8TargetFramework>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);$(_Net8TargetFramework)netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ private DirectoryInfoWrapper(DirectoryInfo directoryInfo, bool isParentPath)
_isParentPath = isParentPath;
}

#if USE_TOUKI_GLOBBING
internal DirectoryInfo DirectoryInfo => _directoryInfo;
#endif

/// <inheritdoc />
public override IEnumerable<FileSystemInfoBase> EnumerateFileSystemInfos()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public override void PushDirectory(DirectoryInfoBase directory)
{
// Determine this frame's contribution to the stem (if any)
IPathSegment segment = Pattern.Segments[Frame.SegmentIndex];
#if USE_TOUKI_GLOBBING
if (TrackStem && (frame.InStem || segment.CanProduceStem))
#else
if (frame.InStem || segment.CanProduceStem)
#endif
{
frame.InStem = true;
frame.StemItems.Add(directory.Name);
Expand Down Expand Up @@ -93,6 +97,10 @@ public struct FrameData

protected ILinearPattern Pattern { get; }

#if USE_TOUKI_GLOBBING
internal bool TrackStem { get; set; } = true;
#endif

protected bool IsLastSegment()
{
return Frame.SegmentIndex == Pattern.Segments.Count - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public sealed override void PushDirectory(DirectoryInfoBase directory)
frame.BacktrackAvailable += 1;
}

#if USE_TOUKI_GLOBBING
if (TrackStem && frame.InStem)
#else
if (frame.InStem)
#endif
{
frame.StemItems.Add(directory.Name);
frame.AddedStemItem = true;
Expand Down Expand Up @@ -140,6 +144,10 @@ public struct FrameData

protected IRaggedPattern Pattern { get; }

#if USE_TOUKI_GLOBBING
internal bool TrackStem { get; set; } = true;
#endif

protected bool IsStartingGroup()
{
return Frame.SegmentGroupIndex == -1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Copyright (c) 2025 Jeremy W Kuhne
// SPDX-License-Identifier: MIT
// See LICENSE file in the project root for full license information

global using System;
global using System.Buffers;
global using System.Collections.Generic;
global using System.Diagnostics;
global using System.Diagnostics.CodeAnalysis;
global using System.IO;
global using System.Runtime.CompilerServices;
global using System.Text;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Copyright (c) 2025 Jeremy W Kuhne
// SPDX-License-Identifier: MIT
// See LICENSE file in the project root for full license information

namespace Touki.Io;

using Microsoft.Extensions.FileSystemGlobbing.Internal;

internal sealed class ExclusionWinsPatternMatcher
{
private readonly ToukiPattern[] _includes;
private readonly ToukiPattern[] _excludes;

public ExclusionWinsPatternMatcher(ToukiPattern[] includes, ToukiPattern[] excludes)
{
_includes = includes;
_excludes = excludes;
}

internal bool TryMatchFile(
ReadOnlySpan<char> currentDirectory,
ReadOnlySpan<char> fileName,
[NotNullWhen(true)] out ToukiPattern? matchingInclude)
{
matchingInclude = null;
foreach (ToukiPattern matcher in _includes)
{
if (matcher.MatchesFile(currentDirectory, fileName))
{
matchingInclude = matcher;
break;
}
}

if (matchingInclude is null)
{
return false;
}

foreach (ToukiPattern matcher in _excludes)
{
if (matcher.MatchesFile(currentDirectory, fileName))
{
matchingInclude = null;
return false;
}
}

return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Copyright (c) 2025 Jeremy W Kuhne
// SPDX-License-Identifier: MIT
// See LICENSE file in the project root for full license information

namespace Touki.Io.Globbing;

// <summary>
// Matches any input. Used for a single-segment <c>*</c> and whole-pattern
// recursive <c>**</c> after the factory has applied the appropriate root scope.
// </summary>
internal sealed class AnyGlobStrategy : GlobStrategy
{
public AnyGlobStrategy()
: base(ignoreCase: false)
{
}

// <inheritdoc/>
internal override bool MatchCore(
ReadOnlySpan<char> directoryPrefix,
ReadOnlySpan<char> fileName)
=> true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Copyright (c) 2025 Jeremy W Kuhne
// SPDX-License-Identifier: MIT
// See LICENSE file in the project root for full license information

namespace Touki.Io.Globbing;

internal sealed partial class CompiledGlobStrategy
{
// <summary>
// Mutable matcher state passed by reference into <see cref="Backtrack"/> instead of
// individual <c>ref int</c> parameters. Cuts <see cref="Backtrack"/>'s argument list
// from ten to three, which on net481 RyuJIT measurably reduces call-site overhead and
// improves inlining behavior. Holds the active program/input cursors plus both
// savepoint slots (AnyRun and GlobStar) and the per-GlobStar invariants.
// </summary>
private ref struct BacktrackState
{
public int ProgramIndex;
public int InputIndex;
public int AnyRunProgramIndex;
public int AnyRunInputIndex;
public int GlobStarProgramIndex;
public int GlobStarInputIndex;
public int GlobStarInitialInput;
public int GlobStarFlags;
}
}
Loading
Loading