有一段javascript算法,需要翻译为delphi,请高手解答
function utf8(wide)
{
var c,s;
var enc='';
var i=0;
while(i<wide.length)
{
c=wide.charCodeAt(i++);
if(c>=0xDC00&&c<0xE000)continue;
if(c>=0xD800&&c<0xDC00)
{
if(i>=wide.length)continue;
s=wide.charCodeAt(i++);
if(s<0xDC00||c>=0xDE00)continue;
c=((c-0xD800)<<10)+(s-0xDC00)+0x10000;
}
if(c<0x80)enc+=String.fromCharCode(c);
else if(c<0x800)enc+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
else if(c<0x10000)enc+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
else enc+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
}
return enc;
}
var hexchars="0123456789ABCDEF";
var okURIchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
function toHex(n)
{
return hexchars.charAt(n>>4)+hexchars.charAt(n&0xF);
}
function encodeURIComponentNew(s)
{
var s=utf8(s);
var c;
var enc='';
for(var i=0;i<s.length;i++)
{
if(okURIchars.indexOf(s.charAt(i))==-1)
enc+='%'+toHex(s.charCodeAt(i));
else
enc+=s.charAt(i);
}
return enc;
}
function utf8(wide)
{
var c,s;
var enc='';
var i=0;
while(i<wide.length)
{
c=wide.charCodeAt(i++);
if(c>=0xDC00&&c<0xE000)continue;
if(c>=0xD800&&c<0xDC00)
{
if(i>=wide.length)continue;
s=wide.charCodeAt(i++);
if(s<0xDC00||c>=0xDE00)continue;
c=((c-0xD800)<<10)+(s-0xDC00)+0x10000;
}
if(c<0x80)enc+=String.fromCharCode(c);
else if(c<0x800)enc+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
else if(c<0x10000)enc+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
else enc+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
}
return enc;
}
var hexchars="0123456789ABCDEF";
var okURIchars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
function toHex(n)
{
return hexchars.charAt(n>>4)+hexchars.charAt(n&0xF);
}
function encodeURIComponentNew(s)
{
var s=utf8(s);
var c;
var enc='';
for(var i=0;i<s.length;i++)
{
if(okURIchars.indexOf(s.charAt(i))==-1)
enc+='%'+toHex(s.charCodeAt(i));
else
enc+=s.charAt(i);
}
return enc;
}
解决方案 »
- insert into插入时间的问题,实在不行了
- 如下
- 这段连接SQL的代码有啥问题?
- 怎样将dbgrid中的数据导出到excel或文本文件中
- 求助!nasm编译出来的bin文件怎么用?
- DELPHI,JSP,PB你会选择哪一个?...... 人人有分!
- 关于取其它程序控件文本的问题
- oracle中创建作业的一个问题 万分紧急
- 请问用TBitmap创建位图,并写上字后,如何保存成16色的位图?默认创建的是高彩色的。
- 如何让数据链结窗口弹出?
- [help] delphi field 'xxxx' cannot be modified
- 请问各位大侠,javascript如何调用delphi函数!急!!!
procedure utf8(wide:wchar)
var c,s:wchar;
var enc :string;
var i :integer; begin
i :=0;
while(i < legnth(wide) )
begin
c :=wide.charCodeAt(inc(i) );
if ((c>=$DC00) and c <$E000)) then
continue;
//--自己来吧,主要是主意多字符问题
//---------------to do
if(c>=0xD800&&c <0xDC00)
{
if(i>=wide.length)continue;
s=wide.charCodeAt(i++);
if(s <0xDC00||c>=0xDE00)continue;
c=((c-0xD800) < <10)+(s-0xDC00)+0x10000;
}
if(c <0x80)enc+=String.fromCharCode(c);
else if(c <0x800)enc+=String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
else if(c <0x10000)enc+=String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
else enc+=String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
}
return enc;
}