Parsing and Try APIs

Prefer a Try... API when malformed input is expected. It makes failure a normal branch instead of silently turning an error into an empty value.

Pascal
if TStringKit.TryHexDecode(Input, Value) then
begin
  Writeln(Value);
end;

Strict functions#

FunctionAcceptsFailure result
TryHexDecodean even number of hexadecimal charactersFalse; decoded string is cleared
TryDecode64standard padded Base64; whitespace is ignoredFalse; decoded string is cleared
TryFromRomancanonical Roman numerals from 1 to 3999False; integer value is set to 0

The successful paths are demonstrated by the compiled hex, Base64, and Roman numeral recipes.

The older HexDecode, Decode64, and FromRoman methods remain for compatibility. Their failure behaviour is deliberately different: HexDecode is permissive, Decode64 returns an empty string on invalid input, and FromRoman remains permissive. Do not use their result alone to distinguish an invalid value from a valid empty one.