Logo Search packages:      
Sourcecode: xulrunner version File versions

nsPrintfCString Class Reference

#include <nsPrintfCString.h>

Inheritance diagram for nsPrintfCString:

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 Types

typedef nsACString abstract_string_type
typedef char char_type
typedef PRInt32(* ComparatorFunc )(const char_type *a, const char_type *b, PRUint32 length)
typedef PRUint32 index_type
typedef nsCString self_type
typedef PRUint32 size_type

Public Member Functions

void Adopt (const char_type *aData, size_type aLength=PR_UINT32_MAX)
const char_type * get () const
 NS_HIDDEN_ (PRInt32) ToInteger(nsresult *aErrorCode
 NS_HIDDEN_ (void) AppendInt(int aInt
 NS_HIDDEN_ (PRInt32) RFindChar(char_type aChar) const
 NS_HIDDEN_ (PRInt32) FindChar(char_type aChar
 NS_HIDDEN_ (PRInt32) RFind(const char_type *aStr
 NS_HIDDEN_ (PRInt32) RFind(const char_type *aStr
 NS_HIDDEN_ (PRInt32) RFind(const self_type &aStr
 NS_HIDDEN_ (PRInt32) Find(const char_type *aStr
 NS_HIDDEN_ (PRInt32) Find(const char_type *aStr
 NS_HIDDEN_ (PRBool) operator<
 NS_HIDDEN_ (PRBool) operator<(const char_type *other) const
 NS_HIDDEN_ (PRBool) operator<(const self_type &other) const
 NS_HIDDEN_ (PRBool) Equals(const self_type &other
 NS_HIDDEN_ (PRBool) Equals(const char_type *other
 NS_HIDDEN_ (PRInt32) Compare(const self_type &other
 NS_HIDDEN_ (PRInt32) Compare(const char_type *other
 NS_HIDDEN_ (void) Trim(const char *aSet
 NS_HIDDEN_ (void) StripWhitespace()
 NS_HIDDEN_ (void) Assign(const char_type *aData
 NS_HIDDEN_ (void) Assign(const self_type &aString)
 NS_HIDDEN_ (PRBool) IsVoid() const
 NS_HIDDEN_ (void) SetIsVoid(PRBool val)
 NS_HIDDEN_ (PRBool) IsEmpty() const
 NS_HIDDEN_ (size_type) Length() const
 NS_HIDDEN_ (PRBool) SetLength(PRUint32 aLen)
 NS_HIDDEN_ (char_type *) EndWriting()
 NS_HIDDEN_ (char_type *) BeginWriting(PRUint32 aLen
 NS_HIDDEN_ (PRUint32) BeginWriting(char_type **begin
 NS_HIDDEN_ (char_type) First() const
 NS_HIDDEN_ (char_type) operator[](PRUint32 aPos) const
 NS_HIDDEN_ (char_type) CharAt(PRUint32 aPos) const
 NS_HIDDEN_ (const char_type *) EndReading() const
 NS_HIDDEN_ (const char_type *) BeginReading() const
 NS_HIDDEN_ (PRUint32) BeginReading(const char_type **begin
 nsPrintfCString (size_type n, const char_type *format,...)
 nsPrintfCString (const char_type *format,...)

Static Public Member Functions

static NS_HIDDEN_ (PRInt32) DefaultComparator(const char_type *a

Public Attributes

PRBool aLeading = PR_TRUE
PRInt32 aLen
PRUint32 aLen
size_type aLength
PRUint32 aOffset = 0) const
PRUint32 aRadix = 10) const
PRInt32 aRadix = 10)
PRBool PRBool aTrailing = PR_TRUE)
static const char_type * b
PRInt32 ComparatorFunc c = DefaultComparator) const
PRUint32 ComparatorFunc c = DefaultComparator) const
ComparatorFunc c = DefaultComparator ) const
char_type ** end = nsnull
const char_type ** end = nsnull) const
static const char_type PRUint32 length
char_type PRUint32 newSize = PR_UINT32_MAX)

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