2000-08-17 01:08:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-08-17 01:08:30 +00:00
|
|
|
|
|
|
|
#ifndef nsPrintfCString_h___
|
|
|
|
#define nsPrintfCString_h___
|
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
#ifndef nsString_h___
|
|
|
|
#include "nsString.h"
|
2001-04-02 19:40:52 +00:00
|
|
|
#endif
|
2000-08-17 01:08:30 +00:00
|
|
|
|
2012-04-13 16:58:59 +00:00
|
|
|
/**
|
|
|
|
* |nsPrintfCString| is syntactic sugar for a printf used as a
|
|
|
|
* |const nsACString| with a small builtin autobuffer. In almost all cases
|
|
|
|
* it is better to just use AppendPrintf. Example usage:
|
|
|
|
*
|
|
|
|
* NS_WARNING(nsPrintfCString("Unexpected value: %f", 13.917).get());
|
|
|
|
*/
|
|
|
|
class nsPrintfCString : public nsFixedCString
|
2000-08-17 01:08:30 +00:00
|
|
|
{
|
2004-02-19 02:44:03 +00:00
|
|
|
typedef nsCString string_type;
|
|
|
|
|
2000-08-17 01:08:30 +00:00
|
|
|
public:
|
2012-04-13 16:58:59 +00:00
|
|
|
explicit nsPrintfCString( const char_type* format, ... )
|
|
|
|
: nsFixedCString(mLocalBuffer, kLocalBufferSize, 0)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
AppendPrintf(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2000-08-17 01:08:30 +00:00
|
|
|
private:
|
2012-04-13 16:58:59 +00:00
|
|
|
enum { kLocalBufferSize=15 };
|
|
|
|
// ought to be large enough for most things ... a |long long| needs at most 20 (so you'd better ask)
|
|
|
|
// pinkerton suggests 7. We should measure and decide what's appropriate
|
|
|
|
|
|
|
|
char_type mLocalBuffer[ kLocalBufferSize ];
|
2000-08-17 01:08:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !defined(nsPrintfCString_h___)
|