Code cleanup

pull/24/head
Tatsuhiro Tsujikawa 2012-07-04 22:59:15 +09:00
parent 995c07c184
commit b25d8a9923
1 changed files with 15 additions and 15 deletions

View File

@ -127,30 +127,30 @@ std::string decode(InputIterator first, InputIterator last)
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
}; };
std::string res; std::string res;
InputIterator k[5]; InputIterator k[4];
int eq = 0; int eq = 0;
for(; first != last;) { for(; first != last;) {
for(int i = 1; i <= 4; ++i) { for(int i = 1; i <= 4; ++i) {
k[i] = getNext(first, last, INDEX_TABLE); k[i-1] = getNext(first, last, INDEX_TABLE);
if(k[i] == last) { if(k[i-1] == last) {
// If i == 1, input may look like this: "TWFu\n" (i.e., // If i == 1, input may look like this: "TWFu\n" (i.e.,
// garbage at the end) // garbage at the end)
if(i != 1) { if(i != 1) {
res.clear(); res.clear();
} }
return res; return res;
} else if(*k[i] == '=' && eq == 0) { } else if(*k[i-1] == '=' && eq == 0) {
eq = i; eq = i;
} }
first = k[i]+1; first = k[i-1]+1;
} }
if(eq) { if(eq) {
break; break;
} }
int n = (INDEX_TABLE[static_cast<unsigned char>(*k[1])] << 18)+ int n = (INDEX_TABLE[static_cast<unsigned char>(*k[0])] << 18)+
(INDEX_TABLE[static_cast<unsigned char>(*k[2])] << 12)+ (INDEX_TABLE[static_cast<unsigned char>(*k[1])] << 12)+
(INDEX_TABLE[static_cast<unsigned char>(*k[3])] << 6)+ (INDEX_TABLE[static_cast<unsigned char>(*k[2])] << 6)+
INDEX_TABLE[static_cast<unsigned char>(*k[4])]; INDEX_TABLE[static_cast<unsigned char>(*k[3])];
res += n >> 16; res += n >> 16;
res += n >> 8 & 0xffu; res += n >> 8 & 0xffu;
res += n & 0xffu; res += n & 0xffu;
@ -161,19 +161,19 @@ std::string decode(InputIterator first, InputIterator last)
return res; return res;
} else { } else {
for(int i = eq; i <= 4; ++i) { for(int i = eq; i <= 4; ++i) {
if(*k[i] != '=') { if(*k[i-1] != '=') {
res.clear(); res.clear();
return res; return res;
} }
} }
if(eq == 3) { if(eq == 3) {
int n = (INDEX_TABLE[static_cast<unsigned char>(*k[1])] << 18)+ int n = (INDEX_TABLE[static_cast<unsigned char>(*k[0])] << 18)+
(INDEX_TABLE[static_cast<unsigned char>(*k[2])] << 12); (INDEX_TABLE[static_cast<unsigned char>(*k[1])] << 12);
res += n >> 16; res += n >> 16;
} else if(eq == 4) { } else if(eq == 4) {
int n = (INDEX_TABLE[static_cast<unsigned char>(*k[1])] << 18)+ int n = (INDEX_TABLE[static_cast<unsigned char>(*k[0])] << 18)+
(INDEX_TABLE[static_cast<unsigned char>(*k[2])] << 12)+ (INDEX_TABLE[static_cast<unsigned char>(*k[1])] << 12)+
(INDEX_TABLE[static_cast<unsigned char>(*k[3])] << 6); (INDEX_TABLE[static_cast<unsigned char>(*k[2])] << 6);
res += n >> 16; res += n >> 16;
res += n >> 8 & 0xffu; res += n >> 8 & 0xffu;
} }