/indra/llcommon/llformat.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 70 lines · 34 code · 7 blank · 29 comment · 0 complexity · 57a6ee5bd710910191d8f374161f08f2 MD5 · raw file

  1. /**
  2. * @file llformat.cpp
  3. * @date January 2007
  4. * @brief string formatting utility
  5. *
  6. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include "llformat.h"
  29. #include <cstdarg>
  30. // common used function with va_list argument
  31. // wrapper for vsnprintf to be called from llformatXXX functions.
  32. static void va_format(std::string& out, const char *fmt, va_list va)
  33. {
  34. char tstr[1024]; /* Flawfinder: ignore */
  35. #if LL_WINDOWS
  36. _vsnprintf(tstr, 1024, fmt, va);
  37. #else
  38. vsnprintf(tstr, 1024, fmt, va); /* Flawfinder: ignore */
  39. #endif
  40. out.assign(tstr);
  41. }
  42. std::string llformat(const char *fmt, ...)
  43. {
  44. std::string res;
  45. va_list va;
  46. va_start(va, fmt);
  47. va_format(res, fmt, va);
  48. va_end(va);
  49. return res;
  50. }
  51. std::string llformat_to_utf8(const char *fmt, ...)
  52. {
  53. std::string res;
  54. va_list va;
  55. va_start(va, fmt);
  56. va_format(res, fmt, va);
  57. va_end(va);
  58. #if LL_WINDOWS
  59. // made converting to utf8. See EXT-8318.
  60. res = ll_convert_string_to_utf8_string(res);
  61. #endif
  62. return res;
  63. }