to64BitEncoding / from64BitEncoding is broken


#1

Sometimes the last byte is wrong. More details to follow.


#2

destString.append (destChars, numChars + 1);

this line needs a + 1


#3

Jeepers, you’re right. Doh!


#4

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…

[code]
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;

}[/code]


#5

Why is it / 6 and not /8 ?

Shouldn’t the method be called toBase64 instead of 64Bits something?
This is confusing.


#6

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.


#7