chRyNaN / pathmatch

A simple path matching utility for Kotlin Multi-platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pathmatch

A simple path matching utility for Kotlin Multi-platform.
GitHub tag (latest by date)

val matches = Path("./Example.kt") matches {
    when {
        exact("Example.kt") -> true
        glob("*/Example.kt") -> true
        regex(".*\\.kt") -> true
        else -> false
    }
}

Usage

Determine if a Path matches a Pattern

val matches = Path("./Example.kt") matches {
    when {
        exact("Example.kt") -> true
        glob("*/Example.kt") -> true
        regex(".*\\.kt") -> true
        else -> false
    }
}

Retrieve a custom result if a Path matches a Pattern

val result = Path("./Example.kt") matchResult {
    when {
        exact("Example.kt") -> getExactMatchValue()
        glob("*/Example.kt") -> getGlobMatchValue()
        regex(".*\\.kt") -> getRegexMatchValue()
        else -> null
    }
}

Using a PathMatcher directly

val pathMatcher = PathMatcher("./Example.kt")

pathMatcher matchesExactly "Example.kt"
pathMatcher matchesGlob "*/Example.kt"
pathMatcher matchesRegex ".*\\.kt"

Getting a Regex from a Glob-like pattern

val glob = Glob("*/Example.kt")

glob.matches("/Example.kt")

Building

The library is provided through Repsy.io. Checkout the releases page to get the latest version.
GitHub tag (latest by date)

Repository

repositories {
    maven { url = "https://repo.repsy.io/mvn/chrynan/public" }
}

Dependencies

implementation "com.chrynan.pathmatcher:pathmatcher-core:$VERSION"

Documentation

More detailed documentation is available in the docs folder. The entry point to the documentation can be found here.

License

Copyright 2021 chRyNaN

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A simple path matching utility for Kotlin Multi-platform

License:Apache License 2.0


Languages

Language:Kotlin 100.0%