Skip to content

Fix Bug in rure_captures_len #365

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

Merged
merged 1 commit into from
May 14, 2017
Merged
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
Fix Bug in rure_captures_len
It looks like at some point in the past the captures were refactored
from being a vector of start and end positions into a list of location
structures. The C API still had a conversion of the length which
corrected for the captures being twice the length of the number of
captures.

This updates the length calculation in `rure.rs` to return the
correct length, and adds an assertion to the test case.
iwillspeak committed May 14, 2017
commit 4ed2fed6a878df60c9e33d5147d9e54b0ca4c4f0
13 changes: 13 additions & 0 deletions regex-capi/ctest/test.c
Original file line number Diff line number Diff line change
@@ -102,6 +102,19 @@ bool test_captures() {
}
passed = false;
}
size_t expect_captures_len = 3;
size_t captures_len = rure_captures_len(caps);
if (captures_len != expect_captures_len) {
if (DEBUG) {
fprintf(stderr,
"[test_captures] "
"expected capture group lenght to be %zd, but "
"got %zd\n",
expect_captures_len, captures_len);
}
passed = false;
goto done;
}
int32_t expect_capture_index = 2;
int32_t capture_index = rure_capture_name_index(re, "snowman");
if (capture_index != expect_capture_index) {
2 changes: 1 addition & 1 deletion regex-capi/src/rure.rs
Original file line number Diff line number Diff line change
@@ -434,7 +434,7 @@ ffi_fn! {

ffi_fn! {
fn rure_captures_len(captures: *const Captures) -> size_t {
unsafe { (*captures).0.len() / 2 }
unsafe { (*captures).0.len() }
}
}