PageRenderTime 24ms CodeModel.GetById 8ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/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
28#include "linden_common.h"
29
30#include "llformat.h"
31
32#include <cstdarg>
33
34// common used function with va_list argument
35// wrapper for vsnprintf to be called from llformatXXX functions.
36static void va_format(std::string& out, const char *fmt, va_list va)
37{
38	char tstr[1024];	/* Flawfinder: ignore */
39#if LL_WINDOWS
40	_vsnprintf(tstr, 1024, fmt, va);
41#else
42	vsnprintf(tstr, 1024, fmt, va);	/* Flawfinder: ignore */
43#endif
44	out.assign(tstr);
45}
46
47std::string llformat(const char *fmt, ...)
48{
49	std::string res;
50	va_list va;
51	va_start(va, fmt);
52	va_format(res, fmt, va);
53	va_end(va);
54	return res;
55}
56
57std::string llformat_to_utf8(const char *fmt, ...)
58{
59	std::string res;
60	va_list va;
61	va_start(va, fmt);
62	va_format(res, fmt, va);
63	va_end(va);
64
65#if LL_WINDOWS
66	// made converting to utf8. See EXT-8318.
67	res = ll_convert_string_to_utf8_string(res);
68#endif
69	return res;
70}