mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 13:49:39 +02:00
* Allow to skip whitespace
This commit is contained in:
parent
8e7791ac23
commit
168cb8f2ca
@ -62,11 +62,11 @@ Type
|
|||||||
Function Encode(const aBuffer : AnsiString; doPad : Boolean = True) : AnsiString; overload;
|
Function Encode(const aBuffer : AnsiString; doPad : Boolean = True) : AnsiString; overload;
|
||||||
// Decode aSrcBuffer with length aLen.
|
// Decode aSrcBuffer with length aLen.
|
||||||
// Buffer must have enough room. Calculate maximum needed room with GetDecodeLen
|
// Buffer must have enough room. Calculate maximum needed room with GetDecodeLen
|
||||||
Function Decode(const aSrcBuffer : PByte; aLen : Integer; ABuffer : PByte) : Integer; virtual; overload;
|
Function Decode(const aSrcBuffer : PByte; aLen : Integer; ABuffer : PByte; SkipWhiteSpace : Boolean = True) : Integer; virtual; overload;
|
||||||
// Buffer must have enough room. Calculate maximum needed room with GetDecodeLen
|
// Buffer must have enough room. Calculate maximum needed room with GetDecodeLen
|
||||||
Function Decode(const S : AnsiString; ABuffer : PByte) : Integer; overload;
|
Function Decode(const S : AnsiString; ABuffer : PByte; SkipWhiteSpace : Boolean = True) : Integer; overload;
|
||||||
// Return a buffer with decoded data.
|
// Return a buffer with decoded data.
|
||||||
Function Decode(const S : AnsiString) : TBytes; overload;
|
Function Decode(const S : AnsiString; SkipWhiteSpace : Boolean = True) : TBytes; overload;
|
||||||
// Return a buffer with decoded data, starting with buffer.
|
// Return a buffer with decoded data, starting with buffer.
|
||||||
Function Decode(const aBuffer: PByte; aLen : Integer) : TBytes; overload;
|
Function Decode(const aBuffer: PByte; aLen : Integer) : TBytes; overload;
|
||||||
// Get a decoding length for the encoded string S. May be oversized due to padding.
|
// Get a decoding length for the encoded string S. May be oversized due to padding.
|
||||||
@ -209,7 +209,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function TAlphabetEncoder.Decode(const aSrcBuffer : PByte; aLen : Integer; ABuffer : PByte) : Integer;
|
Function TAlphabetEncoder.Decode(const aSrcBuffer : PByte; aLen : Integer; ABuffer : PByte;SkipWhiteSpace : Boolean = True) : Integer;
|
||||||
|
|
||||||
|
Const
|
||||||
|
WhiteSpace = [Ord(' '),10,13,9];
|
||||||
|
|
||||||
var
|
var
|
||||||
i, Reg, lBits : Integer;
|
i, Reg, lBits : Integer;
|
||||||
@ -224,8 +227,19 @@ begin
|
|||||||
if Alen=0 then exit;
|
if Alen=0 then exit;
|
||||||
pSrc:=@aSrcBuffer[0];
|
pSrc:=@aSrcBuffer[0];
|
||||||
pDest:=aBuffer;
|
pDest:=aBuffer;
|
||||||
for i:=1 to aLen do
|
I:=1;
|
||||||
|
While (i<=aLen) do
|
||||||
begin
|
begin
|
||||||
|
if SkipWhiteSpace then
|
||||||
|
begin
|
||||||
|
While (PSrc^ in WhiteSpace) and (I<=aLen) do
|
||||||
|
begin
|
||||||
|
Inc(PSrc);
|
||||||
|
Inc(I);
|
||||||
|
end;
|
||||||
|
if I>aLen then
|
||||||
|
break;
|
||||||
|
end;
|
||||||
if Reverse[pSrc^] <= 0 then
|
if Reverse[pSrc^] <= 0 then
|
||||||
break;
|
break;
|
||||||
Reg:=Reg shl Bits;
|
Reg:=Reg shl Bits;
|
||||||
@ -238,6 +252,7 @@ begin
|
|||||||
inc(pDest);
|
inc(pDest);
|
||||||
end;
|
end;
|
||||||
inc(pSrc);
|
inc(pSrc);
|
||||||
|
Inc(i);
|
||||||
end;
|
end;
|
||||||
Result:=pDest-aBuffer;
|
Result:=pDest-aBuffer;
|
||||||
end;
|
end;
|
||||||
@ -250,12 +265,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TAlphabetEncoder.Decode(const S: AnsiString): TBytes;
|
function TAlphabetEncoder.Decode(const S: AnsiString; SkipWhiteSpace : Boolean = True): TBytes;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=[];
|
Result:=[];
|
||||||
SetLength(Result,GetDecodeLen(S));
|
SetLength(Result,GetDecodeLen(S));
|
||||||
SetLength(Result,Decode(S,PByte(Result)));
|
SetLength(Result,Decode(S,PByte(Result),SkipWhiteSpace));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -268,10 +283,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function TAlphabetEncoder.Decode(const S : AnsiString; ABuffer : PByte) : Integer; overload;
|
Function TAlphabetEncoder.Decode(const S : AnsiString; ABuffer : PByte;SkipWhiteSpace : Boolean = True) : Integer; overload;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=Decode(PByte(S),Length(S),ABuffer);
|
Result:=Decode(PByte(S),Length(S),ABuffer,SkipWhiteSpace);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user