Chinaunix首页 | 论坛 | 博客
  • 博客访问: 401183
  • 博文数量: 78
  • 博客积分: 3642
  • 博客等级: 中校
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-23 15:33
文章分类

全部博文(78)

文章存档

2007年(53)

2006年(25)

分类:

2006-11-02 18:51:39

//摘自dansguardian 

std::string ConnectionHandler::miniURLEncode(std::string s)

{
    std::string encoded;
    char* buf = new char[16]; // way longer than needed

    unsigned char c;
    for(int i=0; i < (signed)s.length(); i++)

    {
        c = s[i];
        if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||

             c == '.' || c == '-' || c == '_')

        {

            // allowed characters in a url that have non special meaning

            encoded += c;
            continue;
        }
        if(c == ' ')
        {
            encoded += '+';
            continue;
        }
        sprintf(buf, "%x", c);
        encoded += "%";
        encoded += buf;
    }
    delete[] buf;
    return encoded;
}

阅读(2280) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~