Sometimes the last byte is wrong. More details to follow.
destString.append (destChars, numChars + 1);
this line needs a + 1
Jeepers, you’re right. Doh!
In fact, that method was looking a bit old and clunky. Here’s a tarted-up version that should be faster than the old one. I’ve run some tests on it too, so it does actually work…
const String MemoryBlock::to64BitEncoding() const
const int numChars = ((size << 3) + 5) / 6;
String destString (size); // store the length, followed by a '.', and then the data. const int initialLen = destString.length(); destString.preallocateStorage (initialLen + 2 + numChars); tchar* d = ((tchar*) (const tchar*) destString) + initialLen; *d++ = T('.'); for (int i = 0; i < numChars; ++i) *d++ = encodingTable [getBitRange (i * 6, 6)]; *d++ = 0; return destString;
Why is it / 6 and not /8 ?
Shouldn’t the method be called toBase64 instead of 64Bits something?
This is confusing.
Yeah, you’re right, actually. I must have got a bit muddled between bases and bits when I named that.
I think I’ll rename it for the next version. It’ll be easy enough for people to copy-and-paste the new name into their code.