diff options
Diffstat (limited to 'buf.c')
-rw-r--r-- | buf.c | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -440,4 +440,62 @@ int Buf::getc(int idx, char *c) *c = buf[idx]; return 0; +} + +int Buf::findc(char c, int *idx) +{ + int i=0; + + for (i=0;i<this->cur_size;i++) + { + if (buf[i] == c) + { + //found + *idx = i; + return 1; + } + } + + //not found + return 0; +} + +int Buf::popsubstring(int sz, char **val, int *size) +{ + int ret=-1; + + if (sz>this->cur_size) + { + sz = this->cur_size; + } + + *val = (char *)malloc(sz); + memcpy(*val,buf,sz); + *size = sz; + shiftleft(sz); + ret = sz; + + return ret; +} + +int Buf::shiftleft(int n) +{ + int i=0; + + if ((n>this->cur_size) || (n<0)) + { + //cant shift + return -1; + } + int mvsz = cur_size-n; + for (i=0;i<mvsz;i++) + { + char c = buf[n+i]; + printf("%c",c); + buf[i] = c; + } + this->cur_size -= n; + + //amount of shifted bytes + return n; }
\ No newline at end of file |