コード例 #1
0
std::string escapeURL(const std::string &URL)
{
	std::string result = "";
	for ( unsigned int i=0; i<URL.size(); i++ ) {
		char c = URL[i];
		if (
			( '0'<=c && c<='9' ) ||
			( 'a'<=c && c<='z' ) ||
			( 'A'<=c && c<='Z' ) ||
			c=='/' || c=='.'
			) {
				result += c;
		} else {
			int j = (short int)c;
			if ( j < 0 ) {
				j += 256;
			}
			int i1, i0;
			i1 = j / 16;
			i0 = j - i1*16;
			result += '%';
			result += dec2hexChar(i1);
			result += dec2hexChar(i0);
		}
	}
	return result;
}
コード例 #2
0
ファイル: screen.cpp プロジェクト: Abdillah/editor
string prettychar(char c){
	if(c==0)return "\\0";
	if(c==9)return "\\t";
	if(c==10)return "\\n";
	if(c==127)return "\\b";
	//if(c<0)return string(1,(char)(192+(((unsigned char)c)>>6)))+(char)(128+(((unsigned char)c)&0x3f)); //utf-8 fanciness
	if(c>0&&c<28)return string(1,'^')+(char)('A'+c-1);
	if(c<32)return string("\\x")+dec2hexChar(((unsigned char)c)/16)+dec2hexChar(((unsigned char)c)%16);
	return string(1,c);
}
コード例 #3
0
ファイル: GlobalHelpers.cpp プロジェクト: BNUACM/bnuoj-vjudge
string sha1String(string msg) {
  unsigned char hash[SHA_DIGEST_LENGTH];
  string hexhash;
  SHA1(reinterpret_cast<const unsigned char *>(msg.c_str()), msg.size(), hash);
  for (int i = 0; i < SHA_DIGEST_LENGTH; i++) {
    hexhash += dec2hexChar(hash[i]/16);
    hexhash += dec2hexChar(hash[i]%16);
  }
  return toLowerCase(hexhash);
}