Ejemplo n.º 1
0
inline winini_bundle::string_type winini_bundle::operator [](char_type const *name) const throw(std::out_of_range)
{
    static const char_type sentinel[] = FASTFORMAT_LITERAL_STRING("{5DDAADE5-5134-4734-ACB8-A6D0FA3BD0EA}-{D875F19B-8279-4c44-9517-F16366BC13E3}");

    ::SetLastError(0);

    char_type   result[1001];
    DWORD       dw = ::GetPrivateProfileString(
                                            m_iniSection.c_str()
                                        ,   name
                                        ,   sentinel
                                        ,   &result[0]
                                        ,   STLSOFT_NUM_ELEMENTS(result)
                                        ,   m_iniFileName.c_str());

    if(dw == STLSOFT_NUM_ELEMENTS(sentinel) - 1)    /* element not found */
    {
        if(0 == string_type::traits_type::compare(sentinel, result, stlsoft::minimum(size_t(dw), STLSOFT_NUM_ELEMENTS(sentinel) - 1)))
        {
            throw std::out_of_range("section/key combination does not exist in the given INI file");
        }
    }

    ::GetLastError();

    return string_type(result, dw);
}
Ejemplo n.º 2
0
/** Filtering conversion shim function for implicitly adapting 
 *  <code>bool</code> format arguments.
 */
#if 0
    inline std::basic_string<ff_char_t> filter_type(bool value, bool const*, ff_char_t const volatile*)
    {
        return value ? FASTFORMAT_LITERAL_STRING("True") : FASTFORMAT_LITERAL_STRING("False");
    }
#else /* ? 0 */
    inline ff_string_slice_t filter_type(bool value, bool const*, ff_char_t const volatile*)
    {
        ff_string_slice_t   result;

        // The following implementation is valid only because the string
        // literals go into the program data section, and are available
        // throughout the lifetime of the process.
        if(value)
        {
            result.len  =   4;
            result.ptr  =   FASTFORMAT_LITERAL_STRING("True");
        }
        else
        {
            result.len  =   5;
            result.ptr  =   FASTFORMAT_LITERAL_STRING("False");
        }

        return result;
    }
Ejemplo n.º 3
0
/** Writes an array of string slices into a <code>std::stringstream</code> sink.
 *
 * \ingroup group__sinks
 *
 */
inline std::basic_stringstream<ff_char_t>&
fmt_slices(
    std::basic_stringstream<ff_char_t>& sink
,   int                                 flags
,   size_t                              /* cchTotal */
,   size_t                              numResults
,   ff_string_slice_t const*            results
)
{
    { for(size_t i = 0; i < numResults; ++i)
    {
        ff_string_slice_t const &slice = results[i];

        if(0 != slice.len)
        {
            sink.write(slice.ptr, static_cast<std::streamsize>(slice.len));
        }
    }}

    switch((0 != (flags::ff_newLine & flags)) + 2 * (0 != (flags::ff_flush & flags)))
    {
        default:
            FASTFORMAT_CONTRACT_ENFORCE_UNEXPECTED_CONDITION_APPL_LAYER("impossible flags combination permutation");
        case    0:  // Do nothing
            break;
        case    1:  // New line only
            sink.write(FASTFORMAT_LITERAL_STRING("\n"), 1);
            break;
        case    2:  // Flush only
            sink.flush();
            break;
        case    3:  // New line and flush
            sink << std::endl;
            break;
    }

    if(sink.fail())
    {
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
        // TODO: Use more-derived exception and capture errno
        throw sink_output_exception("Failed to write statement");
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
    }

    return sink;
}
inline S change_windows_replacement_parameters_to_fastformat(S const& str)
{
    typedef ss_typename_type_k S::const_iterator    iter_t;

    enum state_t
    {
        normal, percent, number
    }       state   =   normal;
    S       str2;
    int     index   =   0;

    str2.reserve(str.size() + 10);

    { for(iter_t begin = str.begin(); begin != str.end(); ++begin)
    {
        bool isNumber = false;

        switch(*begin)
        {
            case    '0':
            case    '1':
            case    '2':
            case    '3':
            case    '4':
            case    '5':
            case    '6':
            case    '7':
            case    '8':
            case    '9':
                isNumber = true;
        }

        if( number == state &&
            !isNumber)
        {
            ff_char_t   parameter[32];
            int         cch = fastformat_util_snprintf(&parameter[0], STLSOFT_NUM_ELEMENTS(parameter), FASTFORMAT_LITERAL_STRING("{%d}"), index - 1);

            str2.append(parameter, size_t(cch));
            str2.append(1u, *begin);

            state = normal;
        }
        else
        {
            switch(*begin)
            {
                case    '%':
                    switch(state)
                    {
                        default:
                        case    number:
                            FASTFORMAT_CONTRACT_ENFORCE_UNEXPECTED_CONDITION_INTERNAL("unexpected state");
                        case    normal:
                            state = percent;
                            break;
                        case    percent:
                            state = normal;
                            str2.append(1, '%');
                            break;
                    }
                    break;
                case    '0':
                case    '1':
                case    '2':
                case    '3':
                case    '4':
                case    '5':
                case    '6':
                case    '7':
                case    '8':
                case    '9':
                    switch(state)
                    {
                        default:
                            FASTFORMAT_CONTRACT_ENFORCE_UNEXPECTED_CONDITION_INTERNAL("unexpected state");
                        case    normal:
                            str2.append(1, *begin);
                            break;
                        case    percent:
                            state = number;
                            index = (*begin - '0');
                            break;
                        case    number:
                            index = (10 * index) + (*begin - '0');
                            break;
                    }
                    break;
                default:
                    state = normal;
                    str2.append(1, *begin);
                    break;
            }
        }
    }}

    if(number == state)
	{
        ff_char_t   parameter[32];
        int         cch = fastformat_util_snprintf(&parameter[0], STLSOFT_NUM_ELEMENTS(parameter), FASTFORMAT_LITERAL_STRING("{%d}"), index - 1);

        str2.append(parameter, size_t(cch));
    }

    return str2;
}
Ejemplo n.º 5
0
 inline std::basic_string<ff_char_t> filter_type(bool value, bool const*, ff_char_t const volatile*)
 {
     return value ? FASTFORMAT_LITERAL_STRING("True") : FASTFORMAT_LITERAL_STRING("False");
 }
Ejemplo n.º 6
0
inline stlsoft::basic_shim_string<ff_char_t, 64> real_helper_4(
    double const&       value
,   int                 minimumWidth
,   int                 precision
,   ff_char_t const*    specifier
)
{
    ff_char_t   type    =   'f';
    ff_char_t   fmt_[]  =   FASTFORMAT_LITERAL_STRING("%-01234567890123456789.01234567890123456789f");
    ff_char_t*  fmt     =   fmt_;

    if(NULL != specifier)
    {
        type = *specifier;
    }

    if( default_width_sentinel_() == minimumWidth &&
        precision < 0)
    {
        fmt[1] = type;
        fmt[2] = '\0';
    }
    else
    {
        if(default_width_sentinel_() == minimumWidth)
        {
            minimumWidth = 0;
        }
        if(precision < 0)
        {
            precision = 0;
        }

        // Performance tests show a substantial advantage in using
        // integer_to_string() over fastformat_util_snprintf()

#if 0

        int n = fastformat_util_snprintf(&fmt[0], STLSOFT_NUM_ELEMENTS(fmt_) - 1, FASTFORMAT_LITERAL_STRING("%%%d.%d%c"), minimumWidth, precision, type);

        FASTFORMAT_CONTRACT_ENFORCE_ASSUMPTION((n > 0) && (n < int(STLSOFT_NUM_ELEMENTS(fmt_)) - 1));

        fmt[n] = '\0';

#else /* ? 0 */

        const size_t    fmtDim  =   STLSOFT_NUM_ELEMENTS(fmt_) - 1;
        ff_char_t*      end     =   &fmt[fmtDim];
        size_t          n1;
        size_t          n2;

        stlsoft::integer_to_string(end - 21, 21, precision, &n1);
        *--end = type;
        end -= n1;
        stlsoft::integer_to_string(end - 21, 21, minimumWidth, &n2);
        *--end = '.';
        end -= n2;
        *--end = '%';
        fmt = end;

#endif /* 0 */
    }

    return real_helper_2(value, fmt);
}