[dhcp-agent-commits] dhcp-agent/src dhcp-stringbuffer.c,1.10,1.11
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-12-30 06:29:22
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11100/src Modified Files: dhcp-stringbuffer.c Log Message: more stringbuffer fun Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-stringbuffer.c 30 Dec 2002 00:45:03 -0000 1.10 --- dhcp-stringbuffer.c 30 Dec 2002 06:29:19 -0000 1.11 *************** *** 193,205 **** } - /* FIXME: use memcpy() */ /* remove whitespace (including tabs) */ stringbuffer_t *stringbuffer_trim_whitespace(stringbuffer_t *sb) { - char *ptr, *curptr; - char *end, *begin; char *newbuf; ! int len; ! int i; if(sb->len == 0) /* empty string. */ --- 193,202 ---- } /* remove whitespace (including tabs) */ stringbuffer_t *stringbuffer_trim_whitespace(stringbuffer_t *sb) { char *newbuf; ! int new_len; ! int i, j; if(sb->len == 0) /* empty string. */ *************** *** 207,233 **** /* find beginning of string after tabs and whitespaces. */ ! begin = &sb->buf[0]; ! for(i = 0; i < sb->len && (*begin == ' ' || *begin == '\t'); begin++); ! if(*begin != '\0') { /* we do have whitespace in the beginning so find the end. */ ! for(end = &sb->buf[sb->len]; *end == ' ' || *end == '\t'; end--); ! len = sb->len; /* save old length. */ ! /* create a new string */ ! newbuf = allocate_string(len); ! ptr = newbuf; ! for(curptr = begin; curptr != end; curptr++) { ! *ptr = *curptr; ! ptr++; ! } ! *ptr = 0; xfree(sb->buf); sb->buf = newbuf; ! sb->len = strlen(newbuf); ! sb->capacity = len; --- 204,232 ---- /* find beginning of string after tabs and whitespaces. */ ! for(i = 0; i < sb->len && (sb->buf[i] == ' ' || sb->buf[i] == '\t'); i++); ! if(sb->buf[i] != '\0') { /* we do have whitespace in the beginning so find the end. */ ! for(j = (sb->len -1);(sb->buf[j] == ' ' || sb->buf[j] == '\t'); j--); ! /* increment j since it's on the non whitespace character. */ ! j++; ! /* create a new string. */ ! new_len = j - i; ! newbuf = allocate_string(new_len); ! ! /* copy in. */ ! memcpy(newbuf, &sb->buf[i], (j - i) * sizeof(char)); ! newbuf[new_len] = 0; + /* free up old. */ xfree(sb->buf); + + /* set new. */ sb->buf = newbuf; ! sb->len = new_len; ! sb->capacity = new_len; *************** *** 246,254 **** { char *ptr, *ptrend = NULL; ptr = sb->buf; ! while((ptr = strchr(ptr, '\n')) != NULL) { ! ptrend = ptr; ! ptr++; } --- 245,255 ---- { char *ptr, *ptrend = NULL; + int i; ptr = sb->buf; ! for(i = 0;i < sb->len;i++) { ! ! if(ptr[i] == c) ! ptrend = &ptr[i]; } *************** *** 298,307 **** void stringbuffer_replace_c(stringbuffer_t *sb, char c, char replace) { ! char *ptr; ! for(ptr = sb->buf; *ptr != 0; ptr++) { ! if(*ptr == c) ! *ptr = replace; } } --- 299,310 ---- void stringbuffer_replace_c(stringbuffer_t *sb, char c, char replace) { ! int i; ! for(i = 0;i < sb->len;i++) { ! if(sb->buf[i] == c) ! sb->buf[i] = replace; } + + return; } *************** *** 372,376 **** stringbuffer_t *aligned_string; int len, i; - stringbuffer_zap_newline(sb); --- 375,378 ---- |