nsACString

« XPCOM API Reference

Summary

The nsACString abstract class represents a character string composed of single-byte storage units. This class is typically used to represent ASCII or UTF-8 character arrays.

#include "nsStringAPI.h"
  class nsACString { ... };

Typedefs

char_type [char]
Storage unit for this class.
self_type [nsACString]
An alias for the type of this class.
size_type [PRUint32]
Type used to represent the number of bytes stored in the string.
index_type [PRUint32]
Type used to represent an offset into the string.

Methods

BeginReading
The BeginReading function returns a const pointer to the first element of the string's internal buffer.
EndReading
The EndReading function returns a const char_type pointer to the element just beyond the last element of the string's internal buffer.
Length
The Length function returns the number of storage units in the string's internal buffer (not including the null-terminator if present).
Assign
The Assign family of functions sets the value of a string's internal buffer.
Replace
The Replace family of functions sets the value of a string's internal buffer.
Append
The Append family of functions appends a value to the end of a string's internal buffer.
Insert
The Insert family of functions inserts a value into a string's internal buffer.
Cut
The Cut function removes a section of the string's internal buffer.

Operators

operator=
This operator is a shortcut for the Assign family of functions.
operator+=
This operator is a shortcut for the Append family of functions.

Remarks

The nsACString class is never instantiated directly. It should be instantiated using a subclass, such as nsEmbedCString.

nsACString corresponds to the ACString and AUTF8String XPIDL data types. nsACString by itself does not imply a particular character encoding. That is, it may be used to store UTF-8 characters, ASCII characters, or any random binary data. The character encoding in use for a particular nsACString instance depends on the context in which it is used. If used with XPIDL, then the character encodings of the corresponding XPIDL data types applies.

nsACString may even hold data with embedded null bytes. Thus, the length of the data contained in the nsACString should be determined by calling the nsACString::Length() method.

The methods defined on nsACString are implemented as inline wrappers around the XPCOM string functions, prefixed with NS_CString. See, for example, NS_CStringGetData.

See also

Document Tags and Contributors

 Contributors to this page: Sheppy, Pmash, Dria, Callek
 Last updated by: Sheppy,