Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

nsPrintfCString Class Reference

#include <nsPrintfCString.h>

List of all members.


Detailed Description

|nsPrintfCString| lets you use a formated |printf| string as an |const nsACString|.

myCStr += nsPrintfCString("%f", 13.917); // ...a general purpose substitute for |AppendFloat|

For longer patterns, you'll want to use the constructor that takes a length

nsPrintfCString(128, "%f, %f, %f, %f, %f, %f, %f, %i, %f", x, y, z, 3.2, j, k, l, 3, 3.1);

Exceding the default size (which you must specify in the constructor, it is not determined) causes an allocation, so avoid that. If your formatted string exceeds the allocated space, it is cut off at the size of the buffer, no error is reported (and no out-of-bounds writing occurs). This class is intended to be useful for numbers and short strings, not arbitrary formatting of other strings (e.g., with s). There is currently no wide version of this class, since wide |printf| is not generally available. That means to get a wide version of your formatted data, you must, e.g.,

CopyASCIItoUTF16(nsPrintfCString("%f", 13.917"), myStr);

That's another good reason to avoid this class for anything but numbers ... as strings can be much more efficiently handled with |NS_LITERAL_[C]STRING| and |nsLiteral[C]String|.

Definition at line 70 of file nsPrintfCString.h.


Public Member Functions

 nsPrintfCString (size_type n, const char_type *format,...)
 nsPrintfCString (const char_type *format,...)

Private Types

enum  { kLocalBufferSize = 15 }
typedef nsCString string_type

Private Attributes

char_type mLocalBuffer [kLocalBufferSize+1]

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index