Converts a char (8 bits) into a 6-bit value for decoding. If the input char is invalid for base64 encoding, the return value has at least its upper 25 bits set.
| 46 | // is invalid for base64 encoding, the return value has at least its upper 25 |
| 47 | // bits set. |
| 48 | inline uint32 Convert(char x) { |
| 49 | // If x < 128, then we look up x in the table. If x is valid, then the table |
| 50 | // will have a value <= 0x3F, otherwise the table will have -1. If x >= 128, |
| 51 | // we still do some table lookup, but the value is ignored since we explicitly |
| 52 | // set the high bit of y to 1. Either way, y is negative (high bit set) in |
| 53 | // case of error. |
| 54 | const int8 y = kBase64Bytes[x & 0x7F] | (x & 0x80); |
| 55 | // Casting from int8 to int32 preserves sign by sign extension. If y was |
| 56 | // negative, at least its 25 high bits of the return value are set. |
| 57 | const int32 z = static_cast<int32>(y); |
| 58 | return static_cast<uint32>(z); |
| 59 | } |
| 60 | |
| 61 | Status DecodeThreeChars(const char* codes, char* result) { |
| 62 | const uint32 packed = (Convert(codes[0]) << 18) | (Convert(codes[1]) << 12) | |
no outgoing calls