.. _stdlib_strings_convert: =============================================================================== Soft-failing string-to-numeric conversions returning Result =============================================================================== .. das:module:: strings_convert The STRINGS_CONVERT module provides soft-failing string-to-numeric conversions that return ``Result`` instead of panicking or silently returning zero. Use these when parsing untrusted input where you need to distinguish between not-a-number, overflow, and trailing-garbage. All functions and symbols are in the "strings_convert" module, use require to get access to it. .. code-block:: das require daslib/strings_convert Example: .. code-block:: das require daslib/strings_convert [export] def main() { let r = try_to_int("42") if (is_ok(r)) { print("parsed: {unwrap(r)}\n") } let bad = try_to_int("nope") if (is_err(bad)) { print("error: {unwrap_err(bad)}\n") } } // output: // parsed: 42 // error: invalid_argument ++++++++++++ Enumerations ++++++++++++ .. _enum-strings_convert-ConversionError: .. das:attribute:: ConversionError enum ConversionError ++++++++++ Structures ++++++++++ .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result .. _struct-strings_convert-Result: .. das:attribute:: Result struct Result ++++++++++++++++++++++++ Soft-failing conversions ++++++++++++++++++++++++ * :ref:`try_to_double (str: string) : Result\ ` * :ref:`try_to_float (str: string) : Result\ ` * :ref:`try_to_int (str: string; hex: bool = false) : Result\ ` * :ref:`try_to_int16 (str: string; hex: bool = false) : Result\ ` * :ref:`try_to_int64 (str: string; hex: bool = false) : Result\ ` * :ref:`try_to_int8 (str: string; hex: bool = false) : Result\ ` * :ref:`try_to_uint (str: string; hex: bool = false) : Result\ ` * :ref:`try_to_uint16 (str: string; hex: bool = false) : Result\ ` * :ref:`try_to_uint64 (str: string; hex: bool = false) : Result\ ` * :ref:`try_to_uint8 (str: string; hex: bool = false) : Result\ ` .. _function-strings_convert_try_to_double_string: .. das:function:: try_to_double(str: string) : Result Parse ``str`` as a 64-bit float. :Arguments: * **str** : string implicit .. _function-strings_convert_try_to_float_string: .. das:function:: try_to_float(str: string) : Result Parse ``str`` as a 32-bit float. :Arguments: * **str** : string implicit .. _function-strings_convert_try_to_int_string_bool: .. das:function:: try_to_int(str: string; hex: bool = false) : Result Parse ``str`` as a signed 32-bit integer. :Arguments: * **str** : string implicit * **hex** : bool .. _function-strings_convert_try_to_int16_string_bool: .. das:function:: try_to_int16(str: string; hex: bool = false) : Result Parse ``str`` as a signed 16-bit integer. :Arguments: * **str** : string implicit * **hex** : bool .. _function-strings_convert_try_to_int64_string_bool: .. das:function:: try_to_int64(str: string; hex: bool = false) : Result Parse ``str`` as a signed 64-bit integer. :Arguments: * **str** : string implicit * **hex** : bool .. _function-strings_convert_try_to_int8_string_bool: .. das:function:: try_to_int8(str: string; hex: bool = false) : Result Parse ``str`` as a signed 8-bit integer. :Arguments: * **str** : string implicit * **hex** : bool .. _function-strings_convert_try_to_uint_string_bool: .. das:function:: try_to_uint(str: string; hex: bool = false) : Result Parse ``str`` as an unsigned 32-bit integer. :Arguments: * **str** : string implicit * **hex** : bool .. _function-strings_convert_try_to_uint16_string_bool: .. das:function:: try_to_uint16(str: string; hex: bool = false) : Result Parse ``str`` as an unsigned 16-bit integer. :Arguments: * **str** : string implicit * **hex** : bool .. _function-strings_convert_try_to_uint64_string_bool: .. das:function:: try_to_uint64(str: string; hex: bool = false) : Result Parse ``str`` as an unsigned 64-bit integer. :Arguments: * **str** : string implicit * **hex** : bool .. _function-strings_convert_try_to_uint8_string_bool: .. das:function:: try_to_uint8(str: string; hex: bool = false) : Result Parse ``str`` as an unsigned 8-bit integer. :Arguments: * **str** : string implicit * **hex** : bool