Registriert seit: 2. Mär 2004
5.508 Beiträge
Delphi 5 Professional
|
Re: Code7 (Ansi/Wide <> 7 Bit)
27. Nov 2006, 18:44
Zitat von himitsu:
So, ich hab hier mal 'ne Codierung in einem 7-Bit-Format
Handelt es sich hierbei um UTF-7 ?
Dann mein Vorschlag:
Delphi-Quellcode:
function StringToWideStringEx(const S: string; CodePage: Word): WideString;
var
InputLength,
OutputLength: Integer;
begin
InputLength := Length(S);
OutputLength := MultiByteToWideChar(CodePage, 0, PChar(S), InputLength, nil, 0);
SetLength(Result, OutputLength);
MultiByteToWideChar(CodePage, 0, PChar(S), InputLength, PWideChar(Result), OutputLength);
end;
function WideStringToStringEx(const WS: WideString; CodePage: Word): string;
var
InputLength,
OutputLength: Integer;
begin
InputLength := Length(WS);
OutputLength := WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, nil, 0, nil, nil);
SetLength(Result, OutputLength);
WideCharToMultiByte(CodePage, 0, PWideChar(WS), InputLength, PChar(Result), OutputLength, nil, nil);
end;
function UTF8ToWideString(const S: string): WideString;
begin
Result := StringToWideStringEx(S, CP_UTF8);
end;
function WideStringToUTF8(const WS: WideString): string;
begin
Result := WideStringToStringEx(WS, CP_UTF8);
end;
function UTF7ToWideString(const S: string): WideString;
begin
Result := StringToWideStringEx(S, CP_UTF7);
end;
function WideStringToUTF7(const WS: WideString): string;
begin
Result := WideStringToStringEx(WS, CP_UTF7);
end;
PS: beide Code-Varianten haben ihre Daseinsberechtigung. Meine Version läuft natürlich nur unter Win32.
Andreas
|
|
Zitat
|