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/. */ 6 7 #ifndef nsPrintfCString_h___ 8 #define nsPrintfCString_h___ 9 10 #include "nsString.h" 11 12 /** 13 * nsPrintfCString lets you create a nsCString using a printf-style format 14 * string. For example: 15 * 16 * NS_WARNING(nsPrintfCString("Unexpected value: %f", 13.917).get()); 17 * 18 * nsPrintfCString has a small built-in auto-buffer. For larger strings, it 19 * will allocate on the heap. 20 * 21 * See also nsCString::AppendPrintf(). 22 */ 23 class nsPrintfCString : public nsFixedCString 24 { 25 typedef nsCString string_type; 26 27 public: 28 explicit nsPrintfCString(const char_type* aFormat, ...) 29 : nsFixedCString(mLocalBuffer, kLocalBufferSize, 0) 30 { 31 va_list ap; 32 va_start(ap, aFormat); 33 AppendPrintf(aFormat, ap); 34 va_end(ap); 35 } 36 37 private: 38 static const uint32_t kLocalBufferSize = 16; 39 char_type mLocalBuffer[kLocalBufferSize]; 40 }; 41 42 #endif // !defined(nsPrintfCString_h___) 43