Skip to content

Commit

Permalink
D2009 + D2010 compatibility.
Browse files Browse the repository at this point in the history
OEncoding.pas failed to compile under Delphi 2009 and 2010 due to missing functionality.
  • Loading branch information
on.pokorny@gmail.com committed Feb 26, 2014
1 parent 2f9cb24 commit 35f4164
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions OEncoding.pas
Expand Up @@ -611,7 +611,8 @@ function TUnicodeEncoding.EncodingName: OWideString;
end;

procedure TUnicodeEncoding.StringToBuffer(const S: OWideString; var outBuffer: TEncodingBuffer);
var xCharCount: Integer;
var
xCharCount: Integer;
{$IFDEF FPC}
xUS: UnicodeString;
{$ENDIF}
Expand Down Expand Up @@ -707,26 +708,12 @@ function TUTF8Encoding.GetBOM: TEncodingBuffer;
end;

procedure TUTF8Encoding.BufferToString(const aBytes: TEncodingBuffer; var outString: OWideString);
{$IFNDEF FPC}
var
xLen: Integer;
{$ENDIF}
begin
{$IFDEF FPC}
outString := aBytes;
{$ELSE}
//DELPHI
//outString := UTF8Decode(aBytes);
xLen := Length(aBytes);
SetLength(outString, xLen);
if xLen > 0 then
begin
xLen := Utf8ToUnicode(PWideChar(outString), xLen+1, PAnsiChar(aBytes), xLen);
if xLen > 0 then
SetLength(outString, xLen-1)
else
outString := '';
end;
outString := UTF8Decode(aBytes);
{$ENDIF}
end;

Expand Down Expand Up @@ -856,13 +843,21 @@ function TEncodingHelper.EncodingAlias: String;

class function TEncodingHelper.GetEncodingFromBOM(const aBuffer: TEncodingBuffer; var outEncoding: TEncoding): Integer;
begin
outEncoding := nil;//must be here: otherwise if outEncoding<>nil, GetBufferEncoding would check only towards outEncoding
Result := Self.GetBufferEncoding(aBuffer, outEncoding);
end;

class function TEncodingHelper.GetEncodingFromBOM(const aBuffer: TEncodingBuffer; var outEncoding: TEncoding;
aDefaultEncoding: TEncoding): Integer;
begin
outEncoding := nil;//must be here: otherwise if outEncoding<>nil, GetBufferEncoding would check only towards outEncoding
{$IFDEF O_DELPHI_XE_UP}
Result := Self.GetBufferEncoding(aBuffer, outEncoding, aDefaultEncoding);
{$ELSE}
Result := Self.GetBufferEncoding(aBuffer, outEncoding);
if Result = 0 then//BOM not found
outEncoding := aDefaultEncoding;
{$ENDIF}
end;

function TEncodingHelper.GetBOM: TEncodingBuffer;
Expand Down

0 comments on commit 35f4164

Please sign in to comment.