C / C ++的网址去code库 [英] C/C++ URL decode library

查看:177
本文介绍了C / C ++的网址去code库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发Linux上的C / C ++程序。你能告诉我,如果有任何C / C ++库,德codeS网址是什么?

I am developing a c/c++ program on linux. Can you please tell me if there is any c/c++ library which decodes url?

我要寻找的库,
兑换
的http%3A%2F%2F
至:
HTTP://

I am looking for libraries which convert "http%3A%2F%2F" to: "http://"


A + T +%26 + T到T& T公司

or "a+t+%26+t" to "a t & t"

感谢您。

推荐答案

我实际使用扫罗的功能分析程序我写(分析数以百万计的URL连接codeD字符串),而它的工作原理,在那个尺度这是可怕的下降减缓我的计划,所以我决定写一个更快的版本。当GCC和-O2选项编译这一个是成千上万倍的速度。它也可以使用相同的输出缓冲器的输入(如urlde code2(BUF,BUF)会工作,如果原来的字符串是BUF,是由其德codeD对口被覆盖)。

I actually used Saul's function in an analysis program I was writing (analyzing millions of URL encoded strings), and while it works, at that scale it was slowing my program down horribly, so I decided to write a faster version. This one is thousands of times faster when compiled with GCC and the -O2 option. It can also use the same output buffer as the input (e.g. urldecode2(buf, buf) will work if the original string was in buf and is to be overwritten by its decoded counterpart).

修改因为假定缓冲区将足够大它并不需要的缓冲器大小作为输入,这是安全的,因为它是已知的,输出的长度将总是是< =,输入的,所以无论是使用相同的缓冲区输出或创建一个是至少输入+ 1为空终止的大小,例如:

It doesn't take the buffer size as an input because it is assumed that the buffer will be large enough, this is safe because it is known that the length of the output will always be <= that of the input, so either use the same buffer for the output or create one that's at least the size of the input + 1 for the null terminator, e.g.:

char *output = malloc(strlen(input)+1);
urldecode2(output, input);
printf("Decoded string: %s\n", output);

编辑2:匿名用户试图编辑这个答案来处理+字的翻译',我想大概应该做的,这同样是没有的东西,我需要我的应用程序,但我下面添加了。

Edit 2: An anonymous user attempted to edit this answer to handle the '+' character's translation to ' ', which I think it should probably do, again this wasn't something that I needed for my application, but I've added it below.

下面是常规:

#include <stdlib.h>
#include <ctype.h>

void urldecode2(char *dst, const char *src)
{
        char a, b;
        while (*src) {
                if ((*src == '%') &&
                    ((a = src[1]) && (b = src[2])) &&
                    (isxdigit(a) && isxdigit(b))) {
                        if (a >= 'a')
                                a -= 'a'-'A';
                        if (a >= 'A')
                                a -= ('A' - 10);
                        else
                                a -= '0';
                        if (b >= 'a')
                                b -= 'a'-'A';
                        if (b >= 'A')
                                b -= ('A' - 10);
                        else
                                b -= '0';
                        *dst++ = 16*a+b;
                        src+=3;
                } else if (*src == '+') {
                        *dst++ = ' ';
                        src++;
                } else {
                        *dst++ = *src++;
                }
        }
        *dst++ = '\0';
}

这篇关于C / C ++的网址去code库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆