Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / xpcom / string / nsPrintfCString.h
blobf7228887050e2965a3eddcbfd9f9e881a85856d7
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___
10 #include "nsString.h"
12 /**
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;
26 public:
27 explicit nsPrintfCString(const char_type* aFormat, ...)
28 MOZ_FORMAT_PRINTF(2, 3) {
29 va_list ap;
30 va_start(ap, aFormat);
31 AppendVprintf(aFormat, ap);
32 va_end(ap);
36 /**
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,...) {
44 * va_list ap;
45 * va_start(ap, aFormat);
46 * nsPrintfCString logString(aFormat, ap);
47 * va_end(ap);
48 * // Use logString
49 * }
51 * See also nsCString::AppendVprintf().
54 class nsVprintfCString : public nsAutoCStringN<16> {
55 typedef nsCString string_type;
57 public:
58 nsVprintfCString(const char_type* aFormat, va_list aArgs)
59 MOZ_FORMAT_PRINTF(2, 0) {
60 AppendVprintf(aFormat, aArgs);
64 #endif // !defined(nsPrintfCString_h___)