--------------------- PatchSet 10272 Date: 2007/12/18 11:59:54 Author: adri Branch: s27_adri Tag: (none) Log: Add a sub-string string generator. Useful for replacing strBuf() calls in ftp.c. Remove some whitespace in String.h and reorder extern prototypes whilst I'm at it. Members: libbuf/String.c:1.1.2.12->1.1.2.13 libbuf/String.h:1.1.2.17->1.1.2.18 Index: squid/libbuf/String.c =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.c,v retrieving revision 1.1.2.12 retrieving revision 1.1.2.13 diff -u -r1.1.2.12 -r1.1.2.13 --- squid/libbuf/String.c 17 Dec 2007 16:40:06 -0000 1.1.2.12 +++ squid/libbuf/String.c 18 Dec 2007 11:59:54 -0000 1.1.2.13 @@ -1,6 +1,6 @@ /* - * $Id: String.c,v 1.1.2.12 2007/12/17 16:40:06 adri Exp $ + * $Id: String.c,v 1.1.2.13 2007/12/18 11:59:54 adri Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -202,3 +202,28 @@ return i; } +/* + * Grab a sub-string of the given string. For now, to keep things simple, + * this will be a completely new copy. Later on this can become a copy-on-write + * reference once strings don't need to be NUL-terminated. + * + * If len is -1, the end is the end of s. + * Values are clamped at the string length. + * + * Offsets begin at 0. + * + * XXX check this for off-by-one errors! + */ +String +strSubStr(String s, int start, int len) +{ + String n; + + if (start > strLen2(s)) + start = strLen2(s); + if (len == -1 || (start + len) > strLen2(s)) + len = strLen2(s); + + stringLimitInit(&n, strBuf(s) + start, len); + return n; +} Index: squid/libbuf/String.h =================================================================== RCS file: /cvsroot/squid-sf//squid/libbuf/Attic/String.h,v retrieving revision 1.1.2.17 retrieving revision 1.1.2.18 diff -u -r1.1.2.17 -r1.1.2.18 --- squid/libbuf/String.h 17 Dec 2007 08:14:03 -0000 1.1.2.17 +++ squid/libbuf/String.h 18 Dec 2007 11:59:54 -0000 1.1.2.18 @@ -106,15 +106,16 @@ #define strCat(s,str) stringAppend(&(s), (str), strlen(str)) #define strCatStr(s, s2) stringAppend(&(s), strBuf2(s2), strLen2(s2)) - extern void stringInit(String * s, const char *str); extern void stringLimitInit(String * s, const char *str, int len); - extern String stringDup(const String * s); extern void stringClean(String * s); extern void stringReset(String * s, const char *str); extern void stringAppend(String * s, const char *buf, int len); /* extern void stringAppendf(String *s, const char *fmt, ...) PRINTF_FORMAT_ARG2; */ +extern int strToOffset(String s, off_t *off, int base); +extern int strCSpn(String s, int start, const char *reject); +extern String strSubStr(String s, int start, int len); typedef struct { int create, reset, clean, dup, make_private; @@ -157,7 +158,4 @@ stringInit(s, str); } -extern int strToOffset(String s, off_t *off, int base); -extern int strCSpn(String s, int start, const char *reject); - #endif /* __LIBBUF_STRING__H_ */