[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: urlstring testing/enhancement
From: |
Chad Yates |
Subject: |
RE: urlstring testing/enhancement |
Date: |
Thu, 09 Jan 2003 17:16:39 -0800 |
> > I also added Base64 functions that take std::string arguments
> for the encode
> > output and the decode input. I don't know where the line is
> supposed to be
> > relating to string usage as I see most of common c++ is char* based, but
> > there seems to be std::string usage in some classes. personally I like
> > having it as an overload option. I can post diffs showing the
> new functions
> > if they are wanted.
> >
>
> I think we should include these new functions. For the last
> months some things have been changed and updated to progresively
> incorporate string as preferred to char*. These new functions do not
> break backwards compatibility, so I see no reason to not include it.
before I post a patch to add the new STL string functions I was wondering if
somebody knew the prefered way of dealing with excessive temporaries. see
the following:
/** @relates URLStream
* Encode a octet stream using base64 coding into a STL string
* @return base 64 encoded string
* @param src source buffer
* @param srcsize source buffer size
*/
CCXX_EXPORT(std::string) b64Encode(const unsigned char *src, size_t srcsize)
{
size_t limit = (srcsize+2)/3*4+1;
char* buffer = new char[limit];
unsigned size = b64Encode(src, srcsize, buffer, limit);
buffer[size] = '\0';
std::string final = string(buffer);
delete buffer;
return final;
}
notice that I have to not only allocate a temporary buffer (since the
b64Encode function doesn't work with strings directly -- or some kind
streaming), but I have to make a copy before I unallocate it, and then yet
another on the actual return by value. I have yet to delve into the realm
of autoptr's. is that the best bet? if so, the stl autoptr, or does common
c++ have a better one.
thanks,
Chad