2002-10-17 20:32:03 +00:00
|
|
|
#include "byte.h"
|
|
|
|
#include "stralloc.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include <errno.h>
|
|
|
|
|
2004-11-25 21:29:35 +00:00
|
|
|
int buffer_get_token_sa(buffer* b,stralloc* sa,
|
2005-04-23 15:50:16 +00:00
|
|
|
const char* charset,
|
2006-11-07 17:56:05 +00:00
|
|
|
size_t setlen) {
|
2002-10-17 20:32:03 +00:00
|
|
|
for (;;) {
|
|
|
|
char x;
|
|
|
|
if (!stralloc_readyplus(sa,1)) goto nomem;
|
|
|
|
switch (buffer_getc(b,&x)) {
|
|
|
|
case -1: return -1;
|
|
|
|
case 0: return 0;
|
|
|
|
}
|
|
|
|
stralloc_append(sa,&x);
|
|
|
|
if (byte_chr(charset,setlen,x)<setlen) break;
|
|
|
|
}
|
2004-11-27 01:12:04 +00:00
|
|
|
return 1;
|
2002-10-17 20:32:03 +00:00
|
|
|
nomem:
|
|
|
|
errno=ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|