From 3154e1ccaabfbdb42aa48cbb5805b23442cdc33e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 10 Sep 2013 23:18:03 -0700 Subject: Whitespace: re-indent the {to,from}Base64 functions The code must have been copied from somewhere, a sample implementation. Change-Id: Ieb6ac5d69824fe8a3f38710a22beb79ac986e182 Reviewed-by: Richard J. Moore --- src/corelib/tools/qbytearray.cpp | 96 ++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 44 deletions(-) (limited to 'src/corelib/tools/qbytearray.cpp') diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 68fb3df618..7ec7333054 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -3546,7 +3546,7 @@ float QByteArray::toFloat(bool *ok) const QByteArray QByteArray::toBase64() const { const char alphabet[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef" - "ghijklmn" "opqrstuv" "wxyz0123" "456789+/"; + "ghijklmn" "opqrstuv" "wxyz0123" "456789+/"; const char padchar = '='; int padlen = 0; @@ -3555,26 +3555,34 @@ QByteArray QByteArray::toBase64() const int i = 0; char *out = tmp.data(); while (i < d->size) { - int chunk = 0; + // encode 3 bytes at a time + int chunk = 0; chunk |= int(uchar(d->data()[i++])) << 16; - if (i == d->size) { - padlen = 2; - } else { + if (i == d->size) { + padlen = 2; + } else { chunk |= int(uchar(d->data()[i++])) << 8; - if (i == d->size) padlen = 1; - else chunk |= int(uchar(d->data()[i++])); - } - - int j = (chunk & 0x00fc0000) >> 18; - int k = (chunk & 0x0003f000) >> 12; - int l = (chunk & 0x00000fc0) >> 6; - int m = (chunk & 0x0000003f); - *out++ = alphabet[j]; - *out++ = alphabet[k]; - if (padlen > 1) *out++ = padchar; - else *out++ = alphabet[l]; - if (padlen > 0) *out++ = padchar; - else *out++ = alphabet[m]; + if (i == d->size) + padlen = 1; + else + chunk |= int(uchar(data()[i++])); + } + + int j = (chunk & 0x00fc0000) >> 18; + int k = (chunk & 0x0003f000) >> 12; + int l = (chunk & 0x00000fc0) >> 6; + int m = (chunk & 0x0000003f); + *out++ = alphabet[j]; + *out++ = alphabet[k]; + + if (padlen > 1) + *out++ = padchar; + else + *out++ = alphabet[l]; + if (padlen > 0) + *out++ = padchar; + else + *out++ = alphabet[m]; } tmp.truncate(out - tmp.data()); @@ -3945,31 +3953,31 @@ QByteArray QByteArray::fromBase64(const QByteArray &base64) int offset = 0; for (int i = 0; i < base64.size(); ++i) { - int ch = base64.at(i); - int d; - - if (ch >= 'A' && ch <= 'Z') - d = ch - 'A'; - else if (ch >= 'a' && ch <= 'z') - d = ch - 'a' + 26; - else if (ch >= '0' && ch <= '9') - d = ch - '0' + 52; - else if (ch == '+') - d = 62; - else if (ch == '/') - d = 63; - else - d = -1; - - if (d != -1) { - buf = (buf << 6) | d; - nbits += 6; - if (nbits >= 8) { - nbits -= 8; - tmp[offset++] = buf >> nbits; - buf &= (1 << nbits) - 1; - } - } + int ch = base64.at(i); + int d; + + if (ch >= 'A' && ch <= 'Z') + d = ch - 'A'; + else if (ch >= 'a' && ch <= 'z') + d = ch - 'a' + 26; + else if (ch >= '0' && ch <= '9') + d = ch - '0' + 52; + else if (ch == '+') + d = 62; + else if (ch == '/') + d = 63; + else + d = -1; + + if (d != -1) { + buf = (buf << 6) | d; + nbits += 6; + if (nbits >= 8) { + nbits -= 8; + tmp[offset++] = buf >> nbits; + buf &= (1 << nbits) - 1; + } + } } tmp.truncate(offset); -- cgit v1.2.3