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

Initial code #1

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "nuget"
directory: "/src"
schedule:
interval: "weekly"
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
40 changes: 40 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish package
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET SDKs
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Verify commit exists in origin/main
run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
git branch --remote --contains | grep origin/main

- name: Set VERSION variable from tag
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV

- name: Build
run: dotnet build --configuration Release /p:Version=${VERSION}

- name: Test
run: dotnet test --configuration Release /p:Version=${VERSION} --no-build

- name: Pack
run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output .

- name: Push
run: dotnet nuget push Anexia.Gregex.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_TOKEN}
env:
NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.DotSettings.user
.idea
**\bin
**\obj
13 changes: 2 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [x.y.z] - YYYY-MM-DD
## [0.0.1] - 2024-10-25

### Added
- Lorem ipsum dolor sit amet

### Deprecated
- Nothing.

### Removed
- Nothing.

### Fixed
- Nothing.
- Initial release with basic matchers.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018 ANEXIA Internetdienstleisungs GmbH
Copyright (c) 2024 ANEXIA Internetdienstleisungs GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
## PROJECT NAME
## Anexia.Gregex

A short description of what this project does.
Generalized regular expressions for sequences (IEnumerables, Lists, Arrays).

## Goals

It is a good idea to provide a mission statement for your project, enshrining
what the project wants to accomplish so that as more people join your project
everyone can work in alignment.
Provide an API to match lists similar to how you can match regexes against strings.

### Installation
### Usage

Instructions for how to download/install the code onto your machine.
The main entry point is the ```Gregex``` class it allows you to construct expressions. You can use the
Matcher class to match these expressions against instances of IEnumerable.

Example:
```
./install myProject --save
```
using Anexia.Gregex;

### Usage
var testList = "FooBarFooBarFoo".ToCharArray();

Usage instructions for your code.
var gregex = Gregex.Is('o').Times(2);

Example:
var matcher = new Matcher<char>();

```
var myMod = require('mymodule');
var matches = matcher.FindMatches(gregex, testList).ToArray();

myMod.foo('hi');
Console.WriteLine($"Found: {matches.Length} matches.");
Console.WriteLine(string.Join("\n", matches.AsEnumerable()));
```

You can find more detailed examples in the [Examples Folder](examples).

### Contributing

Contributions are welcomed! Read the [Contributing Guide](CONTRIBUTING.md) for more information.
Expand Down
39 changes: 39 additions & 0 deletions dotnetcore-gregex.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Anexia.Gregex", "src\Anexia.Gregex\Anexia.Gregex.csproj", "{07B62AC7-BCE4-4A20-8A0F-6EE1152F90E0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DB20A418-DCE6-457F-BF75-CC36CE1E8D25}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{471DF611-07A8-4581-9297-110580DBCC4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Anexia.Gregex.Test", "test\Anexia.Gregex.Test\Anexia.Gregex.Test.csproj", "{905349B3-4F44-4EE9-AEFB-7E24967AF0B5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{9799FB17-155A-4CCC-A6A3-5FC365CEED3F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Anexia.Gregex.Examples", "examples\Anexia.Gregex.Examples\Anexia.Gregex.Examples.csproj", "{166B6342-8E5E-4C5F-90DF-F6DB456BA573}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07B62AC7-BCE4-4A20-8A0F-6EE1152F90E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07B62AC7-BCE4-4A20-8A0F-6EE1152F90E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07B62AC7-BCE4-4A20-8A0F-6EE1152F90E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07B62AC7-BCE4-4A20-8A0F-6EE1152F90E0}.Release|Any CPU.Build.0 = Release|Any CPU
{905349B3-4F44-4EE9-AEFB-7E24967AF0B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{905349B3-4F44-4EE9-AEFB-7E24967AF0B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{905349B3-4F44-4EE9-AEFB-7E24967AF0B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{905349B3-4F44-4EE9-AEFB-7E24967AF0B5}.Release|Any CPU.Build.0 = Release|Any CPU
{166B6342-8E5E-4C5F-90DF-F6DB456BA573}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{166B6342-8E5E-4C5F-90DF-F6DB456BA573}.Debug|Any CPU.Build.0 = Debug|Any CPU
{166B6342-8E5E-4C5F-90DF-F6DB456BA573}.Release|Any CPU.ActiveCfg = Release|Any CPU
{166B6342-8E5E-4C5F-90DF-F6DB456BA573}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{07B62AC7-BCE4-4A20-8A0F-6EE1152F90E0} = {DB20A418-DCE6-457F-BF75-CC36CE1E8D25}
{905349B3-4F44-4EE9-AEFB-7E24967AF0B5} = {471DF611-07A8-4581-9297-110580DBCC4F}
{166B6342-8E5E-4C5F-90DF-F6DB456BA573} = {9799FB17-155A-4CCC-A6A3-5FC365CEED3F}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions examples/Anexia.Gregex.Examples/Anexia.Gregex.Examples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Anexia.Gregex\Anexia.Gregex.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions examples/Anexia.Gregex.Examples/AnyExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ------------------------------------------------------------------------------------------
// <copyright file = "AnyExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH">
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved.
// </copyright>
// ------------------------------------------------------------------------------------------


namespace Anexia.Gregex.Examples;

/// <summary>
/// Example for how to use the <see cref="Gregex.Any{T}"/> method for matching any element.
/// </summary>
public static class AnyExample
{
public static void Main()
{
var listOfWords = new List<string>()
{
"Hello",
"World",
"This",
"Is",
"A",
"Test",
"For",
"Any",
"Regex"
};
var anyString = Gregex.Any<string>();

var matcher = new Matcher<string>();

var matches = matcher.FindMatches(anyString, listOfWords);

Console.WriteLine(string.Join(Environment.NewLine, matches));

}
}
29 changes: 29 additions & 0 deletions examples/Anexia.Gregex.Examples/AtLeastOnceExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ------------------------------------------------------------------------------------------
// <copyright file = "AtLeastOnceExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH">
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved.
// </copyright>
// ------------------------------------------------------------------------------------------

namespace Anexia.Gregex.Examples;

/// <summary>
/// Example of how to use the <see cref="Gregex.AtLeastOnce{T}"/> method to match an element at least once.
/// </summary>
public static class AtLeastOnceExample
{
public static void Main()
{
var listOfStringWithOneStringRepeated = new List<string>()
{
"Hello", "World", "Hello", "Hello", "Hello"
};

var atLeastOneHello = Gregex.Is("Hello").AtLeastOnce();

var matcher = new Matcher<string>();

var matches = matcher.FindMatches(atLeastOneHello, listOfStringWithOneStringRepeated);

Console.WriteLine(string.Join(Environment.NewLine, matches));
}
}
31 changes: 31 additions & 0 deletions examples/Anexia.Gregex.Examples/FollowedByExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ------------------------------------------------------------------------------------------
// <copyright file = "FollowedByExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH">
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved.
// </copyright>
// ------------------------------------------------------------------------------------------

namespace Anexia.Gregex.Examples;

/// <summary>
/// Example of how to use the <see cref="Gregex.FollowedBy{T}"/> method to match to consecutive elements.
/// </summary>
public static class FollowedByExample
{
public static void Main()
{
var listOfWords = new List<string>
{
"This", "is", "a", "test", "of", "Gregex", "followed", "by", "a",
"example", "one", "more", "time", "and", "then",
"we'll", "see", "if", "it's", "working", "This", "is", "not", "a", "test"
};

var aTest = Gregex.Is("a").FollowedBy(Gregex.Is("test"));

var matcher = new Matcher<string>();

var matches = matcher.FindMatches(aTest, listOfWords);

Console.WriteLine(string.Join(Environment.NewLine, matches));
}
}
43 changes: 43 additions & 0 deletions examples/Anexia.Gregex.Examples/IsExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ------------------------------------------------------------------------------------------
// <copyright file = "IsExample.cs" company = "ANEXIA® Internetdienstleistungs GmbH">
// Copyright (c) ANEXIA® Internetdienstleistungs GmbH. All rights reserved.
// </copyright>
// ------------------------------------------------------------------------------------------

namespace Anexia.Gregex.Examples;

/// <summary>
/// Example for matching an element exactly using the <see cref="Gregex.Is{T}"/> method.
/// </summary>
public static class IsExample
{
public static void Main()
{
var listOfWords = new List<string>()
{
"Hello",
"World",
"This",
"Is",
"And",
"Test",
"Example",
"List",
"With",
"More",
"Words",
"Like",
"These",
"And",
"Those"
};

var gregex = Gregex.Is("And");

var matcher = new Matcher<string>();

var matches = matcher.FindMatches(gregex, listOfWords);

Console.WriteLine(string.Join(Environment.NewLine, matches));
}
}
Loading