Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
nsTXPIDLString_CharT Class Reference

nsTXPIDLString extends nsTString such that: More...

#include <nsTString.h>

Inheritance diagram for nsTXPIDLString_CharT:
Inheritance graph
[legend]
Collaboration diagram for nsTXPIDLString_CharT:
Collaboration graph
[legend]

List of all members.

Public Types

typedef nsTXPIDLString_CharT self_type
enum  {
  F_NONE = 0, F_TERMINATED = 1 << 0, F_VOIDED = 1 << 1, F_SHARED = 1 << 2,
  F_OWNED = 1 << 3, F_FIXED = 1 << 4, F_CLASS_FIXED = 1 << 16
}
typedef nsTString_CharT string_type
typedef char_typechar_iterator
typedef const char_typeconst_char_iterator
typedef nsTSubstring_CharT base_string_type
typedef CharT char_type
typedef nsCharTraits< char_typechar_traits
typedef
char_traits::incompatible_char_type 
incompatible_char_type
typedef nsTAString_CharT abstract_string_type
typedef nsTObsoleteAString_CharT obsolete_string_type
typedef nsTSubstring_CharT substring_type
typedef nsTSubstringTuple_CharT substring_tuple_type
typedef nsReadingIterator
< char_type
const_iterator
typedef nsWritingIterator
< char_type
iterator
typedef nsTStringComparator_CharT comparator_type
typedef PRUint32 size_type
typedef PRUint32 index_type

Public Member Functions

 nsTXPIDLString_CharT ()
 nsTXPIDLString_CharT (const self_type &str)
const char_typeget () const
 returns the null-terminated string
 operator const char_type * () const
char_type operator[] (PRInt32 i) const
self_typeoperator= (char_type c)
self_typeoperator= (const char_type *data)
self_typeoperator= (const self_type &str)
self_typeoperator= (const substring_type &str)
self_typeoperator= (const substring_tuple_type &tuple)
char_type CharAt (index_type i) const
 returns character at specified index.
char_type operator[] (index_type i) const
const_char_iterator BeginReading () const
 reading iterators
const_iteratorBeginReading (const_iterator &iter) const
 deprecated reading iterators
const_char_iteratorBeginReading (const_char_iterator &iter) const
const_char_iterator EndReading () const
const_iteratorEndReading (const_iterator &iter) const
const_char_iteratorEndReading (const_char_iterator &iter) const
char_iterator BeginWriting ()
 writing iterators
iteratorBeginWriting (iterator &iter)
 deprecated writing iterators
char_iteratorBeginWriting (char_iterator &iter)
char_iterator EndWriting ()
iteratorEndWriting (iterator &iter)
char_iteratorEndWriting (char_iterator &iter)
const char_typeData () const
 accessors
size_type Length () const
PRBool IsEmpty () const
PRBool IsVoid () const
PRBool IsTerminated () const
char_type First () const
char_type Last () const
NS_COM size_type NS_FASTCALL CountChar (char_type) const
NS_COM PRInt32 NS_FASTCALL FindChar (char_type, index_type offset=0) const
NS_COM PRBool NS_FASTCALL Equals (const self_type &) const
 equality
NS_COM PRBool NS_FASTCALL Equals (const self_type &, const comparator_type &) const
NS_COM PRBool NS_FASTCALL Equals (const char_type *data) const
NS_COM PRBool NS_FASTCALL Equals (const char_type *data, const comparator_type &comp) const
NS_COM PRBool NS_FASTCALL EqualsASCII (const char *data, size_type len) const
 An efficient comparison with ASCII that can be used even for wide strings.
NS_COM PRBool NS_FASTCALL EqualsASCII (const char *data) const
 An efficient comparison with ASCII that can be used even for wide strings.
template<int N>
PRBool EqualsLiteral (const char(&str)[N]) const
template<int N>
PRBool EqualsLiteral (char(&str)[N]) const
NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII (const char *data, size_type len) const
NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII (const char *data) const
template<int N>
PRBool LowerCaseEqualsLiteral (const char(&str)[N]) const
template<int N>
PRBool LowerCaseEqualsLiteral (char(&str)[N]) const
void Assign (char_type c)
 assignment
NS_COM void NS_FASTCALL Assign (const char_type *data, size_type length=size_type(-1))
NS_COM void NS_FASTCALL Assign (const self_type &)
NS_COM void NS_FASTCALL Assign (const substring_tuple_type &)
NS_COM void NS_FASTCALL AssignASCII (const char *data, size_type length)
NS_COM void NS_FASTCALL AssignASCII (const char *data)
template<int N>
void AssignLiteral (const char(&str)[N])
template<int N>
void AssignLiteral (char(&str)[N])
NS_COM void NS_FASTCALL Adopt (char_type *data, size_type length=size_type(-1))
void Replace (index_type cutStart, size_type cutLength, char_type c)
 buffer manipulation
NS_COM void NS_FASTCALL Replace (index_type cutStart, size_type cutLength, const char_type *data, size_type length=size_type(-1))
void Replace (index_type cutStart, size_type cutLength, const self_type &str)
NS_COM void NS_FASTCALL Replace (index_type cutStart, size_type cutLength, const substring_tuple_type &tuple)
NS_COM void NS_FASTCALL ReplaceASCII (index_type cutStart, size_type cutLength, const char *data, size_type length=size_type(-1))
void Append (char_type c)
void Append (const char_type *data, size_type length=size_type(-1))
void Append (const self_type &str)
void Append (const substring_tuple_type &tuple)
void AppendASCII (const char *data, size_type length=size_type(-1))
template<int N>
void AppendLiteral (const char(&str)[N])
template<int N>
void AppendLiteral (char(&str)[N])
self_typeoperator+= (char_type c)
self_typeoperator+= (const char_type *data)
self_typeoperator+= (const self_type &str)
self_typeoperator+= (const substring_tuple_type &tuple)
void Insert (char_type c, index_type pos)
void Insert (const char_type *data, index_type pos, size_type length=size_type(-1))
void Insert (const self_type &str, index_type pos)
void Insert (const substring_tuple_type &tuple, index_type pos)
void Cut (index_type cutStart, size_type cutLength)
NS_COM void NS_FASTCALL SetCapacity (size_type capacity)
 buffer sizing
NS_COM void NS_FASTCALL SetLength (size_type)
void Truncate (size_type newLength=0)
NS_COM void NS_FASTCALL SetIsVoid (PRBool)
 string data is never null, but can be marked void.
NS_COM void StripChar (char_type aChar, PRInt32 aOffset=0)
 This method is used to remove all occurances of aChar from this string.

Protected Member Functions

void NS_FASTCALL Finalize ()
 this function releases mData and does not change the value of any of its member variables.
PRBool NS_FASTCALL MutatePrep (size_type capacity, char_type **old_data, PRUint32 *old_flags)
 this function prepares mData to be mutated.
PRBool NS_FASTCALL ReplacePrep (index_type cutStart, size_type cutLength, size_type newLength)
 this function prepares a section of mData to be modified.
size_type NS_FASTCALL Capacity () const
 returns the number of writable storage units starting at mData.
NS_COM void NS_FASTCALL EnsureMutable ()
 this helper function can be called prior to directly manipulating the contents of mData.
PRBool IsDependentOn (const char_type *start, const char_type *end) const
 returns true if this string overlaps with the given string fragment.
void SetDataFlags (PRUint32 dataFlags)
 this helper function stores the specified dataFlags in mFlags

Protected Attributes

char_typemData
size_type mLength
PRUint32 mFlags

Friends

class nsTObsoleteAStringThunk_CharT
class nsTAString_CharT
class nsTSubstringTuple_CharT
class nsTPromiseFlatString_CharT

Detailed Description

nsTXPIDLString extends nsTString such that:

(1) mData can be null (2) objects of this type can be automatically cast to |const CharT*| (3) getter_Copies method is supported to adopt data

Definition at line 583 of file nsTString.h.


Member Typedef Documentation

Definition at line 116 of file nsTAString.h.

Definition at line 68 of file nsTSubstring.h.

Definition at line 62 of file nsTSubstring.h.

Definition at line 111 of file nsTAString.h.

typedef CharT nsTAString_CharT::char_type [inherited]

Definition at line 110 of file nsTAString.h.

Definition at line 124 of file nsTAString.h.

Definition at line 63 of file nsTSubstring.h.

Definition at line 121 of file nsTAString.h.

typedef char_traits::incompatible_char_type nsTAString_CharT::incompatible_char_type [inherited]

Definition at line 113 of file nsTAString.h.

Definition at line 127 of file nsTAString.h.

Definition at line 122 of file nsTAString.h.

Definition at line 117 of file nsTAString.h.

Reimplemented from nsTString_CharT.

Reimplemented in nsTAdoptingString_CharT.

Definition at line 587 of file nsTString.h.

Definition at line 126 of file nsTAString.h.

Definition at line 60 of file nsTSubstring.h.

Definition at line 119 of file nsTAString.h.

Definition at line 118 of file nsTAString.h.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
F_NONE 
F_TERMINATED 
F_VOIDED 
F_SHARED 
F_OWNED 
F_FIXED 
F_CLASS_FIXED 

Definition at line 607 of file nsTSubstring.h.

        {
          F_NONE         = 0,       // no flags

          // data flags are in the lower 16-bits
          F_TERMINATED   = 1 << 0,  // IsTerminated returns true
          F_VOIDED       = 1 << 1,  // IsVoid returns true
          F_SHARED       = 1 << 2,  // mData points to a heap-allocated, shared buffer
          F_OWNED        = 1 << 3,  // mData points to a heap-allocated, raw buffer
          F_FIXED        = 1 << 4,  // mData points to a fixed-size writable, dependent buffer

          // class flags are in the upper 16-bits
          F_CLASS_FIXED  = 1 << 16   // indicates that |this| is of type nsTFixedString
        };

Constructor & Destructor Documentation

Definition at line 591 of file nsTString.h.

        : string_type(NS_CONST_CAST(char_type*, char_traits::sEmptyBuffer), 0, F_TERMINATED | F_VOIDED) {}

Definition at line 595 of file nsTString.h.

        : string_type(NS_CONST_CAST(char_type*, char_traits::sEmptyBuffer), 0, F_TERMINATED | F_VOIDED)
        {
          Assign(str);
        }

Here is the call graph for this function:


Member Function Documentation

void nsTSubstring_CharT::Adopt ( char_type data,
size_type  length = size_type(-1) 
) [inherited]

Definition at line 402 of file nsTSubstring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::Append ( char_type  c) [inline, inherited]

Definition at line 354 of file nsTSubstring.h.

{ Replace(mLength, 0, c); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::Append ( const char_type data,
size_type  length = size_type(-1) 
) [inline, inherited]

Definition at line 355 of file nsTSubstring.h.

Here is the call graph for this function:

void nsTSubstring_CharT::Append ( const self_type str) [inline, inherited]

Definition at line 356 of file nsTSubstring.h.

{ Replace(mLength, 0, str); }

Here is the call graph for this function:

void nsTSubstring_CharT::Append ( const substring_tuple_type tuple) [inline, inherited]

Definition at line 357 of file nsTSubstring.h.

{ Replace(mLength, 0, tuple); }

Here is the call graph for this function:

void nsTSubstring_CharT::AppendASCII ( const char *  data,
size_type  length = size_type(-1) 
) [inline, inherited]

Definition at line 362 of file nsTSubstring.h.

Here is the call graph for this function:

Here is the caller graph for this function:

template<int N>
void nsTSubstring_CharT::AppendLiteral ( const char(&)  str[N]) [inline, inherited]

Definition at line 372 of file nsTSubstring.h.

                  { AppendASCII(str, N-1); }

Here is the call graph for this function:

template<int N>
void nsTSubstring_CharT::AppendLiteral ( char(&)  str[N]) [inline, inherited]

Definition at line 375 of file nsTSubstring.h.

                  { AppendASCII(str, N-1); }

Here is the call graph for this function:

void nsTSubstring_CharT::Assign ( char_type  c) [inline, inherited]

assignment

Definition at line 303 of file nsTSubstring.h.

{ Assign(&c, 1); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::Assign ( const char_type data,
size_type  length = size_type(-1) 
) [inherited]

Definition at line 287 of file nsTSubstring.cpp.

  {
      // unfortunately, some callers pass null :-(
    if (!data)
      {
        Truncate();
        return;
      }

    if (length == size_type(-1))
      length = char_traits::length(data);

    if (IsDependentOn(data, data + length))
      {
        // take advantage of sharing here...
        Assign(string_type(data, length));
        return;
      }

    if (ReplacePrep(0, mLength, length))
      char_traits::copy(mData, data, length);
  }

Here is the call graph for this function:

Definition at line 335 of file nsTSubstring.cpp.

  {
    // |str| could be sharable.  we need to check its flags to know how to
    // deal with it.

    if (&str == this)
      return;

    if (str.mFlags & F_SHARED)
      {
        // nice! we can avoid a string copy :-)

        // |str| should be null-terminated
        NS_ASSERTION(str.mFlags & F_TERMINATED, "shared, but not terminated");

        ::ReleaseData(mData, mFlags);

        mData = str.mData;
        mLength = str.mLength;
        SetDataFlags(F_TERMINATED | F_SHARED);

        // get an owning reference to the mData
        nsStringBuffer::FromData(mData)->AddRef();
      }
    else if (str.mFlags & F_VOIDED)
      {
        // inherit the F_VOIDED attribute
        SetIsVoid(PR_TRUE);
      }
    else
      {
        // else, treat this like an ordinary assignment.
        Assign(str.Data(), str.Length());
      }
  }

Here is the call graph for this function:

Definition at line 372 of file nsTSubstring.cpp.

  {
    if (tuple.IsDependentOn(mData, mData + mLength))
      {
        // take advantage of sharing here...
        Assign(string_type(tuple));
        return;
      }

    size_type length = tuple.Length();

    if (ReplacePrep(0, mLength, length) && length)
      tuple.WriteTo(mData, length);
  }

Here is the call graph for this function:

void nsTSubstring_CharT::AssignASCII ( const char *  data,
size_type  length 
) [inherited]

Definition at line 311 of file nsTSubstring.cpp.

  {
    // A Unicode string can't depend on an ASCII string buffer,
    // so this dependence check only applies to CStrings.
#ifdef CharT_is_char
    if (IsDependentOn(data, data + length))
      {
        // take advantage of sharing here...
        Assign(string_type(data, length));
        return;
      }
#endif

    if (ReplacePrep(0, mLength, length))
      char_traits::copyASCII(mData, data, length);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::AssignASCII ( const char *  data) [inherited]

Definition at line 329 of file nsTSubstring.cpp.

  {
    AssignASCII(data, strlen(data));
  }

Here is the call graph for this function:

template<int N>
void nsTSubstring_CharT::AssignLiteral ( const char(&)  str[N]) [inline, inherited]

Definition at line 322 of file nsTSubstring.h.

                  { AssignASCII(str, N-1); }

Here is the call graph for this function:

template<int N>
void nsTSubstring_CharT::AssignLiteral ( char(&)  str[N]) [inline, inherited]

Definition at line 325 of file nsTSubstring.h.

                  { AssignASCII(str, N-1); }

Here is the call graph for this function:

reading iterators

Definition at line 82 of file nsTSubstring.h.

{ return mData; }

Here is the caller graph for this function:

const_iterator& nsTSubstring_CharT::BeginReading ( const_iterator iter) const [inline, inherited]

deprecated reading iterators

Definition at line 89 of file nsTSubstring.h.

        {
          iter.mStart = mData;
          iter.mEnd = mData + mLength;
          iter.mPosition = iter.mStart;
          return iter;
        }

Definition at line 105 of file nsTSubstring.h.

        {
          return iter = mData;
        }

writing iterators

Definition at line 120 of file nsTSubstring.h.

{ EnsureMutable(); return mData; }

Here is the call graph for this function:

Here is the caller graph for this function:

iterator& nsTSubstring_CharT::BeginWriting ( iterator iter) [inline, inherited]

deprecated writing iterators

Definition at line 127 of file nsTSubstring.h.

        {
          EnsureMutable();
          iter.mStart = mData;
          iter.mEnd = mData + mLength;
          iter.mPosition = iter.mStart;
          return iter;
        }

Here is the call graph for this function:

Definition at line 145 of file nsTSubstring.h.

        {
          EnsureMutable();
          return iter = mData;
        }

Here is the call graph for this function:

returns the number of writable storage units starting at mData.

the value does not include space for the null-terminator character.

NOTE: this function returns size_type(-1) if mData is immutable.

Definition at line 238 of file nsTSubstring.cpp.

  {
    // return size_type(-1) to indicate an immutable buffer

    size_type capacity;
    if (mFlags & F_SHARED)
      {
        // if the string is readonly, then we pretend that it has no capacity.
        nsStringBuffer* hdr = nsStringBuffer::FromData(mData);
        if (hdr->IsReadonly())
          capacity = size_type(-1);
        else
          capacity = (hdr->StorageSize() / sizeof(char_type)) - 1;
      }
    else if (mFlags & F_FIXED)
      {
        capacity = AsFixedString(this)->mFixedCapacity;
      }
    else if (mFlags & F_OWNED)
      {
        // we don't store the capacity of an adopted buffer because that would
        // require an additional member field.  the best we can do is base the
        // capacity on our length.  remains to be seen if this is the right
        // trade-off.
        capacity = mLength;
      }
    else
      {
        capacity = size_type(-1);
      }

    return capacity;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

char_type nsTString_CharT::CharAt ( index_type  i) const [inline, inherited]

returns character at specified index.

NOTE: unlike nsTSubstring::CharAt, this function allows you to index the null terminator character.

Reimplemented from nsTSubstring_CharT.

Definition at line 131 of file nsTString.h.

        {
          NS_ASSERTION(i <= mLength, "index exceeds allowable range");
          return mData[i];
        }

Here is the caller graph for this function:

Definition at line 656 of file nsTSubstring.cpp.

  {
    const char_type *start = mData;
    const char_type *end   = mData + mLength;

    return NS_COUNT(start, end, c);
  }

Here is the call graph for this function:

void nsTSubstring_CharT::Cut ( index_type  cutStart,
size_type  cutLength 
) [inline, inherited]

Definition at line 395 of file nsTSubstring.h.

{ Replace(cutStart, cutLength, char_traits::sEmptyBuffer, 0); }

Here is the call graph for this function:

Here is the caller graph for this function:

const char_type* nsTSubstring_CharT::Data ( ) const [inline, inherited]

accessors

Definition at line 163 of file nsTSubstring.h.

        {
          return mData;
        }

Here is the caller graph for this function:

const_char_iterator nsTSubstring_CharT::EndReading ( ) const [inline, inherited]

Definition at line 83 of file nsTSubstring.h.

{ return mData + mLength; }
const_iterator& nsTSubstring_CharT::EndReading ( const_iterator iter) const [inline, inherited]

Definition at line 97 of file nsTSubstring.h.

        {
          iter.mStart = mData;
          iter.mEnd = mData + mLength;
          iter.mPosition = iter.mEnd;
          return iter;
        }

Definition at line 110 of file nsTSubstring.h.

        {
          return iter = mData + mLength;
        }

Definition at line 121 of file nsTSubstring.h.

{ EnsureMutable(); return mData + mLength; }

Here is the call graph for this function:

iterator& nsTSubstring_CharT::EndWriting ( iterator iter) [inline, inherited]

Definition at line 136 of file nsTSubstring.h.

        {
          EnsureMutable();
          iter.mStart = mData;
          iter.mEnd = mData + mLength;
          iter.mPosition = iter.mEnd;
          return iter;
        }

Here is the call graph for this function:

Definition at line 151 of file nsTSubstring.h.

        {
          EnsureMutable();
          return iter = mData + mLength;
        }

Here is the call graph for this function:

void nsTSubstring_CharT::EnsureMutable ( ) [protected, inherited]

this helper function can be called prior to directly manipulating the contents of mData.

see, for example, BeginWriting.

Definition at line 273 of file nsTSubstring.cpp.

  {
    if (mFlags & (F_FIXED | F_OWNED))
      return;
    if ((mFlags & F_SHARED) && !nsStringBuffer::FromData(mData)->IsReadonly())
      return;

    // promote to a shared string buffer
    Assign(string_type(mData, mLength));
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::Equals ( const self_type str) const [inherited]

equality

Definition at line 570 of file nsTSubstring.cpp.

  {
    return mLength == str.mLength && char_traits::compare(mData, str.mData, mLength) == 0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::Equals ( const self_type str,
const comparator_type comp 
) const [inherited]

Definition at line 576 of file nsTSubstring.cpp.

  {
    return mLength == str.mLength && comp(mData, str.mData, mLength) == 0;
  }
PRBool nsTSubstring_CharT::Equals ( const char_type data) const [inherited]

Definition at line 602 of file nsTSubstring.cpp.

  {
    // unfortunately, some callers pass null :-(
    if (!data)
      {
        NS_NOTREACHED("null data pointer");
        return mLength == 0;
      }

    // XXX avoid length calculation?
    size_type length = char_traits::length(data);
    return mLength == length && char_traits::compare(mData, data, mLength) == 0;
  }

Here is the call graph for this function:

PRBool nsTSubstring_CharT::Equals ( const char_type data,
const comparator_type comp 
) const [inherited]

Definition at line 617 of file nsTSubstring.cpp.

  {
    // unfortunately, some callers pass null :-(
    if (!data)
      {
        NS_NOTREACHED("null data pointer");
        return mLength == 0;
      }

    // XXX avoid length calculation?
    size_type length = char_traits::length(data);
    return mLength == length && comp(mData, data, mLength) == 0;
  }
PRBool nsTSubstring_CharT::EqualsASCII ( const char *  data,
size_type  len 
) const [inherited]

An efficient comparison with ASCII that can be used even for wide strings.

Call this version when you know the length of 'data'.

Definition at line 632 of file nsTSubstring.cpp.

  {
    return mLength == len && char_traits::compareASCII(mData, data, len) == 0;
  }

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::EqualsASCII ( const char *  data) const [inherited]

An efficient comparison with ASCII that can be used even for wide strings.

Call this version when 'data' is null-terminated.

Definition at line 638 of file nsTSubstring.cpp.

  {
    return char_traits::compareASCIINullTerminated(mData, mLength, data) == 0;
  }
template<int N>
PRBool nsTSubstring_CharT::EqualsLiteral ( const char(&)  str[N]) const [inline, inherited]

Definition at line 256 of file nsTSubstring.h.

        {
          return EqualsASCII(str, N-1);
        }

Here is the call graph for this function:

template<int N>
PRBool nsTSubstring_CharT::EqualsLiteral ( char(&)  str[N]) const [inline, inherited]

Definition at line 261 of file nsTSubstring.h.

        {
          const char* s = str;
          return EqualsASCII(s, N-1);
        }

Here is the call graph for this function:

void nsTSubstring_CharT::Finalize ( void  ) [protected, inherited]

this function releases mData and does not change the value of any of its member variables.

inotherwords, this function acts like a destructor.

Definition at line 166 of file nsTSubstring.cpp.

  {
    ::ReleaseData(mData, mFlags);
    // mData, mLength, and mFlags are purposefully left dangling
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsTSubstring_CharT::FindChar ( char_type  c,
index_type  offset = 0 
) const [inherited]

Definition at line 665 of file nsTSubstring.cpp.

  {
    if (offset < mLength)
      {
        const char_type* result = char_traits::find(mData + offset, mLength - offset, c);
        if (result)
          return result - mData;
      }
    return -1;
  }
char_type nsTSubstring_CharT::First ( void  ) const [inline, inherited]

Definition at line 199 of file nsTSubstring.h.

        {
          NS_ASSERTION(mLength > 0, "|First()| called on an empty string");
          return mData[0];
        }

returns the null-terminated string

Reimplemented from nsTString_CharT.

Definition at line 602 of file nsTString.h.

        {
          return (mFlags & F_VOIDED) ? nsnull : mData;
        }
void nsTSubstring_CharT::Insert ( char_type  c,
index_type  pos 
) [inline, inherited]

Definition at line 387 of file nsTSubstring.h.

{ Replace(pos, 0, c); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::Insert ( const char_type data,
index_type  pos,
size_type  length = size_type(-1) 
) [inline, inherited]

Definition at line 388 of file nsTSubstring.h.

{ Replace(pos, 0, data, length); }

Here is the call graph for this function:

void nsTSubstring_CharT::Insert ( const self_type str,
index_type  pos 
) [inline, inherited]

Definition at line 389 of file nsTSubstring.h.

{ Replace(pos, 0, str); }

Here is the call graph for this function:

void nsTSubstring_CharT::Insert ( const substring_tuple_type tuple,
index_type  pos 
) [inline, inherited]

Definition at line 390 of file nsTSubstring.h.

{ Replace(pos, 0, tuple); }

Here is the call graph for this function:

PRBool nsTSubstring_CharT::IsDependentOn ( const char_type start,
const char_type end 
) const [inline, protected, inherited]

returns true if this string overlaps with the given string fragment.

if it isn't the case that one fragment starts after the other ends, or ends before the other starts, then, they conflict:

!(f2.begin >= f1.end || f2.end <= f1.begin)

Simplified, that gives us:

Definition at line 577 of file nsTSubstring.h.

        {
          return ( start < (mData + mLength) && end > mData );
        }

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::IsEmpty ( void  ) const [inline, inherited]

Definition at line 173 of file nsTSubstring.h.

        {
          return mLength == 0;
        }
PRBool nsTSubstring_CharT::IsTerminated ( ) const [inline, inherited]

Definition at line 183 of file nsTSubstring.h.

        {
          return mFlags & F_TERMINATED;
        }

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::IsVoid ( ) const [inline, inherited]

Definition at line 178 of file nsTSubstring.h.

        {
          return mFlags & F_VOIDED;
        }

Here is the caller graph for this function:

char_type nsTSubstring_CharT::Last ( void  ) const [inline, inherited]

Definition at line 206 of file nsTSubstring.h.

        {
          NS_ASSERTION(mLength > 0, "|Last()| called on an empty string");
          return mData[mLength - 1];
        }
size_type nsTSubstring_CharT::Length ( ) const [inline, inherited]

Definition at line 168 of file nsTSubstring.h.

        {
          return mLength;
        }

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::LowerCaseEqualsASCII ( const char *  data,
size_type  len 
) const [inherited]

Definition at line 644 of file nsTSubstring.cpp.

  {
    return mLength == len && char_traits::compareLowerCaseToASCII(mData, data, len) == 0;
  }

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::LowerCaseEqualsASCII ( const char *  data) const [inherited]

Definition at line 650 of file nsTSubstring.cpp.

  {
    return char_traits::compareLowerCaseToASCIINullTerminated(mData, mLength, data) == 0;
  }
template<int N>
PRBool nsTSubstring_CharT::LowerCaseEqualsLiteral ( const char(&)  str[N]) const [inline, inherited]

Definition at line 287 of file nsTSubstring.h.

        {
          return LowerCaseEqualsASCII(str, N-1);
        }

Here is the call graph for this function:

template<int N>
PRBool nsTSubstring_CharT::LowerCaseEqualsLiteral ( char(&)  str[N]) const [inline, inherited]

Definition at line 292 of file nsTSubstring.h.

        {
          const char* s = str;
          return LowerCaseEqualsASCII(s, N-1);
        }

Here is the call graph for this function:

PRBool nsTSubstring_CharT::MutatePrep ( size_type  capacity,
char_type **  oldData,
PRUint32 oldFlags 
) [protected, inherited]

this function prepares mData to be mutated.

this function is called to prepare mData for writing.

Parameters:
capacityspecifies the required capacity of mData
old_datareturns null or the old value of mData
old_flagsreturns 0 or the old value of mFlags

if mData is already mutable and of sufficient capacity, then this function will return immediately. otherwise, it will either resize mData or allocate a new shared buffer. if it needs to allocate a new buffer, then it will return the old buffer and the corresponding flags. this allows the caller to decide when to free the old data.

this function returns false if is unable to allocate sufficient memory.

XXX we should expose a way for subclasses to free old_data.

the given capacity indicates the required minimum storage size for mData, in sizeof(char_type) increments. this function returns true if the operation succeeds. it also returns the old data and old flags members if mData is newly allocated. the old data must be released by the caller.

Definition at line 58 of file nsTSubstring.cpp.

  {
    // initialize to no old data
    *oldData = nsnull;
    *oldFlags = 0;

    size_type curCapacity = Capacity();

    // If |capacity > size_type(-1)/2|, then our doubling algorithm may not be
    // able to allocate it.  Just bail out in cases like that.  We don't want
    // to be allocating 2GB+ strings anyway.
    if (capacity > size_type(-1)/2) {
      // Also assert for |capacity| equal to |size_type(-1)|, since we use that value to
      // flag immutability.
      NS_ASSERTION(capacity != size_type(-1), "Bogus capacity");
      return PR_FALSE;
    }

    // |curCapacity == size_type(-1)| means that the buffer is immutable, so we
    // need to allocate a new buffer.  we cannot use the existing buffer even
    // though it might be large enough.

    if (curCapacity != size_type(-1))
      {
        if (capacity <= curCapacity)
          return PR_TRUE;

        if (curCapacity > 0)
          {
            // use doubling algorithm when forced to increase available
            // capacity.
            PRUint32 temp = curCapacity;
            while (temp < capacity)
              temp <<= 1;
            capacity = temp;
          }
      }

    //
    // several cases:
    //
    //  (1) we have a shared buffer (mFlags & F_SHARED)
    //  (2) we have an owned buffer (mFlags & F_OWNED)
    //  (3) we have a fixed buffer (mFlags & F_FIXED)
    //  (4) we have a readonly buffer
    //
    // requiring that we in some cases preserve the data before creating
    // a new buffer complicates things just a bit ;-)
    //

    size_type storageSize = (capacity + 1) * sizeof(char_type);

    // case #1
    if (mFlags & F_SHARED)
      {
        nsStringBuffer* hdr = nsStringBuffer::FromData(mData);
        if (!hdr->IsReadonly())
          {
            nsStringBuffer *newHdr = nsStringBuffer::Realloc(hdr, storageSize);
            if (!newHdr)
              return PR_FALSE; // out-of-memory (original header left intact)

            hdr = newHdr;
            mData = (char_type*) hdr->Data();
            return PR_TRUE;
          }
      }

    char_type* newData;
    PRUint32 newDataFlags;

      // if we have a fixed buffer of sufficient size, then use it.  this helps
      // avoid heap allocations.
    if ((mFlags & F_CLASS_FIXED) && (capacity < AsFixedString(this)->mFixedCapacity))
      {
        newData = AsFixedString(this)->mFixedBuf;
        newDataFlags = F_TERMINATED | F_FIXED;
      }
    else
      {
        // if we reach here then, we must allocate a new buffer.  we cannot
        // make use of our F_OWNED or F_FIXED buffers because they are not
        // large enough.

        nsStringBuffer* newHdr = nsStringBuffer::Alloc(storageSize);
        if (!newHdr)
          return PR_FALSE; // we are still in a consistent state

        newData = (char_type*) newHdr->Data();
        newDataFlags = F_TERMINATED | F_SHARED;
      }

    // save old data and flags
    *oldData = mData;
    *oldFlags = mFlags;

    mData = newData;
    SetDataFlags(newDataFlags);

    // mLength does not change

    // though we are not necessarily terminated at the moment, now is probably
    // still the best time to set F_TERMINATED.

    return PR_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsTXPIDLString_CharT::operator const char_type * ( ) const [inline]

Definition at line 609 of file nsTString.h.

        {
          return get();
        }
self_type& nsTSubstring_CharT::operator+= ( char_type  c) [inline, inherited]

Definition at line 379 of file nsTSubstring.h.

{ Append(c);        return *this; }

Here is the call graph for this function:

self_type& nsTSubstring_CharT::operator+= ( const char_type data) [inline, inherited]

Definition at line 380 of file nsTSubstring.h.

{ Append(data);     return *this; }

Here is the call graph for this function:

self_type& nsTSubstring_CharT::operator+= ( const self_type str) [inline, inherited]

Definition at line 381 of file nsTSubstring.h.

{ Append(str);      return *this; }

Here is the call graph for this function:

self_type& nsTSubstring_CharT::operator+= ( const substring_tuple_type tuple) [inline, inherited]

Definition at line 382 of file nsTSubstring.h.

{ Append(tuple);    return *this; }

Here is the call graph for this function:

self_type& nsTXPIDLString_CharT::operator= ( char_type  c) [inline]

Reimplemented from nsTString_CharT.

Definition at line 621 of file nsTString.h.

{ Assign(c);        return *this; }

Here is the call graph for this function:

self_type& nsTXPIDLString_CharT::operator= ( const char_type data) [inline]

Reimplemented from nsTString_CharT.

Reimplemented in nsTAdoptingString_CharT.

Definition at line 622 of file nsTString.h.

{ Assign(data);     return *this; }

Here is the call graph for this function:

self_type& nsTXPIDLString_CharT::operator= ( const self_type str) [inline]

Reimplemented from nsTString_CharT.

Reimplemented in nsTAdoptingString_CharT.

Definition at line 623 of file nsTString.h.

{ Assign(str);      return *this; }

Here is the call graph for this function:

self_type& nsTXPIDLString_CharT::operator= ( const substring_type str) [inline]

Reimplemented from nsTString_CharT.

Reimplemented in nsTAdoptingString_CharT.

Definition at line 624 of file nsTString.h.

{ Assign(str);      return *this; }

Here is the call graph for this function:

self_type& nsTXPIDLString_CharT::operator= ( const substring_tuple_type tuple) [inline]

Reimplemented from nsTString_CharT.

Reimplemented in nsTAdoptingString_CharT.

Definition at line 625 of file nsTString.h.

{ Assign(tuple);    return *this; }

Here is the call graph for this function:

char_type nsTString_CharT::operator[] ( index_type  i) const [inline, inherited]

Reimplemented from nsTSubstring_CharT.

Definition at line 137 of file nsTString.h.

        {
          return CharAt(i);
        }

Here is the call graph for this function:

char_type nsTXPIDLString_CharT::operator[] ( PRInt32  i) const [inline]

Definition at line 615 of file nsTString.h.

        {
          return CharAt(index_type(i));
        }

Here is the call graph for this function:

void nsTSubstring_CharT::Replace ( index_type  cutStart,
size_type  cutLength,
char_type  c 
) [inline, inherited]

buffer manipulation

Definition at line 344 of file nsTSubstring.h.

{ Replace(cutStart, cutLength, &c, 1); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::Replace ( index_type  cutStart,
size_type  cutLength,
const char_type data,
size_type  length = size_type(-1) 
) [inherited]

Definition at line 425 of file nsTSubstring.cpp.

  {
      // unfortunately, some callers pass null :-(
    if (!data)
      {
        length = 0;
      }
    else
      {
        if (length == size_type(-1))
          length = char_traits::length(data);

        if (IsDependentOn(data, data + length))
          {
            nsTAutoString_CharT temp(data, length);
            Replace(cutStart, cutLength, temp);
            return;
          }
      }

    cutStart = PR_MIN(cutStart, Length());

    if (ReplacePrep(cutStart, cutLength, length) && length > 0)
      char_traits::copy(mData + cutStart, data, length);
  }

Here is the call graph for this function:

void nsTSubstring_CharT::Replace ( index_type  cutStart,
size_type  cutLength,
const self_type str 
) [inline, inherited]

Definition at line 346 of file nsTSubstring.h.

{ Replace(cutStart, cutLength, str.Data(), str.Length()); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::Replace ( index_type  cutStart,
size_type  cutLength,
const substring_tuple_type tuple 
) [inherited]

Definition at line 475 of file nsTSubstring.cpp.

  {
    if (tuple.IsDependentOn(mData, mData + mLength))
      {
        nsTAutoString_CharT temp(tuple);
        Replace(cutStart, cutLength, temp);
        return;
      }

    size_type length = tuple.Length();

    cutStart = PR_MIN(cutStart, Length());

    if (ReplacePrep(cutStart, cutLength, length) && length > 0)
      tuple.WriteTo(mData + cutStart, length);
  }

Here is the call graph for this function:

void nsTSubstring_CharT::ReplaceASCII ( index_type  cutStart,
size_type  cutLength,
const char *  data,
size_type  length = size_type(-1) 
) [inherited]

Definition at line 452 of file nsTSubstring.cpp.

  {
    if (length == size_type(-1))
      length = strlen(data);
    
    // A Unicode string can't depend on an ASCII string buffer,
    // so this dependence check only applies to CStrings.
#ifdef CharT_is_char
    if (IsDependentOn(data, data + length))
      {
        nsTAutoString_CharT temp(data, length);
        Replace(cutStart, cutLength, temp);
        return;
      }
#endif

    cutStart = PR_MIN(cutStart, Length());

    if (ReplacePrep(cutStart, cutLength, length) && length > 0)
      char_traits::copyASCII(mData + cutStart, data, length);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsTSubstring_CharT::ReplacePrep ( index_type  cutStart,
size_type  cutLength,
size_type  newLength 
) [protected, inherited]

this function prepares a section of mData to be modified.

if necessary, this function will reallocate mData and possibly move existing data to open up the specified section.

Parameters:
cutStartspecifies the starting offset of the section
cutLengthspecifies the length of the section to be replaced
newLengthspecifies the length of the new section

for example, suppose mData contains the string "abcdef" then

ReplacePrep(2, 3, 4);

would cause mData to look like "ab____f" where the characters indicated by '_' have an unspecified value and can be freely modified. this function will null-terminate mData upon return.

this function returns false if is unable to allocate sufficient memory.

Definition at line 180 of file nsTSubstring.cpp.

  {
    // bound cut length
    cutLen = NS_MIN(cutLen, mLength - cutStart);

    PRUint32 newLen = mLength - cutLen + fragLen;

    char_type* oldData;
    PRUint32 oldFlags;
    if (!MutatePrep(newLen, &oldData, &oldFlags))
      return PR_FALSE; // out-of-memory

    if (oldData)
      {
        // determine whether or not we need to copy part of the old string
        // over to the new string.

        if (cutStart > 0)
          {
            // copy prefix from old string
            char_traits::copy(mData, oldData, cutStart);
          }

        if (cutStart + cutLen < mLength)
          {
            // copy suffix from old string to new offset
            size_type from = cutStart + cutLen;
            size_type fromLen = mLength - from;
            PRUint32 to = cutStart + fragLen;
            char_traits::copy(mData + to, oldData + from, fromLen);
          }

        ::ReleaseData(oldData, oldFlags);
      }
    else
      {
        // original data remains intact

        // determine whether or not we need to move part of the existing string
        // to make room for the requested hole.
        if (fragLen != cutLen && cutStart + cutLen < mLength)
          {
            PRUint32 from = cutStart + cutLen;
            PRUint32 fromLen = mLength - from;
            PRUint32 to = cutStart + fragLen;
            char_traits::move(mData + to, mData + from, fromLen);
          }
      }

    // add null terminator (mutable mData always has room for the null-
    // terminator).
    mData[newLen] = char_type(0);
    mLength = newLen;

    return PR_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::SetCapacity ( size_type  capacity) [inherited]

buffer sizing

Definition at line 501 of file nsTSubstring.cpp.

  {
    // capacity does not include room for the terminating null char

    // if our capacity is reduced to zero, then free our buffer.
    if (capacity == 0)
      {
        ::ReleaseData(mData, mFlags);
        mData = NS_CONST_CAST(char_type*, char_traits::sEmptyBuffer);
        mLength = 0;
        SetDataFlags(F_TERMINATED);
      }
    else
      {
        char_type* oldData;
        PRUint32 oldFlags;
        if (!MutatePrep(capacity, &oldData, &oldFlags))
          return; // out-of-memory

        // compute new string length
        size_type newLen = NS_MIN(mLength, capacity);

        if (oldData)
          {
            // preserve old data
            if (mLength > 0)
              char_traits::copy(mData, oldData, newLen);

            ::ReleaseData(oldData, oldFlags);
          }

        // adjust mLength if our buffer shrunk down in size
        if (newLen < mLength)
          mLength = newLen;

        // always null-terminate here, even if the buffer got longer.  this is
        // for backwards compat with the old string implementation.
        mData[capacity] = char_type(0);
      }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::SetDataFlags ( PRUint32  dataFlags) [inline, protected, inherited]

this helper function stores the specified dataFlags in mFlags

Definition at line 593 of file nsTSubstring.h.

        {
          NS_ASSERTION((dataFlags & 0xFFFF0000) == 0, "bad flags");
          mFlags = dataFlags | (mFlags & 0xFFFF0000);
        }

Here is the caller graph for this function:

string data is never null, but can be marked void.

if true, the string will be truncated.

See also:
nsTSubstring::IsVoid

Definition at line 556 of file nsTSubstring.cpp.

  {
    if (val)
      {
        Truncate();
        mFlags |= F_VOIDED;
      }
    else
      {
        mFlags &= ~F_VOIDED;
      }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::SetLength ( size_type  length) [inherited]

Definition at line 543 of file nsTSubstring.cpp.

  {
    SetCapacity(length);

    // XXX(darin): SetCapacity may fail, but it doesn't give us a way to find
    // out.  We should improve that.  For now we just verify that the capacity
    // changed as expected as a means of error checking.
 
    if (Capacity() >= length)
      mLength = length;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsTSubstring_CharT::StripChar ( char_type  aChar,
PRInt32  aOffset = 0 
) [inherited]

This method is used to remove all occurances of aChar from this string.

Parameters:
aChar-- char to be stripped
aOffset-- where in this string to start stripping chars

Definition at line 677 of file nsTSubstring.cpp.

  {
    if (mLength == 0 || aOffset >= PRInt32(mLength))
      return;

    EnsureMutable(); // XXX do this lazily?

    // XXX(darin): this code should defer writing until necessary.

    char_type* to   = mData + aOffset;
    char_type* from = mData + aOffset;
    char_type* end  = mData + mLength;

    while (from < end)
      {
        char_type theChar = *from++;
        if (aChar != theChar)
          *to++ = theChar;
      }
    *to = char_type(0); // add the null
    mLength = to - mData;
  }

Here is the call graph for this function:

void nsTSubstring_CharT::Truncate ( size_type  newLength = 0) [inline, inherited]

Definition at line 406 of file nsTSubstring.h.

        {
          NS_ASSERTION(newLength <= mLength, "Truncate cannot make string longer");
          SetLength(newLength);
        }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsTAString_CharT [friend, inherited]

Definition at line 468 of file nsTSubstring.h.

friend class nsTObsoleteAStringThunk_CharT [friend, inherited]

Definition at line 467 of file nsTSubstring.h.

friend class nsTPromiseFlatString_CharT [friend, inherited]

Definition at line 472 of file nsTSubstring.h.

friend class nsTSubstringTuple_CharT [friend, inherited]

Definition at line 469 of file nsTSubstring.h.


Member Data Documentation

char_type* nsTSubstring_CharT::mData [protected, inherited]

Definition at line 475 of file nsTSubstring.h.

PRUint32 nsTSubstring_CharT::mFlags [protected, inherited]

Definition at line 477 of file nsTSubstring.h.

size_type nsTSubstring_CharT::mLength [protected, inherited]

Definition at line 476 of file nsTSubstring.h.


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