extend API To read line/token to stralloc to allow clearing the
stralloc first. add stralloc_zero to clear a strallocmaster
parent
dd66bcb7c3
commit
82b0bb6f39
@ -0,0 +1,26 @@
|
|||||||
|
.TH buffer_get_new_token_sa 3
|
||||||
|
.SH NAME
|
||||||
|
buffer_get_new_token_sa \- read token from buffer
|
||||||
|
.SH SYNTAX
|
||||||
|
.nf
|
||||||
|
.B #include <stralloc.h>
|
||||||
|
.B #include <buffer.h>
|
||||||
|
|
||||||
|
int \fBbuffer_get_new_token_sa\fP(buffer* \fIb\fR,stralloc* \fIsa\fR,
|
||||||
|
const char* \fIcharset\fR,unsigned int \fIsetlen\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
buffer_get_new_token_sa copies data from the \fIb\fR to \fIsa\fR until
|
||||||
|
one of the delimiters in \fIcharset\fR is found, overwriting the
|
||||||
|
previous content of \fIsa\fR. That delimiter is also copied to
|
||||||
|
\fIsa\fR.
|
||||||
|
|
||||||
|
If reading from the buffer or allocating memory fails,
|
||||||
|
buffer_get_new_token_sa returns -1 and sets \fIerrno\fR appropriately. At
|
||||||
|
that point \fIsa\fR may already contain a partial token.
|
||||||
|
|
||||||
|
On success, buffer_get_new_token_sa returns 0.
|
||||||
|
|
||||||
|
If you want to read from a non-blocking socket, use buffer_get_token_sa
|
||||||
|
instead.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
buffer_getline_sa(3), buffer_get_token(3), buffer(3)
|
@ -0,0 +1,7 @@
|
|||||||
|
#include "stralloc.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,unsigned int setlen) {
|
||||||
|
stralloc_zero(sa);
|
||||||
|
return buffer_get_token_sa(b,sa,charset,setlen);
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
.TH buffer_get_new_token_sa_pred 3
|
||||||
|
.SH NAME
|
||||||
|
buffer_get_new_token_sa_pred \- read token from buffer
|
||||||
|
.SH SYNTAX
|
||||||
|
.nf
|
||||||
|
.B #include <stralloc.h>
|
||||||
|
.B #include <buffer.h>
|
||||||
|
|
||||||
|
int \fBbuffer_get_new_token_sa_pred\fP(buffer* \fIb\fR,stralloc* \fIsa\fR,
|
||||||
|
int (*\fIpredicate\fR)(stralloc* * \fIsa\fR));
|
||||||
|
.SH DESCRIPTION
|
||||||
|
buffer_get_token_sa_pred copies data from \fIb\fR to \fIsa\fR until
|
||||||
|
\fIpredicate\fR(\fIsa\fR) returns 1 or -1.
|
||||||
|
|
||||||
|
If \fIpredicate\fR returns 1 once a '\\n' was read, that new-line
|
||||||
|
character is still appended to \fIsa\fR -- use stralloc_chop or
|
||||||
|
stralloc_chomp to get rid of it. \fIpredicate\fR can also return 0
|
||||||
|
(indicating further input is required to complete the token) or -1
|
||||||
|
(abort and return -1; use this if \fIpredicate\fR wants to enfore a
|
||||||
|
maximum message size or does timeout handling or detects a malformed
|
||||||
|
message).
|
||||||
|
|
||||||
|
If reading from the buffer or allocating memory fails,
|
||||||
|
buffer_get_new_token_sa_pred returns -1 and sets \fIerrno\fR
|
||||||
|
appropriately. At that point \fIsa\fR may already contain a partial
|
||||||
|
token.
|
||||||
|
|
||||||
|
On success, buffer_get_new_token_sa_pred returns 0.
|
||||||
|
|
||||||
|
If you want to read from a non-blocking socket, use
|
||||||
|
buffer_get_token_sa_pred instead.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
buffer_getline_sa(3), buffer_get_token(3), buffer(3)
|
@ -0,0 +1,7 @@
|
|||||||
|
#include "stralloc.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
int buffer_get_new_token_sa_pred(buffer* b,stralloc* sa,sa_predicate p) {
|
||||||
|
stralloc_zero(sa);
|
||||||
|
return buffer_get_token_sa_pred(b,sa,p);
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
.TH buffer_getline 3
|
||||||
|
.SH NAME
|
||||||
|
buffer_getline \- read line from buffer
|
||||||
|
.SH SYNTAX
|
||||||
|
.B #include <buffer.h>
|
||||||
|
|
||||||
|
int \fBbuffer_getline\fP(buffer* \fIb\fR,char* \fIx\fR,unsigned int \fIlen\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
buffer_getline copies data from \fIb\fR to \fIx\fR[0], \fIx\fR[1], ...,
|
||||||
|
\fIx\fR[\fIlen\fR-1] until \fIlen\fR bytes have been copied or a
|
||||||
|
new-line character ('\\n') is encountered. That character is also
|
||||||
|
copied.
|
||||||
|
|
||||||
|
buffer_getline returns the number of bytes read (excluding the '\\n') or
|
||||||
|
-1 on error (setting \fIerrno\fR appropriately).
|
||||||
|
|
||||||
|
Note that line is not 0-terminated to make reading lines with 0-bytes
|
||||||
|
possible through this interface.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
buffer_init(3), buffer_feed(3), buffer_peek(3), buffer_seek(3), buffer(3)
|
@ -0,0 +1,24 @@
|
|||||||
|
.TH buffer_getnewline_sa 3
|
||||||
|
.SH NAME
|
||||||
|
buffer_getnewline_sa \- read line from buffer
|
||||||
|
.SH SYNTAX
|
||||||
|
.nf
|
||||||
|
.B #include <stralloc.h>
|
||||||
|
.B #include <buffer.h>
|
||||||
|
|
||||||
|
int \fBbuffer_getnewline_sa\fP(buffer* \fIb\fR,stralloc* \fIsa\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
buffer_getnewline_sa copies data from the \fIb\fR to \fIsa\fR until a '\\n'
|
||||||
|
is found, overwriting the previous content of \fIsa\fR. The new-line
|
||||||
|
is also appended to \fIsa\fR.
|
||||||
|
|
||||||
|
If reading from the buffer or allocating memory fails,
|
||||||
|
buffer_getnewline_sa returns -1 and sets \fIerrno\fR appropriately. At
|
||||||
|
that point \fIsa\fR may be empty or it may already contain a partial
|
||||||
|
token.
|
||||||
|
|
||||||
|
On success, buffer_getnewline_sa returns 0.
|
||||||
|
|
||||||
|
To read from a non-blocking socket, use buffer_getline_sa.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
buffer_get_token_sa(3), buffer(3)
|
@ -0,0 +1,7 @@
|
|||||||
|
#include "stralloc.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
int buffer_getnewline_sa(buffer* b,stralloc* sa) {
|
||||||
|
stralloc_zero(sa);
|
||||||
|
return buffer_getline_sa(b,sa);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
.TH stralloc_zero 3
|
||||||
|
.SH NAME
|
||||||
|
stralloc_zero \- set length of stralloc to 0
|
||||||
|
.SH SYNTAX
|
||||||
|
.B #include <stralloc.h>
|
||||||
|
|
||||||
|
int \fBstralloc_zero\fP(stralloc* \fIsa\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
stralloc_zero sets the length of the stralloc to 0.
|
||||||
|
|
||||||
|
It is a shortcut for stralloc_copys(\fIsa\fR,"").
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
stralloc_copys(3)
|
Loading…
Reference in New Issue