michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsPrintfCString_h___ michael@0: #define nsPrintfCString_h___ michael@0: michael@0: #include "nsString.h" michael@0: michael@0: /** michael@0: * nsPrintfCString lets you create a nsCString using a printf-style format michael@0: * string. For example: michael@0: * michael@0: * NS_WARNING(nsPrintfCString("Unexpected value: %f", 13.917).get()); michael@0: * michael@0: * nsPrintfCString has a small built-in auto-buffer. For larger strings, it michael@0: * will allocate on the heap. michael@0: * michael@0: * See also nsCString::AppendPrintf(). michael@0: */ michael@0: class nsPrintfCString : public nsFixedCString michael@0: { michael@0: typedef nsCString string_type; michael@0: michael@0: public: michael@0: explicit nsPrintfCString( const char_type* format, ... ) michael@0: : nsFixedCString(mLocalBuffer, kLocalBufferSize, 0) michael@0: { michael@0: va_list ap; michael@0: va_start(ap, format); michael@0: AppendPrintf(format, ap); michael@0: va_end(ap); michael@0: } michael@0: michael@0: private: michael@0: static const uint32_t kLocalBufferSize = 16; michael@0: char_type mLocalBuffer[kLocalBufferSize]; michael@0: }; michael@0: michael@0: #endif // !defined(nsPrintfCString_h___)