diff --git a/SimpleBaseLib/src/Alphabets/SbpAliasedBase32Alphabet.pas b/SimpleBaseLib/src/Alphabets/SbpAliasedBase32Alphabet.pas index 9079e7a..88be508 100644 --- a/SimpleBaseLib/src/Alphabets/SbpAliasedBase32Alphabet.pas +++ b/SimpleBaseLib/src/Alphabets/SbpAliasedBase32Alphabet.pas @@ -13,6 +13,9 @@ interface SbpIAliasedBase32Alphabet, SbpBase32Alphabet; +resourcestring + SErrCharacterNotInAlphabet = 'Character "%s" is not in the alphabet'; + type TAliasedBase32Alphabet = class(TBase32Alphabet, IAliasedBase32Alphabet) strict private @@ -55,8 +58,8 @@ procedure TAliasedBase32Alphabet.MapAlternate(ASource, ADestination: Char); LResult: Int32; begin if not TCodingAlphabet.TryLookup(ReverseLookupTable, ADestination, LResult) then - raise EArgumentSimpleBaseLibException.CreateFmt( - 'Character "%s" is not in the alphabet', [ADestination]); + raise EArgumentSimpleBaseLibException.CreateResFmt( + @SErrCharacterNotInAlphabet, [ADestination]); Map(ASource, LResult); Map(TCharUtilities.ToAsciiLower(ASource), LResult); end; diff --git a/SimpleBaseLib/src/Alphabets/SbpCodingAlphabet.pas b/SimpleBaseLib/src/Alphabets/SbpCodingAlphabet.pas index 6ab2c34..4a04390 100644 --- a/SimpleBaseLib/src/Alphabets/SbpCodingAlphabet.pas +++ b/SimpleBaseLib/src/Alphabets/SbpCodingAlphabet.pas @@ -10,6 +10,10 @@ interface SbpICodingAlphabet, SbpCharUtilities; +resourcestring + SErrAlphabetLengthMismatch = 'Required alphabet length is %d but provided alphabet is %d characters long'; + SErrCaseSensitivityConflict = 'Case-sensitivity cannot be selected with an alphabet that contains both cases of the same letter'; + type /// /// Base class for ASCII-only coding alphabets with reverse lookup support @@ -59,8 +63,8 @@ constructor TCodingAlphabet.Create(ALength: Int32; const AAlphabet: String; if System.Length(AAlphabet) <> ALength then begin - raise EArgumentSimpleBaseLibException.CreateFmt - ('Required alphabet length is %d but provided alphabet is %d characters long', + raise EArgumentSimpleBaseLibException.CreateResFmt + (@SErrAlphabetLengthMismatch, [ALength, System.Length(AAlphabet)]); end; @@ -86,8 +90,8 @@ constructor TCodingAlphabet.Create(ALength: Int32; const AAlphabet: String; if System.Pos(LCounterpart, FValue) <> 0 then begin - raise EArgumentSimpleBaseLibException.Create - ('Case-sensitivity cannot be selected with an alphabet that contains both cases of the same letter'); + raise EArgumentSimpleBaseLibException.CreateRes + (@SErrCaseSensitivityConflict); end; Map(LCounterpart, LI); diff --git a/SimpleBaseLib/src/Bases/SbpBase16.pas b/SimpleBaseLib/src/Bases/SbpBase16.pas index c576b8c..cd54f79 100644 --- a/SimpleBaseLib/src/Bases/SbpBase16.pas +++ b/SimpleBaseLib/src/Bases/SbpBase16.pas @@ -16,6 +16,10 @@ interface SbpCodingAlphabet, SbpBase16Alphabet; +resourcestring + SErrInvalidTextLength = 'Invalid text length'; + SErrInvalidCharacterInInput = 'Invalid character in input'; + type TBase16 = class(TInterfacedObject, IBase16, IBaseStreamCoder, INonAllocatingBaseCoder) strict private @@ -156,13 +160,13 @@ function TBase16.Decode(const AText: String): TSimpleBaseLibByteArray; LSafeCount := GetSafeByteCountForDecoding(AText); if LSafeCount = 0 then begin - raise EArgumentSimpleBaseLibException.Create('Invalid text length'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidTextLength); end; System.SetLength(Result, LSafeCount); if not InternalDecode(AText, Result, LBytesWritten) then begin - raise EArgumentSimpleBaseLibException.Create('Invalid character in input'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidCharacterInInput); end; end; diff --git a/SimpleBaseLib/src/Bases/SbpBase2.pas b/SimpleBaseLib/src/Bases/SbpBase2.pas index f77f49e..7727b9c 100644 --- a/SimpleBaseLib/src/Bases/SbpBase2.pas +++ b/SimpleBaseLib/src/Bases/SbpBase2.pas @@ -13,6 +13,10 @@ interface SbpIBaseStreamCoder, SbpStreamUtilities; +resourcestring + SErrInputLengthNotMultipleOf8 = 'Input length must be a multiple of 8'; + SErrInvalidBase2Character = 'Invalid Base2 character encountered'; + type TBase2 = class(TInterfacedObject, IBase2, INonAllocatingBaseCoder, IBaseStreamCoder) strict private @@ -90,7 +94,7 @@ function TBase2.Decode(const AText: String): TSimpleBaseLibByteArray; if (System.Length(AText) mod 8) <> 0 then begin - raise EArgumentSimpleBaseLibException.Create('Input length must be a multiple of 8'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInputLengthNotMultipleOf8); end; LOutputLen := System.Length(AText) div 8; @@ -98,7 +102,7 @@ function TBase2.Decode(const AText: String): TSimpleBaseLibByteArray; if not InternalDecode(AText, Result, LOutputLen) then begin - raise EArgumentSimpleBaseLibException.Create('Invalid Base2 character encountered'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidBase2Character); end; end; diff --git a/SimpleBaseLib/src/Bases/SbpBase32.pas b/SimpleBaseLib/src/Bases/SbpBase32.pas index c37ed8d..a60b28c 100644 --- a/SimpleBaseLib/src/Bases/SbpBase32.pas +++ b/SimpleBaseLib/src/Bases/SbpBase32.pas @@ -20,6 +20,15 @@ interface SbpBitOperations, SbpBinaryPrimitives; +resourcestring + SErrOnlyEndPaddingSupported = 'Only encoding alphabets with paddings at the end are supported by this implementation'; + SErrInsufficientOutputBuffer = 'Internal error: insufficient output buffer size'; + SErrInvalidCharacterInInput = 'Invalid character in input'; + SErrUnexpectedDecodeResult = 'Unexpected decode result'; + SErrNumberIsNegative = 'Number is negative'; + SErrDecodedTextTooLong = 'Decoded text is too long to fit in a buffer'; + SErrDecodedOutOfInt64Range = 'Decoded buffer is out of Int64 range'; + type TBase32 = class(TInterfacedObject, IBase32, IBaseStreamCoder, INonAllocatingBaseCoder, INumericBaseCoder) strict private @@ -140,8 +149,7 @@ constructor TBase32.Create(const AAlphabet: IBase32Alphabet); inherited Create; if AAlphabet.PaddingPosition <> TPaddingPosition.&End then begin - raise EArgumentSimpleBaseLibException.Create( - 'Only encoding alphabets with paddings at the end are supported by this implementation'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrOnlyEndPaddingSupported); end; FAlphabet := AAlphabet; @@ -268,8 +276,7 @@ function TBase32.Encode(const ABytes: TSimpleBaseLibByteArray; System.SetLength(LOutput, LOutputLen); if not InternalEncode(ABytes, LOutput, APadding, LCharsWritten) then begin - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); end; SetString(Result, PChar(@LOutput[0]), LCharsWritten); end; @@ -293,15 +300,13 @@ function TBase32.Decode(const AText: String): TSimpleBaseLibByteArray; LDecodeResult := InternalDecode(AText, LTextLen, LOutput, LBytesWritten); case LDecodeResult of TDecodeResult.InvalidInput: - raise EArgumentSimpleBaseLibException.Create('Invalid character in input'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidCharacterInInput); TDecodeResult.OutputOverflow: - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); TDecodeResult.Success: Result := System.Copy(LOutput, 0, LBytesWritten); else - raise EInvalidOperationSimpleBaseLibException.Create( - 'Unexpected decode result'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrUnexpectedDecodeResult); end; end; @@ -309,7 +314,7 @@ function TBase32.EncodeInt64(const ANumber: Int64): String; begin if ANumber < 0 then begin - raise EArgumentOutOfRangeSimpleBaseLibException.Create('Number is negative'); + raise EArgumentOutOfRangeSimpleBaseLibException.CreateRes(@SErrNumberIsNegative); end; Result := EncodeUInt64(UInt64(ANumber)); end; @@ -350,8 +355,7 @@ function TBase32.DecodeUInt64(const AText: String): UInt64; end; if System.Length(LBuffer) > 8 then begin - raise EInvalidOperationSimpleBaseLibException.Create( - 'Decoded text is too long to fit in a buffer'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrDecodedTextTooLong); end; System.SetLength(LNewSpan, 8); @@ -386,8 +390,7 @@ function TBase32.DecodeInt64(const AText: String): Int64; LResult := DecodeUInt64(AText); if LResult > UInt64(High(Int64)) then begin - raise EArgumentOutOfRangeSimpleBaseLibException.Create( - 'Decoded buffer is out of Int64 range'); + raise EArgumentOutOfRangeSimpleBaseLibException.CreateRes(@SErrDecodedOutOfInt64Range); end; Result := Int64(LResult); end; diff --git a/SimpleBaseLib/src/Bases/SbpBase45.pas b/SimpleBaseLib/src/Bases/SbpBase45.pas index 8625ab9..d8ff5f2 100644 --- a/SimpleBaseLib/src/Bases/SbpBase45.pas +++ b/SimpleBaseLib/src/Bases/SbpBase45.pas @@ -18,6 +18,13 @@ interface SbpBitOperations, SbpStreamUtilities; +resourcestring + SErrInsufficientOutputBuffer = 'Internal error: insufficient output buffer size'; + SErrInvalidCharacter = 'Invalid character: %s'; + SErrInputCorrupt = 'Input buffer is incorrectly encoded or corrupt'; + SErrInputIncorrectSize = 'Input buffer is at incorrect size'; + SErrUnexpectedDecodeResult = 'Unexpected decode result'; + type TBase45 = class(TInterfacedObject, IBase45, INonAllocatingBaseCoder, IBaseStreamCoder) strict private @@ -334,19 +341,16 @@ function TBase45.Decode(const AText: String): TSimpleBaseLibByteArray; TDecodeResult.Success: Result := System.Copy(LOutput, 0, LBytesWritten); TDecodeResult.InvalidOutputLength: - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); TDecodeResult.InvalidCharacter: - raise EArgumentSimpleBaseLibException.CreateFmt('Invalid character: %s', + raise EArgumentSimpleBaseLibException.CreateResFmt(@SErrInvalidCharacter, [LOutcome.InvalidChar]); TDecodeResult.InvalidInput: - raise EArgumentSimpleBaseLibException.Create( - 'Input buffer is incorrectly encoded or corrupt'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInputCorrupt); TDecodeResult.InvalidInputLength: - raise EArgumentSimpleBaseLibException.Create( - 'Input buffer is at incorrect size'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInputIncorrectSize); else - raise EInvalidOperationSimpleBaseLibException.Create('Unexpected decode result'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrUnexpectedDecodeResult); end; end; @@ -365,8 +369,7 @@ function TBase45.Encode(const ABytes: TSimpleBaseLibByteArray): String; System.SetLength(LOutput, LOutputLen); if not InternalEncode(ABytes, LOutput, LCharsWritten) then begin - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); end; SetString(Result, PChar(@LOutput[0]), LCharsWritten); end; diff --git a/SimpleBaseLib/src/Bases/SbpBase64.pas b/SimpleBaseLib/src/Bases/SbpBase64.pas index 0161302..451c201 100644 --- a/SimpleBaseLib/src/Bases/SbpBase64.pas +++ b/SimpleBaseLib/src/Bases/SbpBase64.pas @@ -18,6 +18,13 @@ interface SbpBitOperations, SbpStreamUtilities; +resourcestring + SErrInsufficientOutputBuffer = 'Internal error: insufficient output buffer size'; + SErrInvalidBase64Character = 'Invalid Base64 character "%s"'; + SErrInvalidBase64Length = 'Invalid Base64 string length'; + SErrInvalidBase64Padding = 'Invalid Base64 padding placement'; + SErrUnexpectedDecodeResult = 'Unexpected decode result'; + type TBase64 = class(TInterfacedObject, IBase64, INonAllocatingBaseCoder, IBaseStreamCoder) @@ -474,8 +481,7 @@ class function TBase64.AllocatingEncode(const ABytes: TSimpleBaseLibByteArray; System.SetLength(LOutput, LOutputLen); if not InternalEncode(ABytes, LOutput, AAlphabetValue, APadding, LCharsWritten) then begin - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); end; SetString(Result, PChar(@LOutput[0]), LCharsWritten); end; @@ -502,18 +508,16 @@ class function TBase64.AllocatingDecode(const AText: String; TDecodeResult.Success: Result := System.Copy(LDecodeBuffer, 0, LBytesWritten); TDecodeResult.InvalidCharacter: - raise EArgumentSimpleBaseLibException.CreateFmt( - 'Invalid Base64 character "%s"', [LOutcome.InvalidChar]); + raise EArgumentSimpleBaseLibException.CreateResFmt( + @SErrInvalidBase64Character, [LOutcome.InvalidChar]); TDecodeResult.InvalidLength: - raise EArgumentSimpleBaseLibException.Create('Invalid Base64 string length'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidBase64Length); TDecodeResult.InvalidPadding: - raise EArgumentSimpleBaseLibException.Create('Invalid Base64 padding placement'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidBase64Padding); TDecodeResult.InsufficientOutputBuffer: - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); else - raise EInvalidOperationSimpleBaseLibException.Create( - 'Unexpected decode result'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrUnexpectedDecodeResult); end; end; diff --git a/SimpleBaseLib/src/Bases/SbpBase8.pas b/SimpleBaseLib/src/Bases/SbpBase8.pas index 9992dff..4420d26 100644 --- a/SimpleBaseLib/src/Bases/SbpBase8.pas +++ b/SimpleBaseLib/src/Bases/SbpBase8.pas @@ -13,6 +13,11 @@ interface SbpIBaseStreamCoder, SbpStreamUtilities; +resourcestring + SErrInvalidBase8Character = 'Invalid Base8 character encountered'; + SErrInvalidEncodedTextLength = 'Invalid encoded text length'; + SErrUnknownDecodingError = 'Unknown error during decoding - this is a bug'; + type TBase8 = class(TInterfacedObject, IBase8, INonAllocatingBaseCoder, IBaseStreamCoder) strict private @@ -112,12 +117,11 @@ function TBase8.Decode(const AText: String): TSimpleBaseLibByteArray; Result := System.Copy(Result, 0, LBytesWritten); end; TDecodeResult.InvalidCharacter: - raise EArgumentSimpleBaseLibException.Create('Invalid Base8 character encountered'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidBase8Character); TDecodeResult.InvalidInputLength: - raise EArgumentSimpleBaseLibException.Create('Invalid encoded text length'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrInvalidEncodedTextLength); else - raise EInvalidOperationSimpleBaseLibException.Create( - 'Unknown error during decoding -- this is a bug'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrUnknownDecodingError); end; end; diff --git a/SimpleBaseLib/src/Bases/SbpBase85.pas b/SimpleBaseLib/src/Bases/SbpBase85.pas index 76a6fb2..fd59ff5 100644 --- a/SimpleBaseLib/src/Bases/SbpBase85.pas +++ b/SimpleBaseLib/src/Bases/SbpBase85.pas @@ -18,6 +18,12 @@ interface SbpBitOperations, SbpStreamUtilities; +resourcestring + SErrInsufficientOutputBuffer = 'Internal error: insufficient output buffer size'; + SErrInvalidCharacter = 'Invalid character: %s'; + SErrInvalidShortcutLocation = 'Invalid location for a shortcut character: %s'; + SErrUnexpectedDecodeResult = 'Unexpected decode result'; + type TBase85 = class(TInterfacedObject, IBase85, IBaseStreamCoder, INonAllocatingBaseCoder) strict private @@ -218,8 +224,7 @@ function TBase85.Encode(const ABytes: TSimpleBaseLibByteArray): String; System.SetLength(LOutput, LOutputLen); if not InternalEncode(ABytes, LOutput, LCharsWritten) then begin - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); end; SetString(Result, PChar(@LOutput[0]), LCharsWritten); end; @@ -261,16 +266,14 @@ function TBase85.Decode(const AText: String): TSimpleBaseLibByteArray; TDecodeResult.Success: Result := System.Copy(LDecodeBuffer, 0, LBytesWritten); TDecodeResult.InvalidCharacter: - raise EArgumentSimpleBaseLibException.CreateFmt('Invalid character: %s', [LOutcome.InvalidChar]); + raise EArgumentSimpleBaseLibException.CreateResFmt(@SErrInvalidCharacter, [LOutcome.InvalidChar]); TDecodeResult.InvalidShortcut: - raise EArgumentSimpleBaseLibException.CreateFmt( - 'Invalid location for a shortcut character: %s', [LOutcome.InvalidChar]); + raise EArgumentSimpleBaseLibException.CreateResFmt( + @SErrInvalidShortcutLocation, [LOutcome.InvalidChar]); TDecodeResult.InsufficientOutputBuffer: - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); else - raise EInvalidOperationSimpleBaseLibException.Create( - 'Unexpected decode result'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrUnexpectedDecodeResult); end; end; diff --git a/SimpleBaseLib/src/Bases/SbpMoneroBase58.pas b/SimpleBaseLib/src/Bases/SbpMoneroBase58.pas index eb50b2f..ab1bd88 100644 --- a/SimpleBaseLib/src/Bases/SbpMoneroBase58.pas +++ b/SimpleBaseLib/src/Bases/SbpMoneroBase58.pas @@ -16,6 +16,11 @@ interface SbpBinaryPrimitives, SbpBits; +resourcestring + SErrInsufficientOutputBuffer = 'Internal error: insufficient output buffer size'; + SErrInvalidCharacter = 'Invalid character: %s'; + SErrUnexpectedDecodeResult = 'Unexpected decode result'; + type TMoneroBase58 = class(TInterfacedObject, IMoneroBase58, INonAllocatingBaseCoder) strict private @@ -357,8 +362,7 @@ function TMoneroBase58.Encode(const ABytes: TSimpleBaseLibByteArray): String; System.SetLength(LOutput, LOutputLen); if not InternalEncode(ABytes, LOutput, LCharsWritten) then begin - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); end; SetString(Result, PChar(@LOutput[0]), LCharsWritten); end; @@ -383,14 +387,12 @@ function TMoneroBase58.Decode(const AText: String): TSimpleBaseLibByteArray; TDecodeResult.Success: Result := System.Copy(LOutput, 0, LBytesWritten); TDecodeResult.InvalidCharacter: - raise EArgumentSimpleBaseLibException.CreateFmt('Invalid character: %s', + raise EArgumentSimpleBaseLibException.CreateResFmt(@SErrInvalidCharacter, [LOutcome.InvalidChar]); TDecodeResult.InsufficientOutputBuffer: - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); else - raise EInvalidOperationSimpleBaseLibException.Create( - 'Unexpected decode result'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrUnexpectedDecodeResult); end; end; diff --git a/SimpleBaseLib/src/Bases/SbpMultibase.pas b/SimpleBaseLib/src/Bases/SbpMultibase.pas index 6520365..15b0c38 100644 --- a/SimpleBaseLib/src/Bases/SbpMultibase.pas +++ b/SimpleBaseLib/src/Bases/SbpMultibase.pas @@ -18,6 +18,11 @@ interface SbpBase58, SbpBase64; +resourcestring + SErrTextCannotBeEmpty = 'Text cannot be empty'; + SErrUnsupportedMultibasePrefix = 'Unsupported multibase prefix: %s'; + SErrUnsupportedEncodingType = 'Unsupported encoding type: %d'; + type TMultibase = class sealed(TObject) public @@ -38,7 +43,7 @@ class function TMultibase.Decode(const AText: String): TSimpleBaseLibByteArray; begin if System.Length(AText) = 0 then begin - raise EArgumentSimpleBaseLibException.Create('Text cannot be empty'); + raise EArgumentSimpleBaseLibException.CreateRes(@SErrTextCannotBeEmpty); end; LC := AText[1]; @@ -85,8 +90,8 @@ class function TMultibase.Decode(const AText: String): TSimpleBaseLibByteArray; TMultibaseEncoding.Base64UrlPad: Result := TBase64.UrlPadded.Decode(LRest); else - raise EInvalidOperationSimpleBaseLibException.CreateFmt( - 'Unsupported multibase prefix: %s', [LC]); + raise EInvalidOperationSimpleBaseLibException.CreateResFmt( + @SErrUnsupportedMultibasePrefix, [LC]); end; end; @@ -196,7 +201,7 @@ class function TMultibase.Encode(const ABytes: TSimpleBaseLibByteArray; TMultibaseEncoding.Base64UrlPad: Result := Result + TBase64.UrlPadded.Encode(ABytes); else - raise EArgumentSimpleBaseLibException.CreateFmt('Unsupported encoding type: %d', + raise EArgumentSimpleBaseLibException.CreateResFmt(@SErrUnsupportedEncodingType, [Ord(AEncoding)]); end; end; diff --git a/SimpleBaseLib/src/Coders/SbpDividingCoder.pas b/SimpleBaseLib/src/Coders/SbpDividingCoder.pas index edaef97..a36821e 100644 --- a/SimpleBaseLib/src/Coders/SbpDividingCoder.pas +++ b/SimpleBaseLib/src/Coders/SbpDividingCoder.pas @@ -18,6 +18,11 @@ interface SbpBitOperations, SbpBits; +resourcestring + SErrInsufficientOutputBuffer = 'Internal error: insufficient output buffer size'; + SErrInvalidCharacter = 'Invalid character: %s'; + SErrUnexpectedDecodeResult = 'Unexpected decode result'; + type /// /// Dividing Encoding/Decoding implementation to be used by other dividing encoders. @@ -303,8 +308,7 @@ function TDividingCoder.Encode( end else begin - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); end; end; @@ -331,19 +335,17 @@ function TDividingCoder.Decode( case LOutcome.Status of TDecodeResult.InvalidCharacter: - raise EArgumentSimpleBaseLibException.CreateFmt('Invalid character: %s', + raise EArgumentSimpleBaseLibException.CreateResFmt(@SErrInvalidCharacter, [LOutcome.InvalidChar]); TDecodeResult.InsufficientOutputBuffer: - raise EInvalidOperationSimpleBaseLibException.Create( - 'Internal error: insufficient output buffer size'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrInsufficientOutputBuffer); TDecodeResult.Success: begin LRangeLen := LRangeWritten.Finish - LRangeWritten.Start; Result := System.Copy(LOutput, LRangeWritten.Start, LRangeLen); end; else - raise EInvalidOperationSimpleBaseLibException.Create( - 'Unexpected decode result'); + raise EInvalidOperationSimpleBaseLibException.CreateRes(@SErrUnexpectedDecodeResult); end; end; diff --git a/SimpleBaseLib/src/Misc/SbpBits.pas b/SimpleBaseLib/src/Misc/SbpBits.pas index ed51786..ea56ff5 100644 --- a/SimpleBaseLib/src/Misc/SbpBits.pas +++ b/SimpleBaseLib/src/Misc/SbpBits.pas @@ -7,6 +7,9 @@ interface uses SbpSimpleBaseLibTypes; +resourcestring + SErrCountTooLarge = 'ACount too large to convert to UInt64'; + type /// @@ -43,7 +46,7 @@ class function TBits.PartialBigEndianBytesToUInt64(const ABytes: TSimpleBaseLibB begin if ACount > System.SizeOf(UInt64) then begin - raise EArgumentOutOfRangeSimpleBaseLibException.Create('ACount too large to convert to UInt64'); + raise EArgumentOutOfRangeSimpleBaseLibException.CreateRes(@SErrCountTooLarge); end; Result := 0; diff --git a/SimpleBaseLib/src/Utilities/SbpStreamUtilities.pas b/SimpleBaseLib/src/Utilities/SbpStreamUtilities.pas index bb8ee36..f8e574a 100644 --- a/SimpleBaseLib/src/Utilities/SbpStreamUtilities.pas +++ b/SimpleBaseLib/src/Utilities/SbpStreamUtilities.pas @@ -9,6 +9,10 @@ interface SysUtils, SbpSimpleBaseLibTypes; +resourcestring + SErrBlockSizeMustBePositive = 'Block size must be positive'; + SErrDefaultBufferSizeMustBePositive = 'Default buffer size must be positive'; + type /// @@ -40,13 +44,11 @@ class function TStreamUtilities.GetAlignedBufferSize(ABlockSize: Int32; begin if ABlockSize < 1 then begin - raise EArgumentOutOfRangeSimpleBaseLibException.Create( - 'Block size must be positive'); + raise EArgumentOutOfRangeSimpleBaseLibException.CreateRes(@SErrBlockSizeMustBePositive); end; if ADefaultBufferSize < 1 then begin - raise EArgumentOutOfRangeSimpleBaseLibException.Create( - 'Default buffer size must be positive'); + raise EArgumentOutOfRangeSimpleBaseLibException.CreateRes(@SErrDefaultBufferSizeMustBePositive); end; Result := ADefaultBufferSize - (ADefaultBufferSize mod ABlockSize);