-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Gradle Wrapper script for Linux should use lf | ||
/gradlew text eol=lf | ||
|
||
# Gradle Wrapper script for Windows should use crlf | ||
/gradlew.bat text eol=crlf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Pull Request | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest ] | ||
java-distribution: | ||
- temurin | ||
- zulu | ||
- adopt-hotspot | ||
- adopt-openj9 | ||
- liberica | ||
- microsoft | ||
- corretto | ||
- semeru | ||
- oracle | ||
- dragonwell | ||
fail-fast: false | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up "${{ matrix.java-distribution }}" JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: ${{ matrix.java-distribution }} | ||
java-version: 21 | ||
|
||
- name: Cache Gradle packages | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: gradle-${{ runner.os }} | ||
|
||
- name: Install PCRE (Ubuntu) | ||
if: ${{ matrix.os == 'ubuntu-latest' }} | ||
run: sudo apt-get install -y libpcre2-8-0 | ||
|
||
- name: Build with Gradle (Ubuntu) | ||
if: ${{ matrix.os == 'ubuntu-latest' }} | ||
run: ./gradlew build -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu | ||
|
||
- name: Run tests (Ubuntu) | ||
if: ${{ matrix.os == 'ubuntu-latest' }} | ||
run: ./gradlew test -Dpcre2.library.path=/usr/lib/x86_64-linux-gnu |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "automatic" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,62 @@ | ||
# PCRE4J: [PCRE](https://www.pcre.org) for Java | ||
# PCRE4J: PCRE for Java | ||
|
||
The PCRE4J project is a Java wrapper for the [Perl Compatible Regular Expressions](https://github.com/PCRE2Project/pcre2) library. | ||
The PCRE4J project's goal is to bring the power of the [PCRE](https://www.pcre.org) library to Java. | ||
|
||
This project is brought to you by [Alexey Pelykh](https://github.com/alexey-pelykh) with a great gratitude to the PCRE | ||
library author [Philip Hazel](https://github.com/PhilipHazel) and its contributors. | ||
|
||
## Usage | ||
|
||
```java | ||
import org.pcre4j.Pcre2Code; | ||
import org.pcre4j.Pcre2CompileOption; | ||
import org.pcre4j.Pcre2MatchData; | ||
import org.pcre4j.Pcre2MatchOption; | ||
import org.pcre4j.Pcre4j; | ||
import org.pcre4j.Pcre4jUtils; | ||
// TODO: Select one of the following imports for the backend you want to use: | ||
import org.pcre4j.jna.Pcre2; | ||
// import org.pcre4j.ffm.Pcre2; | ||
|
||
public class Usage { | ||
static { | ||
Pcre4j.setup(new Pcre2()); | ||
} | ||
|
||
public static String[] example(String pattern, String subject) { | ||
final var code = new Pcre2Code( | ||
pattern, | ||
EnumSet.noneOf(Pcre2CompileOption.class), | ||
null | ||
); | ||
final var matchData = new Pcre2MatchData(code); | ||
code.match( | ||
subject, | ||
0, | ||
EnumSet.noneOf(Pcre2MatchOption.class), | ||
matchData, | ||
null | ||
); | ||
return Pcre4jUtils.getMatchGroups(code, subject, matchData); | ||
} | ||
} | ||
``` | ||
|
||
## Backends | ||
|
||
The PCRE4J library supports several backends to invoke the `pcre2` API. | ||
|
||
### `jna` | ||
|
||
The `jna` backend uses the [Java Native Access](https://github.com/java-native-access/jna) library to invoke the `pcre2` | ||
shared library. For this backend to work, the `pcre2` shared library must be installed on the system and be visible to | ||
the JNA. | ||
|
||
### `ffm` | ||
|
||
The `ffm` backend uses the [Foreign Functions and Memory API](https://docs.oracle.com/en/java/javase/21/core/foreign-function-and-memory-api.html) | ||
to invoke the `pcre2` shared library. For this backend to work, the `pcre2` shared library must be installed on the | ||
system and be visible via `java.library.path`. | ||
|
||
Note that `--enable-preview` must be passed to the Java compiler to enable the preview features for this backend to be | ||
used. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (C) 2024 Oleksii PELYKH | ||
* | ||
* This file is a part of the PCRE4J. The PCRE4J is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with this program. If not, see | ||
* <https://www.gnu.org/licenses/>. | ||
*/ | ||
plugins { | ||
`java-library` | ||
`maven-publish` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
} | ||
|
||
configurations { | ||
implementation { | ||
resolutionStrategy.failOnVersionConflict() | ||
} | ||
} | ||
|
||
sourceSets { | ||
main { | ||
java.srcDir("src/main/java") | ||
} | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_21 | ||
targetCompatibility = JavaVersion.VERSION_21 | ||
|
||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(21) | ||
} | ||
|
||
withSourcesJar() | ||
withJavadocJar() | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
|
||
tasks.named<Jar>("sourcesJar") { | ||
duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("mavenJava") { | ||
from(components["java"]) | ||
|
||
artifact(tasks.named("sourcesJar")) | ||
artifact(tasks.named("javadocJar")) | ||
|
||
groupId = "org.pcre4j" | ||
artifactId = project.name | ||
version = findProperty("pcre4j.version") as String? ?: "0.0.0-SNAPSHOT" | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral { | ||
credentials { | ||
username = findProperty("pcre4j.mavenCentral.user") as String? ?: "" | ||
password = findProperty("pcre4j.mavenCentral.password") as String? ?: "" | ||
} | ||
} | ||
} | ||
} |