source: trunk/src/core/string.cpp @ 2102

Last change on this file since 2102 was 2102, checked in by sam, 8 years ago

core: try to fix a general compilation issue caused by inconsistent
namespaces between platforms.

  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16
17#ifdef WIN32
18#   define WIN32_LEAN_AND_MEAN
19#   include <windows.h>
20#endif
21
22#include <cstdarg>
23
24#include "core.h"
25
26namespace lol
27{
28
29String String::Printf(char const *format, ...)
30{
31    using std::vsnprintf;
32
33    String ret;
34    va_list ap;
35
36    /* vsnprintf() tells us how many character we need, and we need to
37     * add one for the terminating null byte. */
38    va_start(ap, format);
39    size_t needed = vsnprintf(NULL, 0, format, ap) + 1;
40    va_end(ap);
41
42    ((Super &)ret).Reserve(needed);
43    ret.m_count = needed;
44
45    /* We don’t use va_copy because Visual Studio 2010 does not support it. */
46    va_start(ap, format);
47    vsnprintf(&ret[0], needed, format, ap);
48    va_end(ap);
49
50    return ret;
51}
52
53} /* namespace lol */
54
Note: See TracBrowser for help on using the repository browser.