nsAString

« XPCOM API Reference

Summary

The nsAString abstract class represents a character string composed of double-byte storage units. This class is typically used to represent Unicode character arrays.

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

Typedefs

char_type [PRUnichar]
Storage unit for this class.
self_type [nsAString]
An alias for the type of this class.
size_type [PRUint32]
Type used to represent the number of double-byte units 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 nsAString class is never instantiated directly. It should be instantiated using a subclass, such as nsEmbedString .

nsAString corresponds to the AString and DOMString XPIDL data types. nsAString by itself does not imply a particular character encoding. That is, it may be used to store UTF-16 characters, UCS-2 characters, or any random double-byte data. The character encoding in use for a particular nsAString 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.

nsAString may even hold data with embedded null values. Thus, the length of the data contained in the nsAString should be determined by calling the nsAString::Length method.

The methods defined on nsAString are implemented as inline wrappers around the XPCOM string functions, prefixed with NS_String. See, for example, NS_StringGetData.

See Also

nsAString::Length, EndReading, NS_StringGetData, nsEmbedString

Document Tags and Contributors

 Contributors to this page: JITR, freaktechnik, Sheppy, Pmash
 Last updated by: JITR,