static Size percentDecode( char* decoded, Size decodedLength, const char* source) { if (!decoded || !source) return 0; const char* start = decoded; decodedLength--; while (*source && decodedLength) { if (*source == '%') { if (*(source + 1) == '\0') break; *(decoded++) = static_cast<char>( (valueFromHexChar(*(source + 1)) << 4) + valueFromHexChar(*(source + 2))); source += 3; } else if (*source == '+') { *(decoded++) = ' '; source++; } else { *(decoded++) = *(source++); } decodedLength--; } *decoded = '\0'; return decoded - start; }
//URLエンコードをデコードする void urlDecode(char* decoded ,unsigned int decoded_length ,const char* source) { decoded_length--; //最後の¥0の分 while(*source && decoded_length){ if(*source == '%'){ if(*(source+1) == '\0') break; //%の後2Byte続かずに終わっている場合に備えて *(decoded++) = (valueFromHexChar( *(source+1) ) <<4 ) + valueFromHexChar( *(source+2) ); source += 3; #ifdef REPLACE_PLUS }else if(*source == '+'){ //おまけ *(decoded++) = ' '; source++; #endif }else{ *(decoded++) = *(source++); } decoded_length--; } *decoded = '\0'; }