From 5503a0c3394511a641ef0a1ff1a5daa6b651dbe3 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 18 Jun 2024 16:31:03 +0200 Subject: [PATCH] string: add 8 and 16-bit string to binary conversions Signed-off-by: Simon Rozman --- include/stdex/string.hpp | 148 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index 44467469f..9f95c1032 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -2126,6 +2126,80 @@ namespace stdex return strtouint(str, N, end, radix); } + /// + /// Parse string for a signed 8-bit integer + /// + /// \param[in] str String + /// \param[in] count String code unit count limit + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + int8_t strto8( + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, + _Out_opt_ size_t* end, + _In_ int radix) + { + return strtoint(str, count, end, radix); + } + + /// + /// Parse string for a signed 8-bit integer + /// + /// \param[in] str String + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + int8_t strto8( + _In_ const T (&str)[N], + _Out_opt_ size_t* end, + _In_ int radix) + { + return strto8(str, N, end, radix); + } + + /// + /// Parse string for a signed 16-bit integer + /// + /// \param[in] str String + /// \param[in] count String code unit count limit + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + int16_t strto16( + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, + _Out_opt_ size_t* end, + _In_ int radix) + { + return strtoint(str, count, end, radix); + } + + /// + /// Parse string for a signed 16-bit integer + /// + /// \param[in] str String + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + int16_t strto16( + _In_ const T (&str)[N], + _Out_opt_ size_t* end, + _In_ int radix) + { + return strto16(str, N, end, radix); + } + /// /// Parse string for a signed 32-bit integer /// @@ -2243,6 +2317,80 @@ namespace stdex return strtoi(str, N, end, radix); } + /// + /// Parse string for an unsigned 8-bit integer + /// + /// \param[in] str String + /// \param[in] count String code unit count limit + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + uint8_t strtou8( + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, + _Out_opt_ size_t* end, + _In_ int radix) + { + return strtouint(str, count, end, radix); + } + + /// + /// Parse string for an unsigned 8-bit integer + /// + /// \param[in] str String + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + uint8_t strtou8( + _In_ const T (&str)[N], + _Out_opt_ size_t* end, + _In_ int radix) + { + return strtou8(str, N, end, radix); + } + + /// + /// Parse string for an unsigned 16-bit integer + /// + /// \param[in] str String + /// \param[in] count String code unit count limit + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + uint16_t strtou16( + _In_reads_or_z_opt_(count) const T* str, _In_ size_t count, + _Out_opt_ size_t* end, + _In_ int radix) + { + return strtouint(str, count, end, radix); + } + + /// + /// Parse string for an unsigned 16-bit integer + /// + /// \param[in] str String + /// \param[out] end On return, count of code units processed + /// \param[in] radix Number radix (0 - autodetect; 2..36) + /// + /// \return Binary integer value + /// + template + uint16_t strtou16( + _In_ const T (&str)[N], + _Out_opt_ size_t* end, + _In_ int radix) + { + return strtou16(str, N, end, radix); + } + /// /// Parse string for an unsigned 32-bit integer ///