From 082dee0658b67744ab3428eea964f375f7aab9dc Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Sun, 12 May 2019 15:05:57 +0100 Subject: Added more functionality to Buf, substring, search for characer, and shifting string. --- buf.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'buf.c') diff --git a/buf.c b/buf.c index c9cf59a..2a64b1c 100644 --- a/buf.c +++ b/buf.c @@ -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;icur_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;icur_size -= n; + + //amount of shifted bytes + return n; } \ No newline at end of file -- cgit v1.2.3