jinyedge's note
{http://www.jinyedge.pe.kr}
Hi, this is jinyedge. I'm a software developer.
I hope you can find some useful information
in my homepage.
jinyedge at gmail.com
Since 2001.12.05
|
|
| Subj: C, punycode2unicode with idnkit. |
|
|
Mtime: 2010-03-09 23:12:47 |
|
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <idn/api.h>
#include <curl/curl.h>
//---------------------------------------------------------------------
char* punycode2unicode_idnkit(char* url){
char* protocol = (char*)"";
char* res_url = NULL;
if(!url){
return NULL;
}
char* dec_url = curl_easy_unescape(NULL, url, 0, NULL);
if(strncmp("http://", dec_url, 7) == 0){
protocol = (char*)"http://";
}
else if(strncmp("https://", dec_url, 8) == 0){
protocol = (char*)"https://";
}
char* temp_url = (char*)calloc(strlen(url) * 2, sizeof(char));
idn_result_t r = idn_decodename(IDN_DECODE_APP, dec_url + strlen(protocol), temp_url, strlen(url) * 2);
if(r != idn_success){
res_url = strdup(dec_url);
}
else{
res_url = (char*)calloc(strlen(temp_url + strlen(protocol) + 1), sizeof(char));
sprintf(res_url, "%s%s", protocol, temp_url);
}
curl_free(dec_url);
free(temp_url);
return res_url;
}
//---------------------------------------------------------------------
int main(int argc, char** argv){
char* url = "http://www.xn--rksmrgsa-0zap8p.com";
char* res = punycode2unicode_idnkit(url);
puts(res);
free(res);
url = "http://xn--rksmrgsa-0zap8p.com";
res = punycode2unicode_idnkit(url);
puts(res);
free(res);
}
|
|
|
|
|