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

(fix) jna: patternInfo for ByteBuffer #3

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
7 changes: 5 additions & 2 deletions jna/src/main/java/org/pcre4j/jna/Pcre2.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.ptr.PointerByReference;
import org.pcre4j.api.IPcre2;

import java.lang.reflect.Method;
Expand Down Expand Up @@ -150,8 +151,10 @@ public int patternInfo(long code, int what, long[] where) {

@Override
public int patternInfo(long code, int what, ByteBuffer where) {
Pointer wherePtr = Native.getDirectBufferPointer(where);
return library.pcre2_pattern_info(new Pointer(code), what, wherePtr);
PointerByReference whereRef = new PointerByReference();
int result = library.pcre2_pattern_info(new Pointer(code), what, whereRef.getPointer());
where.put(whereRef.getValue().getByteArray(0, where.capacity()));
return result;
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions test/src/main/java/org/pcre4j/test/Pcre2Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,16 @@ public void plainStringMatchNamedCapture() {
}, ovector);
}

@Test
public void nameTable() {
final var code = new Pcre2Code(
"(?<number>42)",
EnumSet.noneOf(Pcre2CompileOption.class),
null
);
final var nameTable = code.nameTable();
assertEquals(1, nameTable.length);
assertEquals(new Pcre2Code.NameTableEntry(1, "number"), nameTable[0]);
}

}