Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code to which you link does not work. The <code>PunycodeDecode</code> function is broken. Line 416 reads:</p> <pre><code>move(output[i], output[i + 1], (outidx - i) * SizeOf(output^)); </code></pre> <p>This is a mis-translation from C. Instead it should read:</p> <pre><code>move(output[i], output[i + 1], (outidx - i) * SizeOf(output^[0])); </code></pre> <p>After making this change, I successfully tested the following program:</p> <pre><code>program Punycode; {$APPTYPE CONSOLE} uses SysUtils, dorPunyCode in 'dorPunyCode.pas'; function PEncode(const str: UnicodeString): AnsiString; var len: Cardinal; begin if str = '' then begin Result := ''; exit; end; if (PunycodeEncode(Length(str), PPunyCode(str), len) = pcSuccess) and (Length(str) + 1 &lt;&gt; len) then begin SetLength(Result, len); PunycodeEncode(Length(str), PPunyCode(str), len, PByte(Result)); end else Result := str; end; function PDecode(const str: AnsiString): UnicodeString; var outputlen: Cardinal; begin if str = '' then begin Result := ''; exit; end; outputlen := 0; if (PunycodeDecode(Length(str), PByte(str), outputlen) = pcSuccess) and (Length(str) + 1 &lt;&gt; outputlen) then begin SetLength(Result, outputlen); PunycodeDecode(Length(str), PByte(str), outputlen, PPunycode(Result)); end else Result := str; end; procedure Test(const Input: UnicodeString); begin if PDecode(PEncode(Input))&lt;&gt;Input then raise EAssertionFailed.CreateFmt('Round-trip failed: %s', [Input]); end; begin Test('http://президент.рф/'); Test('David Heffernan'); Test(''); Test('A'); end. </code></pre> <p>However, I know exactly nothing about Punycode and in particular I've no idea what the point of the <code>'xn--'</code> prefix that is added at the question to which you linked. So the <code>PEncode</code> and <code>PDecode</code> routines that I show above are probably not exactly what you need.</p> <p>I am extremely dubious of the Delphi code in the <code>dorPunyCode</code> unit and I suspect that there are other problems lurking. In your position I would get hold of <code>punycode.c</code>, compile it with <code>bcc32</code> and then link to it with <code>$L</code>. I would regard that as much more trustworthy than this <code>dorPunyCode</code> unit.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload