Skip to content

Commit

Permalink
(fix) jna: patternInfo for ByteBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Jun 20, 2024
1 parent 9110d65 commit 45d401a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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]);
}

}

0 comments on commit 45d401a

Please sign in to comment.