POST coding rules

xiaoxiao2021-03-06  88

This is a POST data encoding and decoding function #pragma Warning (Disable: 4786) #include #include #include #include using namespace std; // Encode const string post_encode String :: const_iterator & begin, const string :: const_iterator & end) {string ret; ret.reserve (begin, end) * 3); for (String :: const_iterator p = begin; p! = end; p) {IF (* p == ' ') RET = "% 2b"; ELSE IF (* p == ') RET =' '; ELSE IF (* p =='% ') RET = "% 25"; ELSE IF (* p == '=') RET = "% 3D"; ELSE IF (* p == '&') RET = "% 26"; ELSE IF (* P <33 || * p> 127) {char TMP = 0; RET = '%'; TMP = ((* p >> 4) & 0x0f) '0'; if (TMP> '9') TMP = 7u; RET = TMP; TMP = (* p & 0x0f) '0'; if (TMP> '9') TMP = 7u; RET = TMP;} else Ret = * P;} Return Ret;} consT string Post_encode (const string & sc) {return post_encode (s Cr.Begin (), scR.End ());} // Decoding const pair post_decode (const string :: const_iterator & begin, const string :: const_iterator & end) {pair ret; refer .first = false; string & = ret.second; rs.Rserve (distance :: const_iterator p = begin; p! = end; p) {// For speed,

Here ignore the legality verification if (* p == ' ') RS = '; ELSE IF (* p ==%') { P; if (p == end) return ret; char C1 = * p - '0'; if (c1> 9) C1 - = 7; p; if (p == end) return return; CHAR C2 = * P - '0'; IF (C2> 9) C2 - = 7; RS = ((C1 << 4) | C2);} Else RS = * P;} Ret.First = true; return ret;} const pair post_decode (const string & sc) { Return Post_Decode (Scr.Begin (), Scr.End ());} // Decoding the entire POST Const Pair > post_decodes (const string :: const_iterator & begin, const string :: const_iterator & End; {pair > ret; ret.first = false; map & hs = ret.second; string :: const_iterator p = begin, p1 = begin, p2 = begin For (; p! = End; p) {if (* p == '=') {p2 = p;} else if (* p == '&') {if (p1> = p2) / / ERROR RETURN RET; Const Pair _key = post_decode (p1, p2); if (! _key.first || _key.second.empty ()) Return Ret; P2; Const Pair _val = post_decode (p2, p); IF (! _val.first) return ret; p1 = p; p1; hs [_key.second] = _val.second;}} = f (p2! = begin) {IF (p1> = p2) // error Return Ret;

转载请注明原文地址:https://www.9cbs.com/read-104934.html

New Post(0)