|
@@ -15,7 +15,7 @@ uses
|
|
resourcestring
|
|
resourcestring
|
|
SAlphabetNil = 'Alphabet Instance cannot be Nil "%s"';
|
|
SAlphabetNil = 'Alphabet Instance cannot be Nil "%s"';
|
|
SUnExpectedCharacter =
|
|
SUnExpectedCharacter =
|
|
- 'Unexpected Character "%s" In The Middle Of a Regular Block';
|
|
|
|
|
|
+ 'Unexpected Shortcut Character In The Middle Of a Regular Block';
|
|
|
|
|
|
type
|
|
type
|
|
TBase85 = class sealed(TInterfacedObject, IBase85)
|
|
TBase85 = class sealed(TInterfacedObject, IBase85)
|
|
@@ -35,7 +35,7 @@ type
|
|
numBytesToWrite: Int32); static; inline;
|
|
numBytesToWrite: Int32); static; inline;
|
|
|
|
|
|
class procedure WriteShortcut(var pOutput: PByte; blockIndex: Int32;
|
|
class procedure WriteShortcut(var pOutput: PByte; blockIndex: Int32;
|
|
- c: Char; value: Int64); static; inline;
|
|
|
|
|
|
+ value: Int64); static; inline;
|
|
|
|
|
|
class function GetDecodeBufferLength(textLen: Int32;
|
|
class function GetDecodeBufferLength(textLen: Int32;
|
|
usingShortcuts: Boolean): Int32; static; inline;
|
|
usingShortcuts: Boolean): Int32; static; inline;
|
|
@@ -57,7 +57,8 @@ type
|
|
: TSimpleBaseLibByteArray; overload;
|
|
: TSimpleBaseLibByteArray; overload;
|
|
|
|
|
|
procedure WriteOutput(var pOutput: PChar; const table: String; input: Int64;
|
|
procedure WriteOutput(var pOutput: PChar; const table: String; input: Int64;
|
|
- stringLength: Int32; hasShortcut: Boolean); inline;
|
|
|
|
|
|
+ stringLength: Int32; usesZeroShortcut, usesSpaceShortcut
|
|
|
|
+ : Boolean); inline;
|
|
|
|
|
|
public
|
|
public
|
|
|
|
|
|
@@ -94,27 +95,27 @@ implementation
|
|
{ TBase85 }
|
|
{ TBase85 }
|
|
|
|
|
|
procedure TBase85.WriteOutput(var pOutput: PChar; const table: String;
|
|
procedure TBase85.WriteOutput(var pOutput: PChar; const table: String;
|
|
- input: Int64; stringLength: Int32; hasShortcut: Boolean);
|
|
|
|
|
|
+ input: Int64; stringLength: Int32; usesZeroShortcut, usesSpaceShortcut
|
|
|
|
+ : Boolean);
|
|
var
|
|
var
|
|
i: Int32;
|
|
i: Int32;
|
|
result: Int64;
|
|
result: Int64;
|
|
begin
|
|
begin
|
|
- // handle "z" shortcut
|
|
|
|
- if (hasShortcut) then
|
|
|
|
|
|
+ // handle shortcuts
|
|
|
|
+ if (input = 0) and (usesZeroShortcut) then
|
|
begin
|
|
begin
|
|
- if (input = 0) then
|
|
|
|
- begin
|
|
|
|
- pOutput^ := Falphabet.AllZeroShortcut;
|
|
|
|
- System.Inc(pOutput);
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
- if (input = allSpace) then
|
|
|
|
- begin
|
|
|
|
- pOutput^ := Falphabet.AllSpaceShortcut;
|
|
|
|
- System.Inc(pOutput);
|
|
|
|
- Exit;
|
|
|
|
- end;
|
|
|
|
|
|
+ pOutput^ := Falphabet.AllZeroShortcut;
|
|
|
|
+ System.Inc(pOutput);
|
|
|
|
+ Exit;
|
|
end;
|
|
end;
|
|
|
|
+
|
|
|
|
+ if (input = allSpace) and (usesSpaceShortcut) then
|
|
|
|
+ begin
|
|
|
|
+ pOutput^ := Falphabet.AllSpaceShortcut;
|
|
|
|
+ System.Inc(pOutput);
|
|
|
|
+ Exit;
|
|
|
|
+ end;
|
|
|
|
+
|
|
// map the 4-byte packet to to 5-byte octets
|
|
// map the 4-byte packet to to 5-byte octets
|
|
i := stringBlockSize - 1;
|
|
i := stringBlockSize - 1;
|
|
while i >= 0 do
|
|
while i >= 0 do
|
|
@@ -146,12 +147,11 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
class procedure TBase85.WriteShortcut(var pOutput: PByte; blockIndex: Int32;
|
|
class procedure TBase85.WriteShortcut(var pOutput: PByte; blockIndex: Int32;
|
|
- c: Char; value: Int64);
|
|
|
|
|
|
+ value: Int64);
|
|
begin
|
|
begin
|
|
if (blockIndex <> 0) then
|
|
if (blockIndex <> 0) then
|
|
begin
|
|
begin
|
|
- raise EArgumentSimpleBaseLibException.CreateResFmt
|
|
|
|
- (@SUnExpectedCharacter, [c]);
|
|
|
|
|
|
+ raise EArgumentSimpleBaseLibException.CreateRes(@SUnExpectedCharacter);
|
|
end;
|
|
end;
|
|
WriteDecodedValue(pOutput, value, byteBlockSize);
|
|
WriteDecodedValue(pOutput, value, byteBlockSize);
|
|
end;
|
|
end;
|
|
@@ -204,8 +204,8 @@ begin
|
|
end;
|
|
end;
|
|
allZeroChar := Falphabet.AllZeroShortcut;
|
|
allZeroChar := Falphabet.AllZeroShortcut;
|
|
allSpaceChar := Falphabet.AllSpaceShortcut;
|
|
allSpaceChar := Falphabet.AllSpaceShortcut;
|
|
- checkZero := allZeroChar <> TBase85Alphabet.NoShortcut;
|
|
|
|
- checkSpace := allSpaceChar <> TBase85Alphabet.NoShortcut;
|
|
|
|
|
|
+ checkZero := allZeroChar <> TBase85Alphabet.NullChar;
|
|
|
|
+ checkSpace := allSpaceChar <> TBase85Alphabet.NullChar;
|
|
usingShortcuts := checkZero or checkSpace;
|
|
usingShortcuts := checkZero or checkSpace;
|
|
// allocate a larger buffer if we're using shortcuts
|
|
// allocate a larger buffer if we're using shortcuts
|
|
|
|
|
|
@@ -234,12 +234,12 @@ begin
|
|
// handle shortcut characters
|
|
// handle shortcut characters
|
|
if ((checkZero) and (c = allZeroChar)) then
|
|
if ((checkZero) and (c = allZeroChar)) then
|
|
begin
|
|
begin
|
|
- WriteShortcut(pDecodeBuffer, blockIndex, allZeroChar, 0);
|
|
|
|
|
|
+ WriteShortcut(pDecodeBuffer, blockIndex, 0);
|
|
continue;
|
|
continue;
|
|
end;
|
|
end;
|
|
if ((checkSpace) and (c = allSpaceChar)) then
|
|
if ((checkSpace) and (c = allSpaceChar)) then
|
|
begin
|
|
begin
|
|
- WriteShortcut(pDecodeBuffer, blockIndex, allSpaceChar, allSpace);
|
|
|
|
|
|
+ WriteShortcut(pDecodeBuffer, blockIndex, allSpace);
|
|
continue;
|
|
continue;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -298,7 +298,7 @@ var
|
|
bytesLen, maxOutputLen, fullLen, remainingBytes, n, outputLen: Int32;
|
|
bytesLen, maxOutputLen, fullLen, remainingBytes, n, outputLen: Int32;
|
|
input: Int64;
|
|
input: Int64;
|
|
t1, t2, t3, t4: UInt32;
|
|
t1, t2, t3, t4: UInt32;
|
|
- hasShortcut: Boolean;
|
|
|
|
|
|
+ usesZeroShortcut, usesSpaceShortcut: Boolean;
|
|
output: TSimpleBaseLibCharArray;
|
|
output: TSimpleBaseLibCharArray;
|
|
table: string;
|
|
table: string;
|
|
inputPtr, pInput, pInputEnd: PByte;
|
|
inputPtr, pInput, pInputEnd: PByte;
|
|
@@ -310,7 +310,8 @@ begin
|
|
begin
|
|
begin
|
|
Exit;
|
|
Exit;
|
|
end;
|
|
end;
|
|
- hasShortcut := Falphabet.hasShortcut;
|
|
|
|
|
|
+ usesZeroShortcut := Falphabet.AllZeroShortcut <> TBase85Alphabet.NullChar;
|
|
|
|
+ usesSpaceShortcut := Falphabet.AllSpaceShortcut <> TBase85Alphabet.NullChar;
|
|
|
|
|
|
// adjust output length based on prefix and suffix settings
|
|
// adjust output length based on prefix and suffix settings
|
|
// we know output length is too large but we will handle it later.
|
|
// we know output length is too large but we will handle it later.
|
|
@@ -339,10 +340,11 @@ begin
|
|
t4 := (UInt32(pInput^));
|
|
t4 := (UInt32(pInput^));
|
|
System.Inc(pInput);
|
|
System.Inc(pInput);
|
|
input := t1 or t2 or t3 or t4;
|
|
input := t1 or t2 or t3 or t4;
|
|
- WriteOutput(pOutput, table, input, stringBlockSize, hasShortcut);
|
|
|
|
|
|
+ WriteOutput(pOutput, table, input, stringBlockSize, usesZeroShortcut,
|
|
|
|
+ usesSpaceShortcut);
|
|
end;
|
|
end;
|
|
|
|
|
|
- // remaining part?
|
|
|
|
|
|
+ // check if a part is remaining
|
|
remainingBytes := bytesLen - fullLen;
|
|
remainingBytes := bytesLen - fullLen;
|
|
if (remainingBytes > 0) then
|
|
if (remainingBytes > 0) then
|
|
begin
|
|
begin
|
|
@@ -355,7 +357,8 @@ begin
|
|
System.Inc(n);
|
|
System.Inc(n);
|
|
end;
|
|
end;
|
|
|
|
|
|
- WriteOutput(pOutput, table, input, remainingBytes + 1, hasShortcut);
|
|
|
|
|
|
+ WriteOutput(pOutput, table, input, remainingBytes + 1, usesZeroShortcut,
|
|
|
|
+ usesSpaceShortcut);
|
|
end;
|
|
end;
|
|
|
|
|
|
outputLen := Int32(pOutput - outputPtr);
|
|
outputLen := Int32(pOutput - outputPtr);
|