Article View: borland.public.cppbuilder.internet.socket
Article #2756Re: URLEncode and Unicode
From: Mark Jacobs
Date: Tue, 31 Jan 2006 16:15
Date: Tue, 31 Jan 2006 16:15
41 lines
2433 bytes
2433 bytes
Hamid wrote:
> I'm using TNMURL to encode a url, but seemingly the component fails to encode urls containing Unicode characters. How can I solve the problem?
Here are a couple of routines. I'll leave you to work them out, and fire questions at this
post :-
AnsiString mjunescape(AnsiString webstr,bool dopls)
{
int ii,jj=webstr.Length(),kk,mm; AnsiString retv="",pschs="0123456789ABCDEF"; char ch;
for (ii=1;ii<=jj;++ii)
{
ch=webstr[ii]; if (ch=='+' && dopls) { retv+=" "; continue;}
if (ch!='%') { retv+=ch; continue;}
if (ii<jj) if (webstr[ii+1]=='%') { retv+="%"; ++ii; continue;}
if (ii<jj-1)
{
kk=pschs.Pos((char)toupper(webstr[ii+1]));
mm=pschs.Pos((char)toupper(webstr[ii+2]));
if (kk>0 && mm>0) { retv+=(char)((kk-1)*16+mm-1); ii+=2;} else retv+=ch;
}
}
return retv;
}
AnsiString mjescape(AnsiString webstr,bool dospc)
{
int ii,jj=webstr.Length(); AnsiString retv=""; char ch;
AnsiString
pschs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789*@._-$!'()%";
for (ii=1;ii<=jj;++ii)
{
ch=webstr[ii]; if (ch==' ' && dospc) { retv+="+"; continue;}
if (pschs.Pos(ch)>0) retv+=ch; else retv+="%"+IntToHex(ch,2);
}
return retv;
}
--
Mark Jacobs
http://www.dkcomputing.co.uk
Technical Details
Message-ID:
<43df8c4f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!nntp.theplanet.net!inewsm1.nntp.theplanet.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43dc6a15$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,7fe0fd91d449167c X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 31 Jan 2006 16:15:27 +0000 From: Mark Jacobs <markj@critical.co.uk> User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: URLEncode and Unicode References: <43dc6a15$1@newsgroups.borland.com> In-Reply-To: <43dc6a15$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 81.144.157.8 Message-ID: <43df8c4f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1138723919 81.144.157.8 (31 Jan 2006 08:11:59 -0700) Lines: 41 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!nntp.theplanet.net!inewsm1.nntp.theplanet.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail