Autor: Carsten Klein Datum: To: pcre-dev Betreff: Re: [pcre-dev] New API
Hi Philip,
great to see, that the new API gets moving again. See my notes on the
new version of the proposal.
12 String extraction functions
In one of the previous versions of this document, you said, that the
string extraction functions return 1 on success and zero otherwise
(especially, if the provided buffer is too small). BTW, isn't zero a
valid length of a captured string?
The following applies to the two pcre2_copy_xxx functions only.
There are languages out there, that have string types, which store the
string's length. For these, I suggest to return the length of the copied
string (number of characters, of course, not bytes), if the copy process
worked fine.
I guess, while copying, you actually have the string's length around and
can easily return it. If you do so, this will save an extra iteration
over the string on the caller side just for getting its length.
Furthermore, if the provided buffer is too small, the string copy
functions should return the required buffer size (that is string length
in characters plus the terminating null character) to help the caller to
provide a large enough buffer (likely after a first call with a
typically sized buffer has failed).
Then, if (retval > buffsize), the caller can directly create a new
buffer of size retval and call the function again.
It is, however, debatable whether to return the required buffer size or
just the string length in the failure case of a failure due to a too
small buffer. Basically, that makes no difference and is subject to
documentation.
Also that way, the returned value is always a positive value, if the
requested group has matched any non-empty string. To stay consistent,
zero should be returned, if the requested group matched an empty string
and a negative value should be returned, if the group did not match at all.