From: Gonzalo A. <ga...@us...> - 2006-09-08 20:59:06
|
Update of /cvsroot/mod-c/ehtml/src In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16888/src Modified Files: Common.cpp Log Message: * Bugfixes in base64decode, urldecode. * Added {hex,base64}encode(std::string). Index: Common.cpp =================================================================== RCS file: /cvsroot/mod-c/ehtml/src/Common.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Common.cpp 8 Sep 2006 14:24:05 -0000 1.7 --- Common.cpp 8 Sep 2006 20:59:02 -0000 1.8 *************** *** 295,300 **** char escape[4] = { '%', ! h2c[(dev[i] >> 4) & 0x0f], ! h2c[dev[i] & 0x0f], '\0' }; --- 295,300 ---- char escape[4] = { '%', ! h2c[(s[i] >> 4) & 0x0f], ! h2c[s[i] & 0x0f], '\0' }; *************** *** 311,319 **** int i = 0; for (; ii < dev.Size(); ++i, ++ii) { if (obuf[ii] != '%') continue; if (ii >= dev.Size() - 2) throw "Invalid string to decode"; ! dev[i] = GetByteFromHex(obuf[++ii], obuf[++ii]); } dev.resize(i); --- 311,320 ---- int i = 0; for (; ii < dev.Size(); ++i, ++ii) { + obuf[i] = obuf[ii]; if (obuf[ii] != '%') continue; if (ii >= dev.Size() - 2) throw "Invalid string to decode"; ! obuf[i] = GetByteFromHex(obuf[++ii], obuf[++ii]); } dev.resize(i); *************** *** 321,324 **** --- 322,329 ---- } + string hexencode(const std::string& s) { + return hexencode(MemBuf::Dup(s.c_str(), s.length())); + } + string hexencode(const MemBuf& mb) { string dev; *************** *** 351,354 **** --- 356,363 ---- "+/"; + std::string base64encode(const std::string& s) { //@todo test + return base64encode(MemBuf::Dup(s.c_str(),s.length())); + } + std::string base64encode(const MemBuf& mb) { //@todo test string dev; *************** *** 401,406 **** unsigned char _b64_aton(char c) { if (c >= 'A' && c <= 'Z') return int(c-'A'); ! if (c >= 'a' && c <= 'z') return int(c-'a') + ('Z'-'A'); ! if (c >= '0' && c <= '9') return int(c-'0') + ('z'-'a') + ('Z'-'A'); if (c == '+') return 62; if (c == '/') return 63; --- 410,415 ---- unsigned char _b64_aton(char c) { if (c >= 'A' && c <= 'Z') return int(c-'A'); ! if (c >= 'a' && c <= 'z') return int(c-'a') + ('Z'-'A') + 1; ! if (c >= '0' && c <= '9') return int(c-'0') + ('z'-'a') + ('Z'-'A') + 2; if (c == '+') return 62; if (c == '/') return 63; |