Back to index

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

nsScannerString provides methods to grow and modify a buffer list. More...

#include <nsScannerString.h>

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

List of all members.

Public Types

typedef nsScannerBufferList::Buffer Buffer
typedef
nsScannerBufferList::Position 
Position
typedef PRUint32 size_type

Public Member Functions

 nsScannerString (Buffer *)
 nsScannerString
void AppendBuffer (Buffer *)
void DiscardPrefix (const nsScannerIterator &)
void UngetReadable (const nsAString &aReadable, const nsScannerIterator &aCurrentPosition)
void ReplaceCharacter (nsScannerIterator &aPosition, PRUnichar aChar)
nsScannerIteratorBeginReading (nsScannerIterator &iter) const
nsScannerIteratorEndReading (nsScannerIterator &iter) const
size_type Length () const
PRInt32 CountChar (PRUnichar) const
void Rebind (const nsScannerSubstring &, const nsScannerIterator &, const nsScannerIterator &)
void Rebind (const nsAString &)
const nsSubstringAsString () const
PRBool GetNextFragment (nsScannerFragment &) const
PRBool GetPrevFragment (nsScannerFragment &) const

Static Public Member Functions

static BufferAllocBufferFromString (const nsAString &aStr)
static BufferAllocBuffer (size_type aCapacity)

Protected Member Functions

void acquire_ownership_of_buffer_list () const
void release_ownership_of_buffer_list ()
void init_range_from_buffer_list ()

Protected Attributes

Position mStart
Position mEnd
nsScannerBufferListmBufferList
size_type mLength
nsDependentSubstring mFlattenedRep
PRBool mIsDirty

Friends

class nsScannerSharedSubstring

Detailed Description

nsScannerString provides methods to grow and modify a buffer list.

Definition at line 286 of file nsScannerString.h.


Member Typedef Documentation

Definition at line 214 of file nsScannerString.h.

Definition at line 215 of file nsScannerString.h.

Definition at line 216 of file nsScannerString.h.


Constructor & Destructor Documentation

nsScannerString

Definition at line 344 of file nsScannerString.cpp.

Here is the call graph for this function:


Member Function Documentation

void nsScannerSubstring::acquire_ownership_of_buffer_list ( ) const [inline, protected, inherited]

Definition at line 243 of file nsScannerString.h.

Here is the call graph for this function:

Here is the caller graph for this function:

static Buffer* nsScannerSubstring::AllocBuffer ( size_type  aCapacity) [inline, static, inherited]

Definition at line 239 of file nsScannerString.h.

{ return nsScannerBufferList::AllocBuffer(aCapacity); }

Here is the caller graph for this function:

static Buffer* nsScannerSubstring::AllocBufferFromString ( const nsAString &  aStr) [inline, static, inherited]

Definition at line 238 of file nsScannerString.h.

Here is the caller graph for this function:

Definition at line 353 of file nsScannerString.cpp.

  {
    mBufferList->Append(aBuf);
    mLength += aBuf->DataLength();

    mEnd.mBuffer = aBuf;
    mEnd.mPosition = aBuf->DataEnd();

    mIsDirty = PR_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 239 of file nsScannerString.cpp.

  {
    if (mIsDirty)
      {
        nsScannerSubstring* mutable_this = NS_CONST_CAST(nsScannerSubstring*, this);

        if (mStart.mBuffer == mEnd.mBuffer) {
          // We only have a single fragment to deal with, so just return it
          // as a substring.
          mutable_this->mFlattenedRep.Rebind(mStart.mPosition, mEnd.mPosition);
        } else {
          // Otherwise, we need to copy the data into a flattened buffer.
          nsScannerIterator start, end;
          CopyUnicodeTo(BeginReading(start), EndReading(end), mutable_this->mFlattenedRep);
        }

        mutable_this->mIsDirty = PR_FALSE;
      }

    return mFlattenedRep;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 262 of file nsScannerString.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 186 of file nsScannerString.cpp.

  {
      /*
        re-write this to use a counting sink
       */

    size_type result = 0;
    size_type lengthToExamine = Length();

    nsScannerIterator iter;
    for ( BeginReading(iter); ; )
      {
        PRInt32 lengthToExamineInThisFragment = iter.size_forward();
        const PRUnichar* fromBegin = iter.get();
        result += size_type(NS_COUNT(fromBegin, fromBegin+lengthToExamineInThisFragment, c));
        if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
          return result;
        iter.advance(lengthToExamineInThisFragment);
      }
      // never reached; quiets warnings
    return 0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 365 of file nsScannerString.cpp.

  {
    Position old_start(mStart);
    mStart = aIter;
    mLength -= Position::Distance(old_start, mStart);
    
    mStart.mBuffer->IncrementUsageCount();
    old_start.mBuffer->DecrementUsageCount();

    mBufferList->DiscardUnreferencedPrefix(old_start.mBuffer);

    mIsDirty = PR_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 279 of file nsScannerString.cpp.

  {
    iter.mOwner = this;

    iter.mFragment.mBuffer = mEnd.mBuffer;
    iter.mFragment.mFragmentEnd = mEnd.mPosition;
    if (mStart.mBuffer == mEnd.mBuffer)
      iter.mFragment.mFragmentStart = mStart.mPosition;
    else
      iter.mFragment.mFragmentStart = mEnd.mBuffer->DataStart();

    iter.mPosition = mEnd.mPosition;
    // must not |normalize_backward| as that would likely invalidate tests like |while ( first != last )|
    return iter;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 296 of file nsScannerString.cpp.

  {
    // check to see if we are at the end of the buffer list
    if (frag.mBuffer == mEnd.mBuffer)
      return PR_FALSE;

    frag.mBuffer = NS_STATIC_CAST(const Buffer*, PR_NEXT_LINK(frag.mBuffer));

    if (frag.mBuffer == mStart.mBuffer)
      frag.mFragmentStart = mStart.mPosition;
    else
      frag.mFragmentStart = frag.mBuffer->DataStart();

    if (frag.mBuffer == mEnd.mBuffer)
      frag.mFragmentEnd = mEnd.mPosition;
    else
      frag.mFragmentEnd = frag.mBuffer->DataEnd();

    return PR_TRUE;
  }

Here is the call graph for this function:

Definition at line 318 of file nsScannerString.cpp.

  {
    // check to see if we are at the beginning of the buffer list
    if (frag.mBuffer == mStart.mBuffer)
      return PR_FALSE;

    frag.mBuffer = NS_STATIC_CAST(const Buffer*, PR_PREV_LINK(frag.mBuffer));

    if (frag.mBuffer == mStart.mBuffer)
      frag.mFragmentStart = mStart.mPosition;
    else
      frag.mFragmentStart = frag.mBuffer->DataStart();

    if (frag.mBuffer == mEnd.mBuffer)
      frag.mFragmentEnd = mEnd.mPosition;
    else
      frag.mFragmentEnd = frag.mBuffer->DataEnd();

    return PR_TRUE;
  }

Here is the call graph for this function:

void nsScannerSubstring::init_range_from_buffer_list ( ) [inline, protected, inherited]

Definition at line 259 of file nsScannerString.h.

Here is the call graph for this function:

Here is the caller graph for this function:

size_type nsScannerSubstring::Length ( ) const [inline, inherited]

Definition at line 226 of file nsScannerString.h.

{ return mLength; }

Here is the caller graph for this function:

Definition at line 210 of file nsScannerString.cpp.

  {
    // allow for the case where &aString == this

    aString.acquire_ownership_of_buffer_list();
    release_ownership_of_buffer_list();

    mStart      = aStart;
    mEnd        = aEnd;
    mBufferList = aString.mBufferList;
    mLength     = Distance(aStart, aEnd);
    mIsDirty    = PR_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsScannerSubstring::Rebind ( const nsAString &  aString) [inherited]
void nsScannerSubstring::release_ownership_of_buffer_list ( ) [inline, protected, inherited]

Definition at line 249 of file nsScannerString.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 412 of file nsScannerString.cpp.

  {
    // XXX Casting a const to non-const. Unless the base class
    // provides support for writing iterators, this is the best
    // that can be done.
    PRUnichar* pos = NS_CONST_CAST(PRUnichar*, aPosition.get());
    *pos = aChar;

    mIsDirty = PR_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsScannerString::UngetReadable ( const nsAString &  aReadable,
const nsScannerIterator aCurrentPosition 
)

Definition at line 380 of file nsScannerString.cpp.

  {
    Position insertPos(aInsertPoint);

    mBufferList->SplitBuffer(insertPos);
      // splitting to the right keeps the work string and any extant token pointing to and
      //  holding a reference count on the same buffer

    Buffer* new_buffer = AllocBufferFromString(aReadable);
      // make a new buffer with all the data to insert...
      //  BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
      //  of this and decide if we should do the work to fill it

    Buffer* buffer_to_split = insertPos.mBuffer;
    mBufferList->InsertAfter(new_buffer, buffer_to_split);
    mLength += aReadable.Length();

    mEnd.mBuffer = mBufferList->Tail();
    mEnd.mPosition = mEnd.mBuffer->DataEnd();

    mIsDirty = PR_TRUE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsScannerSharedSubstring [friend, inherited]

Definition at line 279 of file nsScannerString.h.


Member Data Documentation

Definition at line 272 of file nsScannerString.h.

Position nsScannerSubstring::mEnd [protected, inherited]

Definition at line 271 of file nsScannerString.h.

Definition at line 276 of file nsScannerString.h.

PRBool nsScannerSubstring::mIsDirty [protected, inherited]

Definition at line 277 of file nsScannerString.h.

size_type nsScannerSubstring::mLength [protected, inherited]

Definition at line 273 of file nsScannerString.h.

Position nsScannerSubstring::mStart [protected, inherited]

Definition at line 270 of file nsScannerString.h.


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