1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/string/public/nsPrintfCString.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,41 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsPrintfCString_h___ 1.10 +#define nsPrintfCString_h___ 1.11 + 1.12 +#include "nsString.h" 1.13 + 1.14 +/** 1.15 + * nsPrintfCString lets you create a nsCString using a printf-style format 1.16 + * string. For example: 1.17 + * 1.18 + * NS_WARNING(nsPrintfCString("Unexpected value: %f", 13.917).get()); 1.19 + * 1.20 + * nsPrintfCString has a small built-in auto-buffer. For larger strings, it 1.21 + * will allocate on the heap. 1.22 + * 1.23 + * See also nsCString::AppendPrintf(). 1.24 + */ 1.25 +class nsPrintfCString : public nsFixedCString 1.26 +{ 1.27 + typedef nsCString string_type; 1.28 + 1.29 +public: 1.30 + explicit nsPrintfCString( const char_type* format, ... ) 1.31 + : nsFixedCString(mLocalBuffer, kLocalBufferSize, 0) 1.32 + { 1.33 + va_list ap; 1.34 + va_start(ap, format); 1.35 + AppendPrintf(format, ap); 1.36 + va_end(ap); 1.37 + } 1.38 + 1.39 +private: 1.40 + static const uint32_t kLocalBufferSize = 16; 1.41 + char_type mLocalBuffer[kLocalBufferSize]; 1.42 +}; 1.43 + 1.44 +#endif // !defined(nsPrintfCString_h___)