Re: [pcre-dev] New API

Página superior
Eliminar este mensaje
Autor: ph10
Fecha:  
A: Carsten Klein
Cc: pcre-dev
Asunto: Re: [pcre-dev] New API
On Wed, 15 Jan 2014, Carsten Klein wrote:

> great to see, that the new API gets moving again. See my notes on the
> new version of the proposal.


Thanks for your comments.

> In one of the previous versions of this document, you said, that the
> string extraction functions return 1 on success and zero otherwise


Did I? I thought my only comment on these was "Apart from changes to the
variable types and the addition of a context argument for functions that
get memory, these are otherwise unchanged." And in the current
specification they return a length for success and a negative number for
error. That is certainly my intention.

> 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.


Number of characters may be tricky; what is known is the number of
bytes (or 16-bit or 32-bit units). Nowhere else in the API does PCRE
count in characters.

> 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).


At present they return PCRE_ERROR_NOMEMORY. A function could be provided
to return the length required: int pcre2_get_stringlength(context,
number) for example.

Philip

--
Philip Hazel