Repository: microsoft/terminal
File: src/inc/til/string.h (C/C++)

Code before:

        // We don't have to test ptr for nullability, as we only access it under either condition:
        // * str.length() > 0, for determining the base
        // * ptr != end, when parsing the characters; if ptr is null, length will be 0 and thus end == ptr
#pragma warning(push)
#pragma warning(disable : 26429) // Symbol 'ptr' is never tested for nullness, it can be marked as not_null
#pragma warning(disable : 26481) // Don't use pointer arithmetic. Use span instead
        auto ptr = str.data();
        const auto end = ptr + str.length();
        unsigned long base = 10;
        unsigned long accumulator = 0;
        unsigned long value = ULONG_MAX;

        if (str.length() > 1 && *ptr == L'0')
        {
            base = 8;
            ptr++;

            if (str.length() > 2 && (*ptr == L'x' || *ptr == L'X'))
            {
                base = 16;
                ptr++;
            }
        }

        if (ptr == end)
        {
            return from_wchars_error;
        }

        for (;; accumulator *= base)
        {
            value = ULONG_MAX;
            if (*ptr >= L'0' && *ptr <= L'9')
            {
                value = *ptr - L'0';
            }
            else if (*ptr >= L'A' && *ptr <= L'F')
            {
                value = *ptr - L'A' + 10;
            }
            else if (*ptr >= L'a' && *ptr <= L'f')
            {
                value = *ptr - L'a' + 10;
            }
            else
            {
                return from_wchars_error;
            }

            accumulator += value;

Review comment (suggestion):
My IDE was complaining that the iterator result is discarded (`ptr++` returns a copy of the previous iterable state). I just changed it - can't hurt after all.

Code after:
        static constexpr unsigned long maximumValue = ULONG_MAX / 16;

        // We don't have to test ptr for nullability, as we only access it under either condition:
        // * str.length() > 0, for determining the base
        // * ptr != end, when parsing the characters; if ptr is null, length will be 0 and thus end == ptr
#pragma warning(push)
#pragma warning(disable : 26429) // Symbol 'ptr' is never tested for nullness, it can be marked as not_null
#pragma warning(disable : 26481) // Don't use pointer arithmetic. Use span instead
        auto ptr = str.data();
        const auto end = ptr + str.length();
        unsigned long accumulator = 0;
        unsigned long value = ULONG_MAX;

        if (!base)
        {
            base = 10;

            if (str.length() > 1 && *ptr == '0')
            {
                base = 8;
                ++ptr;

                if (str.length() > 2 && (*ptr == 'x' || *ptr == 'X'))
                {
                    base = 16;
                    ++ptr;
                }
            }
        }

        if (ptr == end)
        {
            return to_ulong_error;
        }

        for (;; accumulator *= base)
        {
            value = ULONG_MAX;
            if (*ptr >= '0' && *ptr <= '9')
            {
                value = *ptr - '0';
            }
            else if (*ptr >= 'A' && *ptr <= 'F')
            {
                value = *ptr - 'A' + 10;
            }
            else if (*ptr >= 'a' && *ptr <= 'f')
            {
                value = *ptr - 'a' + 10;
            }
            else