Bjørnar,
> Arno,
>
>> The only workaround that comes to my mind was another overload that
>> takes
>> a RawByteString instead of string. I won't use AnsiString because
>> implicit ansi string casts must be avoided too.
>
> That would work for me. I'm not very familiar with the use of
> RawByteString, but I made version of the function that works for me,
> do you think this version would work for others too (I just testet in
> 2010 C++ builder):
The new overload is only required in RDS 2009+.
It has to be conditional compiled for other reasons too, please try the
following code and let me know how it works for you, first declaration
just got the overload directive:
function UrlDecode(const S : String;
SrcCodePage : LongWord = CP_ACP;
DetectUtf8 : Boolean = TRUE) : String; overload;
{$IFDEF COMPILER12_UP}
function UrlDecode(const S: RawByteString;
SrcCodePage: LongWord = CP_ACP;
DetectUtf8: Boolean = TRUE) : UnicodeString; overload;
{$ENDIF}
{$IFDEF COMPILER12_UP}
function UrlDecode(const S: RawByteString; SrcCodePage: LongWord = CP_ACP;
DetectUtf8: Boolean = TRUE) : UnicodeString;
var
I, J, L : Integer;
U8Str : AnsiString;
Ch : AnsiChar;
begin
L := Length(S);
SetLength(U8Str, L);
I := 1;
J := 0;
while (I <= L) and (S[I] <> '&') do begin
Ch := AnsiChar(S[I]);
if Ch = '%' then begin
Ch := AnsiChar(htoi2(PAnsiChar(@S[I + 1])));
Inc(I, 2);
end
else if Ch = '+' then
Ch := ' ';
Inc(J);
U8Str[J] := Ch;
Inc(I);
end;
SetLength(U8Str, J);
if (SrcCodePage = CP_UTF8) or (DetectUtf8 and IsUtf8Valid(U8Str)) then
Result := Utf8ToStringW(U8Str)
else
Result := AnsiToUnicode(U8Str, SrcCodePage);
end;
{$ENDIF}
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be