inline
C const*
integer_to_string(C* buf, ss_size_t cchBuf, ss_uint32_t i, ss_size_t* pcchRes)
{
    STLSOFT_ASSERT(NULL != pcchRes);

    return unsigned_integer_to_string(buf, cchBuf, i, pcchRes);
}
inline
C const*
integer_to_string(C (&buf)[N], ss_uint32_t i)
{
    STLSOFT_STATIC_ASSERT(!(N < 11));

    return unsigned_integer_to_string(buf, N, i);
}
示例#3
0
inline C const* integer_to_string(C *buf, ss_size_t cchBuf, unsigned long i, ss_size_t &cchRes)
{
    return unsigned_integer_to_string(buf, cchBuf, i, cchRes);
}
示例#4
0
inline C const* integer_to_string(C *buf, ss_size_t cchBuf, ss_uint_t i)
{
    return unsigned_integer_to_string(buf, cchBuf, i);
}
示例#5
0
inline C const* signed_integer_to_string(C *buf, ss_size_t cchBuf, I i)
{
#ifndef STLSOFT_CF_NEGATIVE_MODULUS_POSITIVE_GIVES_NEGATIVE_RESULT
// If the compiler does not evaluate -9 % 10 to equal -9, then we need to work
// with it as if an unsigned, and prepend the -ve
    typedef limit_traits<I>                                 limit_traits_t;
    typedef sign_traits<I>                                  sign_traits_t;
    typedef ss_typename_type_k sign_traits_t::signed_type   signed_type_t;
    typedef ss_typename_type_k sign_traits_t::unsigned_type unsigned_type_t;

    // If this fires, something has happened to invoke this function on an
    // unsigned type.
    STLSOFT_STATIC_ASSERT((0 != is_same_type<signed_type_t, I>::value));

    C const* psz;

    if(i == limit_traits_t::minimum())
    {
        STLSOFT_ASSERT(i == -i);

        // Special case of the (signed) minimum, since the maximum -ve value
        // of a signed integer cannot be negated.
        //
        // We instead take the equivalent value as an unsigned integer,
        // convert that (as unsigned), and prepend a '-'

        psz = unsigned_integer_to_string(buf, cchBuf, static_cast<unsigned_type_t>(limit_traits_t::minimum()));

        *const_cast<C*>(--psz) = C('-');
    }
    else
    {
        // Just using the unsigned version here for the absence of
        // sign. Perversely, The invoked function is still a signed
        // specialisation.
        psz = unsigned_integer_to_string(buf, cchBuf, i);

        if(i < 0)
        {
            *const_cast<C*>(--psz) = C('-');
        }
    }

    return psz;
#else /* ? STLSOFT_CF_NEGATIVE_MODULUS_POSITIVE_GIVES_NEGATIVE_RESULT */
// Compiler evaluates -9 % 10 to equal -9, so use the full -ve algorithm. This
// is chosen because it is more efficient on most compilers than calling the
// unsigned peer and converting.

#if defined(STLSOFT_COMPILER_IS_MSVC)
    typedef I           rem_t;
#else /* ? compiler */
    typedef ss_sint_t   rem_t;
#endif /* compiler */

    C   *psz    =   buf + cchBuf - 1;  // Set pointer to last character.

    *psz = 0;   // Set the terminating null character.

    if(i < 0)
    {
        do
        {
            rem_t   lsd = static_cast<rem_t>(i % 10);   // Determine the least significant digit.

            i = static_cast<I>(i / 10);                 // Deal with next most significant.

            --psz;                                      // Move back.

#ifdef STLSOFT_CF_TEMPLATE_TYPE_REQUIRED_IN_ARGS
            *psz = get_digit_character(static_cast<C*>(NULL))[lsd];
#else /* ? STLSOFT_CF_TEMPLATE_TYPE_REQUIRED_IN_ARGS */
            *psz = get_digit_character<C>()[lsd];
#endif /* STLSOFT_CF_TEMPLATE_TYPE_REQUIRED_IN_ARGS */

        } while(i != 0);

        *(--psz) = C('-');              // Prepend the minus sign.
    }
    else
    {
        do
        {
            rem_t   lsd = static_cast<rem_t>(i % 10);   // Determine the least significant digit.

            i = static_cast<I>(i / 10);                 // Deal with next most significant.

            --psz;                                      // Move back.

#ifdef STLSOFT_CF_TEMPLATE_TYPE_REQUIRED_IN_ARGS
            *psz = get_digit_character(static_cast<C*>(NULL))[lsd];
#else /* ? STLSOFT_CF_TEMPLATE_TYPE_REQUIRED_IN_ARGS */
            *psz = get_digit_character<C>()[lsd];
#endif /* STLSOFT_CF_TEMPLATE_TYPE_REQUIRED_IN_ARGS */

        } while(i != 0);
    }

    STLSOFT_ASSERT(!(psz < buf));

    return psz;
#endif /* !STLSOFT_CF_NEGATIVE_MODULUS_POSITIVE_GIVES_NEGATIVE_RESULT */
}
inline
C const*
integer_to_string(C* buf, ss_size_t cchBuf, ss_uint64_t const& i, ss_size_t& cchRes)
{
    return unsigned_integer_to_string(buf, cchBuf, i, &cchRes);
}