--------------------- PatchSet 6540 Date: 2008/01/19 09:19:31 Author: amosjeffries Branch: ayjwork Tag: (none) Log: Add array operator to String. Provides for easier usage of String's in-line with usage of char-arrays which they are meant to imitate to some safe degree. Single operator deprecates several semi-safe pointer functions: * str.set(ptr, char); A.K.A. str[p] = 'h'; (String 'users' should not be playing with pointers into the raw data) * str.cut(pos); A.K.A. str[pos] = '\0'; * str.cutPointer(ptr); A.K.A. str[p] = '\0'; (String 'users' should not be playing with pointers into the raw data) These functions are left, and users not modified by this patch. Members: src/SquidString.h:1.8.8.9->1.8.8.10 src/String.cci:1.6.6.3->1.6.6.4 Index: squid3/src/SquidString.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/SquidString.h,v retrieving revision 1.8.8.9 retrieving revision 1.8.8.10 diff -u -r1.8.8.9 -r1.8.8.10 --- squid3/src/SquidString.h 13 Dec 2007 01:15:15 -0000 1.8.8.9 +++ squid3/src/SquidString.h 19 Jan 2008 09:19:31 -0000 1.8.8.10 @@ -1,6 +1,5 @@ - /* - * $Id: SquidString.h,v 1.8.8.9 2007/12/13 01:15:15 amosjeffries Exp $ + * $Id: SquidString.h,v 1.8.8.10 2008/01/19 09:19:31 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -90,6 +89,12 @@ bool operator ==(String const &) const; bool operator !=(String const &) const; + /** + * Retrieve a single character in the string. + \param pos Position of character to retrieve. + */ + char &operator [](unsigned int pos); + _SQUID_INLINE_ int size() const; _SQUID_INLINE_ char const * buf() const; void buf(char *); @@ -112,10 +117,19 @@ _SQUID_INLINE_ int caseCmp (char const *) const; _SQUID_INLINE_ int caseCmp (char const *, size_t count) const; + /** \deprecated Use assignment to [] position instead. + * ie str[0] = 'h'; + */ _SQUID_INLINE_ void set(char const *loc, char const ch); + /** \deprecated Use assignment to [] position instead. + * ie str[newLength] = '\0'; + */ _SQUID_INLINE_ void cut(size_t newLength); + /** \deprecated Use assignment to [] position instead. + * ie str[newLength] = '\0'; + */ _SQUID_INLINE_ void cutPointer(char const *loc); #if DEBUGSTRINGS Index: squid3/src/String.cci =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/String.cci,v retrieving revision 1.6.6.3 retrieving revision 1.6.6.4 diff -u -r1.6.6.3 -r1.6.6.4 --- squid3/src/String.cci 13 Dec 2007 01:15:15 -0000 1.6.6.3 +++ squid3/src/String.cci 19 Jan 2008 09:19:32 -0000 1.6.6.4 @@ -1,6 +1,5 @@ - /* - * $Id: String.cci,v 1.6.6.3 2007/12/13 01:15:15 amosjeffries Exp $ + * $Id: String.cci,v 1.6.6.4 2008/01/19 09:19:32 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -52,6 +51,14 @@ return buf_; } +char& +String::operator [](unsigned int pos) +{ + assert(pos < size_); + + return buf_[pos]; +} + const char * String::pos(char const *aString) const {