我正在学习 PCRE,但我不明白为什么偏移向量必须是 3 的倍数。这是来自 pcredemo.c (rc
结果来自pcre_exec()
):
/* The output vector wasn't big enough */
if (rc == 0) {
rc = OVECCOUNT / 3;
printf("ovector only has room for %d captured substrings\n", rc - 1);
}
/* Show substrings stored in the output vector by number. Obviously, in a real
* application you might want to do things other than print them. */
for (i = 0; i < rc; i++) {
char *substring_start = subject + ovector[2 * i];
int substring_length = ovector[2 * i + 1] - ovector[2 * i];
printf("%2d: %.*s\n", i, substring_length, substring_start);
}
在我看来,ovector 存储str1_start, str1_end, str2_start, str2_end, ...
,所以数组可以保存 OVECCOUNT/2 个字符串。为什么是 OVECCOUNT/3?
谢谢你。