add buffer_putsa, buffer_get_token_sa, buffer_getline_sa, stralloc_chomp
and stralloc_chop
This commit is contained in:
19
stralloc/stralloc_chomp.c
Normal file
19
stralloc/stralloc_chomp.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stralloc.h>
|
||||
|
||||
int stralloc_chomp(stralloc* sa) {
|
||||
unsigned int max=sa->len;
|
||||
if (max>0) {
|
||||
register char x;
|
||||
--max;
|
||||
x=sa->s[max];
|
||||
if (x=='\n' || x=='\r') {
|
||||
if (x=='\n' && max>1 && sa->s[max-1]=='\r') {
|
||||
sa->len-=2;
|
||||
return 2;
|
||||
}
|
||||
--sa->len;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user