Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

53 righe
1.1 KiB

  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdio>
  14. #ifdef WIN32
  15. # define WIN32_LEAN_AND_MEAN
  16. # include <windows.h>
  17. #endif
  18. #include <cstdarg>
  19. #include "core.h"
  20. namespace lol
  21. {
  22. String String::Printf(char const *format, ...)
  23. {
  24. String ret;
  25. va_list ap;
  26. /* vsnprintf() tells us how many character we need, and we need to
  27. * add one for the terminating null byte. */
  28. va_start(ap, format);
  29. size_t needed = vsnprintf(NULL, 0, format, ap) + 1;
  30. va_end(ap);
  31. ((Super &)ret).Reserve(needed);
  32. ret.m_count = needed;
  33. /* We don’t use va_copy because Visual Studio 2010 does not support it. */
  34. va_start(ap, format);
  35. std::vsnprintf(&ret[0], needed, format, ap);
  36. va_end(ap);
  37. return ret;
  38. }
  39. } /* namespace lol */