PCRE-偏移向量,为3的倍数?

wok*_*oky 5 c regex pcre

我正在使用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);
}
Run Code Online (Sandbox Code Playgroud)

在我看来,ovector存储了str1_start, str1_end, str2_start, str2_end, ...,因此数组可以容纳OVECCOUNT / 2个字符串。为什么是OVECCOUNT / 3?

谢谢。

the*_*mel 5

手册

向量的前三分之二用于传回捕获的子字符串,每个子字符串使用一对整数。向量的其余三分之一在匹配捕获子模式时被pcre_exec()用作工作空间,并且不可用于传递回信息。ovecsize中传递的数字应始终为三的倍数。如果不是,则将其四舍五入。