No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

57 líneas
1.2 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. #if defined __CELLOS_LV2__
  25. using std::vsnprintf;
  26. #endif
  27. String ret;
  28. va_list ap;
  29. /* vsnprintf() tells us how many character we need, and we need to
  30. * add one for the terminating null byte. */
  31. va_start(ap, format);
  32. size_t needed = vsnprintf(NULL, 0, format, ap) + 1;
  33. va_end(ap);
  34. ((Super &)ret).Reserve(needed);
  35. ret.m_count = needed;
  36. /* We don’t use va_copy because Visual Studio 2010 does not support it. */
  37. va_start(ap, format);
  38. vsnprintf(&ret[0], needed, format, ap);
  39. va_end(ap);
  40. return ret;
  41. }
  42. } /* namespace lol */