1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsPrintfCString_h___
8 #define nsPrintfCString_h___
13 * nsPrintfCString lets you create a nsCString using a printf-style format
14 * string. For example:
16 * NS_WARNING(nsPrintfCString("Unexpected value: %f", 13.917).get());
18 * nsPrintfCString has a small built-in auto-buffer. For larger strings, it
19 * will allocate on the heap.
21 * See also nsCString::AppendPrintf().
23 class nsPrintfCString
: public nsAutoCStringN
<16> {
24 typedef nsCString string_type
;
27 explicit nsPrintfCString(const char_type
* aFormat
, ...)
28 MOZ_FORMAT_PRINTF(2, 3) {
30 va_start(ap
, aFormat
);
31 AppendVprintf(aFormat
, ap
);
39 * nsVPrintfCString is like nsPrinfCString but is created using vprintf style
40 * args. This is useful for functions that have already received variadic
41 * arguments and want to create a nsPrintfCString. For example:
43 * void LogToSeveralLocations(const char* aFormat,...) {
45 * va_start(ap, aFormat);
46 * nsPrintfCString logString(aFormat, ap);
51 * See also nsCString::AppendVprintf().
54 class nsVprintfCString
: public nsAutoCStringN
<16> {
55 typedef nsCString string_type
;
58 nsVprintfCString(const char_type
* aFormat
, va_list aArgs
)
59 MOZ_FORMAT_PRINTF(2, 0) {
60 AppendVprintf(aFormat
, aArgs
);
64 #endif // !defined(nsPrintfCString_h___)