mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 08:51:10 +02:00
TEncoding: fix base convert functions for empty inputs
git-svn-id: trunk@46430 -
This commit is contained in:
parent
56613723b9
commit
38c7659d07
@ -38,7 +38,10 @@ end;
|
|||||||
|
|
||||||
function TEncoding.GetAnsiBytes(const S: string): TBytes;
|
function TEncoding.GetAnsiBytes(const S: string): TBytes;
|
||||||
begin
|
begin
|
||||||
Result := GetAnsiBytes(S, 1, Length(S));
|
if S='' then
|
||||||
|
Result := nil
|
||||||
|
else
|
||||||
|
Result := GetAnsiBytes(S, 1, Length(S));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetAnsiBytes(const S: string; CharIndex, CharCount: Integer
|
function TEncoding.GetAnsiBytes(const S: string; CharIndex, CharCount: Integer
|
||||||
@ -49,7 +52,10 @@ end;
|
|||||||
|
|
||||||
function TEncoding.GetAnsiString(const Bytes: TBytes): string;
|
function TEncoding.GetAnsiString(const Bytes: TBytes): string;
|
||||||
begin
|
begin
|
||||||
Result := GetAnsiString(Bytes, 0, Length(Bytes));
|
if Length(Bytes)=0 then
|
||||||
|
Result := ''
|
||||||
|
else
|
||||||
|
Result := GetAnsiString(Bytes, 0, Length(Bytes));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetAnsiString(const Bytes: TBytes; ByteIndex,
|
function TEncoding.GetAnsiString(const Bytes: TBytes; ByteIndex,
|
||||||
@ -294,7 +300,10 @@ end;
|
|||||||
|
|
||||||
function TEncoding.GetByteCount(const Chars: TUnicodeCharArray): Integer;
|
function TEncoding.GetByteCount(const Chars: TUnicodeCharArray): Integer;
|
||||||
begin
|
begin
|
||||||
Result := GetByteCount(Chars, 0, Length(Chars));
|
if Length(Chars)=0 then
|
||||||
|
Result := 0
|
||||||
|
else
|
||||||
|
Result := GetByteCount(Chars, 0, Length(Chars));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetByteCount(const Chars: TUnicodeCharArray; CharIndex,
|
function TEncoding.GetByteCount(const Chars: TUnicodeCharArray; CharIndex,
|
||||||
@ -309,7 +318,10 @@ end;
|
|||||||
|
|
||||||
function TEncoding.GetByteCount(const S: UnicodeString): Integer;
|
function TEncoding.GetByteCount(const S: UnicodeString): Integer;
|
||||||
begin
|
begin
|
||||||
Result := GetByteCount(PUnicodeChar(S), Length(S));
|
if S='' then
|
||||||
|
Result := 0
|
||||||
|
else
|
||||||
|
Result := GetByteCount(PUnicodeChar(S), Length(S));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetByteCount(const S: UnicodeString; CharIndex, CharCount: Integer): Integer;
|
function TEncoding.GetByteCount(const S: UnicodeString; CharIndex, CharCount: Integer): Integer;
|
||||||
@ -324,7 +336,8 @@ end;
|
|||||||
function TEncoding.GetBytes(const Chars: TUnicodeCharArray): TBytes;
|
function TEncoding.GetBytes(const Chars: TUnicodeCharArray): TBytes;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, GetByteCount(Chars));
|
SetLength(Result, GetByteCount(Chars));
|
||||||
GetBytes(@Chars[0], Length(Chars), @Result[0], Length(Result));
|
if Length(Result)>0 then
|
||||||
|
GetBytes(@Chars[0], Length(Chars), @Result[0], Length(Result));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetBytes(const Chars: TUnicodeCharArray; CharIndex,
|
function TEncoding.GetBytes(const Chars: TUnicodeCharArray; CharIndex,
|
||||||
@ -358,7 +371,8 @@ end;
|
|||||||
function TEncoding.GetBytes(const S: UnicodeString): TBytes;
|
function TEncoding.GetBytes(const S: UnicodeString): TBytes;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, GetByteCount(S));
|
SetLength(Result, GetByteCount(S));
|
||||||
GetBytes(@S[1], Length(S), @Result[0], Length(Result));
|
if Length(Result)>0 then
|
||||||
|
GetBytes(@S[1], Length(S), @Result[0], Length(Result));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetBytes(const S: UnicodeString; CharIndex, CharCount: Integer;
|
function TEncoding.GetBytes(const S: UnicodeString; CharIndex, CharCount: Integer;
|
||||||
@ -380,7 +394,10 @@ end;
|
|||||||
|
|
||||||
function TEncoding.GetCharCount(const Bytes: TBytes): Integer;
|
function TEncoding.GetCharCount(const Bytes: TBytes): Integer;
|
||||||
begin
|
begin
|
||||||
Result := GetCharCount(@Bytes[0], Length(Bytes));
|
if Length(Bytes)=0 then
|
||||||
|
Result := 0
|
||||||
|
else
|
||||||
|
Result := GetCharCount(@Bytes[0], Length(Bytes));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetCharCount(const Bytes: TBytes; ByteIndex,
|
function TEncoding.GetCharCount(const Bytes: TBytes; ByteIndex,
|
||||||
@ -394,7 +411,8 @@ end;
|
|||||||
function TEncoding.GetChars(const Bytes: TBytes): TUnicodeCharArray;
|
function TEncoding.GetChars(const Bytes: TBytes): TUnicodeCharArray;
|
||||||
begin
|
begin
|
||||||
SetLength(Result, GetCharCount(Bytes));
|
SetLength(Result, GetCharCount(Bytes));
|
||||||
GetChars(@Bytes[0], Length(Bytes), @Result[0], Length(Result));
|
if Length(Result)>0 then
|
||||||
|
GetChars(@Bytes[0], Length(Bytes), @Result[0], Length(Result));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetChars(const Bytes: TBytes; ByteIndex, ByteCount: Integer): TUnicodeCharArray;
|
function TEncoding.GetChars(const Bytes: TBytes; ByteIndex, ByteCount: Integer): TUnicodeCharArray;
|
||||||
@ -444,8 +462,13 @@ function TEncoding.GetString(const Bytes: TBytes): UnicodeString;
|
|||||||
var
|
var
|
||||||
Chars: TUnicodeCharArray;
|
Chars: TUnicodeCharArray;
|
||||||
begin
|
begin
|
||||||
Chars := GetChars(Bytes);
|
if Length(Bytes)=0 then
|
||||||
SetString(Result, PUnicodeChar(Chars), Length(Chars));
|
Result := ''
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Chars := GetChars(Bytes);
|
||||||
|
SetString(Result, PUnicodeChar(Chars), Length(Chars));
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEncoding.GetString(const Bytes: TBytes; ByteIndex, ByteCount: Integer): UnicodeString;
|
function TEncoding.GetString(const Bytes: TBytes; ByteIndex, ByteCount: Integer): UnicodeString;
|
||||||
|
Loading…
Reference in New Issue
Block a user