Changeset 2256 for trunk


Ignore:
Timestamp:
Jan 22, 2013, 1:48:46 AM (7 years ago)
Author:
sam
Message:

core: implement String::Printf() for va_list arguments.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/base/string.cpp

    r2216 r2256  
    2929String String::Printf(char const *format, ...)
    3030{
     31    String ret;
     32
     33    va_list ap;
     34    va_start(ap, format);
     35    ret = String::Printf(format, ap);
     36    va_end(ap);
     37
     38    return ret;
     39}
     40
     41String String::Printf(char const *format, va_list ap)
     42{
    3143#if defined __CELLOS_LV2__
    3244    using std::vsnprintf;
     
    3446
    3547    String ret;
    36     va_list ap;
     48
     49    /* Visual Studio 2010 does not support it va_copy. */
     50#if defined _MSC_VER
     51#   undef va_copy
     52#   define va_copy(dst, src) (dst = src)
     53#endif
     54    va_list ap2;
     55    va_copy(ap2, ap);
     56#if defined _MSC_VER
     57#   undef va_copy
     58#endif
    3759
    3860    /* vsnprintf() tells us how many character we need, and we need to
    3961     * add one for the terminating null byte. */
    40     va_start(ap, format);
    41     size_t needed = vsnprintf(NULL, 0, format, ap) + 1;
    42     va_end(ap);
     62    size_t needed = vsnprintf(NULL, 0, format, ap2) + 1;
    4363
    4464    ((Super &)ret).Reserve(needed);
    4565    ret.m_count = needed;
    4666
    47     /* We don’t use va_copy because Visual Studio 2010 does not support it. */
    48     va_start(ap, format);
    4967    vsnprintf(&ret[0], needed, format, ap);
    50     va_end(ap);
    5168
    5269    return ret;
  • trunk/src/lol/base/string.h

    r2249 r2256  
    2121
    2222#include <cstring>
     23#include <cstdarg>
    2324
    2425namespace lol
     
    141142    static String Printf(char const *format, ...) LOL_FMT_ATTR(1, 2);
    142143#undef LOL_FMT_ATTR
     144    static String Printf(char const *format, va_list ap);
    143145};
    144146
Note: See TracChangeset for help on using the changeset viewer.