Skip to content

Commit

Permalink
(feat) use pcre2.library.name and pcre2.function.suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Jun 23, 2024
1 parent 4ae7708 commit 3f656b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
15 changes: 13 additions & 2 deletions ffm/src/main/java/org/pcre4j/ffm/Pcre2.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,27 @@ public class Pcre2 implements IPcre2 {
* Constructs a new PCRE2 API using the common library name "pcre2-8".
*/
public Pcre2() {
this("pcre2-8", "_8");
this(
System.getProperty("pcre2.library.name", "pcre2-8"),
System.getProperty("pcre2.function.suffix", "_8")
);
}

/**
* Constructs a new PCRE2 API using the specified library name and function suffix.
*
* @param library the library name or path to the file (e.g. "pcre2-8" or "/usr/lib/libpcre2-8.so")
* @param library the library name (e.g. "pcre2-8" for "pcre2-8.dll" on Windows, "libpcre2-8.so" on Linux,
* "libpcre2-8.dylib" on macOS) or an absolute path to the library file
* @param suffix the function suffix (e.g. "_8" as in "pcre2_compile_8")
*/
public Pcre2(String library, String suffix) {
if (library == null) {
throw new IllegalArgumentException("library must not be null");
}
if (suffix == null) {
throw new IllegalArgumentException("suffix must not be null");
}

if (new File(library).exists()) {
System.load(library);
} else {
Expand Down
22 changes: 16 additions & 6 deletions jna/src/main/java/org/pcre4j/jna/Pcre2.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,29 @@ public class Pcre2 implements IPcre2 {
* Constructs a new PCRE2 API using the common library name "pcre2-8".
*/
public Pcre2() {
this("pcre2-8", "_8");
this(
System.getProperty("pcre2.library.name", "pcre2-8"),
System.getProperty("pcre2.function.suffix", "_8")
);
}

/**
* Constructs a new PCRE2 API using the specified library name and function suffix.
*
* @param libraryName the library name (e.g. "pcre2-8" for "pcre2-8.dll" on Windows, "libpcre2-8.so" on Linux,
* "libpcre2-8.dylib" on macOS)
* @param suffix the function suffix (e.g. "_8" as in "pcre2_compile_8")
* @param library the library name (e.g. "pcre2-8" for "pcre2-8.dll" on Windows, "libpcre2-8.so" on Linux,
* "libpcre2-8.dylib" on macOS) or an absolute path to the library file
* @param suffix the function suffix (e.g. "_8" as in "pcre2_compile_8")
*/
public Pcre2(String libraryName, String suffix) {
public Pcre2(String library, String suffix) {
if (library == null) {
throw new IllegalArgumentException("library must not be null");
}
if (suffix == null) {
throw new IllegalArgumentException("suffix must not be null");
}

this.library = Native.load(
libraryName,
library,
Library.class,
Map.of(Library.OPTION_FUNCTION_MAPPER, new SuffixFunctionMapper(suffix))
);
Expand Down

0 comments on commit 3f656b0

Please sign in to comment.