libowfat/stralloc/stralloc_chomp.c
2016-03-17 11:13:23 +00:00

20 lines
316 B
C

#include "stralloc.h"
int stralloc_chomp(stralloc* sa) {
size_t 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;
}