Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the complete code that solved my problem:</p> <pre> function Unescape(const s: AnsiString): string; var i: Integer; j: Integer; c: Integer; begin // Make result at least large enough. This prevents too many reallocs SetLength(Result, Length(s)); i := 1; j := 1; while i &lt;= Length(s) do begin if s[i] = '\' then begin if i &lt; Length(s) then begin // escaped backslash? if s[i + 1] = '\' then begin Result[j] := '\'; inc(i, 2); end // convert hex number to WideChar else if (s[i + 1] = 'u') and (i + 1 + 4 &lt;= Length(s)) and TryStrToInt('$' + string(Copy(s, i + 2, 4)), c) then begin inc(i, 6); Result[j] := WideChar(c); end else begin raise Exception.CreateFmt('Invalid code at position %d', [i]); end; end else begin raise Exception.Create('Unexpected end of string'); end; end else begin Result[j] := WideChar(s[i]); inc(i); end; inc(j); end; // Trim result in case we reserved too much space SetLength(Result, j - 1); end; const NormalizationC = 1; function NormalizeString(NormForm: Integer; lpSrcString: LPCWSTR; cwSrcLength: Integer; lpDstString: LPWSTR; cwDstLength: Integer): Integer; stdcall; external 'Normaliz.dll'; function Normalize(const s: string): string; var newLength: integer; begin // in NormalizationC mode the result string won't grow longer than the input string SetLength(Result, Length(s)); newLength := NormalizeString(NormalizationC, PChar(s), Length(s), PChar(Result), Length(Result)); SetLength(Result, newLength); end; function UnescapeAndNormalize(const s: AnsiString): string; begin Result := Normalize(Unescape(s)); end; </pre> <p>Thank you all! I am sure that my first experience with StackOverflow won't be my last one :-) </p>
 

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