Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Protected Member Functions | Protected Attributes
nsSimpleCharString Class Reference

#include <nsFileSpec.h>

Collaboration diagram for nsSimpleCharString:
Collaboration graph
[legend]

List of all members.

Classes

struct  Data

Public Member Functions

 nsSimpleCharString ()
 nsSimpleCharString (const char *)
 nsSimpleCharString (const nsString &)
 nsSimpleCharString (const nsSimpleCharString &)
 nsSimpleCharString (const char *inData, PRUint32 inLength)
 ~nsSimpleCharString ()
void operator= (const char *)
void operator= (const nsString &)
void operator= (const nsSimpleCharString &)
 operator const char * () const
 operator char * ()
PRBool operator== (const char *)
PRBool operator== (const nsString &)
PRBool operator== (const nsSimpleCharString &)
void operator+= (const char *inString)
nsSimpleCharString operator+ (const char *inString) const
char operator[] (int i) const
char & operator[] (int i)
char & operator[] (unsigned int i)
void Catenate (const char *inString1, const char *inString2)
void SetToEmpty ()
PRBool IsEmpty () const
PRUint32 Length () const
void SetLength (PRUint32 inLength)
void CopyFrom (const char *inData, PRUint32 inLength)
void LeafReplace (char inSeparator, const char *inLeafName)
char * GetLeaf (char inSeparator) const
void Unescape ()
 nsSimpleCharString ()
 nsSimpleCharString (const char *)
 nsSimpleCharString (const nsString &)
 nsSimpleCharString (const nsSimpleCharString &)
 nsSimpleCharString (const char *inData, PRUint32 inLength)
 ~nsSimpleCharString ()
void operator= (const char *)
void operator= (const nsString &)
void operator= (const nsSimpleCharString &)
 operator const char * () const
 operator char * ()
PRBool operator== (const char *)
PRBool operator== (const nsString &)
PRBool operator== (const nsSimpleCharString &)
void operator+= (const char *inString)
nsSimpleCharString operator+ (const char *inString) const
char operator[] (int i) const
char & operator[] (int i)
char & operator[] (unsigned int i)
void Catenate (const char *inString1, const char *inString2)
void SetToEmpty ()
PRBool IsEmpty () const
PRUint32 Length () const
void SetLength (PRUint32 inLength)
void CopyFrom (const char *inData, PRUint32 inLength)
void LeafReplace (char inSeparator, const char *inLeafName)
char * GetLeaf (char inSeparator) const
void Unescape ()

Protected Member Functions

void AddRefData ()
void ReleaseData ()
void ReallocData (PRUint32 inLength)
void AddRefData ()
void ReleaseData ()
void ReallocData (PRUint32 inLength)

Protected Attributes

DatamData

Detailed Description

Definition at line 241 of file nsFileSpec.h.


Class Documentation

struct nsSimpleCharString::Data

Definition at line 305 of file nsFileSpec.h.

Collaboration diagram for nsSimpleCharString::Data:
Class Members
PRUint32 mLength
int mRefCount
char mString

Constructor & Destructor Documentation

Definition at line 88 of file nsFileSpec.cpp.

:   mData(nsnull)
{
    
} // nsSimpleCharString::nsSimpleCharString

Definition at line 96 of file nsFileSpec.cpp.

:   mData(nsnull)
{
    if (inString)
        CopyFrom(inString, strlen(inString));
} // nsSimpleCharString::nsSimpleCharString

Here is the call graph for this function:

Definition at line 105 of file nsFileSpec.cpp.

:   mData(nsnull)
{
    *this = inString;
} // nsSimpleCharString::nsSimpleCharString

Definition at line 113 of file nsFileSpec.cpp.

{
    mData = inOther.mData;
    AddRefData();
} // nsSimpleCharString::nsSimpleCharString

Here is the call graph for this function:

nsSimpleCharString::nsSimpleCharString ( const char *  inData,
PRUint32  inLength 
)

Definition at line 121 of file nsFileSpec.cpp.

:   mData(nsnull)
{
    CopyFrom(inData, inLength);
} // nsSimpleCharString::nsSimpleCharString

Here is the call graph for this function:

Definition at line 129 of file nsFileSpec.cpp.

{
    ReleaseData();
} // nsSimpleCharString::nsSimpleCharString

Here is the call graph for this function:

nsSimpleCharString::nsSimpleCharString ( const char *  inData,
PRUint32  inLength 
)

Member Function Documentation

Definition at line 239 of file nsFileSpec.cpp.

{
    if (mData)
        ++mData->mRefCount;
} // nsSimpleCharString::AddRefData

Here is the caller graph for this function:

void nsSimpleCharString::Catenate ( const char *  inString1,
const char *  inString2 
)

Definition at line 188 of file nsFileSpec.cpp.

{
    if (!inString2)
    {
        *this += inString1;
        return;
    }
    int newLength = Length() + strlen(inString1) + strlen(inString2);
    ReallocData(newLength);
    strcat(mData->mString, inString1);
    strcat(mData->mString, inString2);
} // nsSimpleCharString::operator =

Here is the call graph for this function:

void nsSimpleCharString::Catenate ( const char *  inString1,
const char *  inString2 
)
void nsSimpleCharString::CopyFrom ( const char *  inData,
PRUint32  inLength 
)

Definition at line 203 of file nsFileSpec.cpp.

{
    if (!inData)
        return;
    ReallocData(inLength);
    if (!mData)
        return;
    if (inLength != 0) {
        memcpy(mData->mString, inData, inLength);
    }
    mData->mString[inLength] = '\0';
} // nsSimpleCharString::CopyFrom

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSimpleCharString::CopyFrom ( const char *  inData,
PRUint32  inLength 
)
char * nsSimpleCharString::GetLeaf ( char  inSeparator) const

Definition at line 384 of file nsFileSpec.cpp.

{
    if (IsEmpty())
        return nsnull;

    char* chars = mData->mString;
    const char* lastSeparator = GetLastSeparator(chars, inSeparator);
    // If there was no separator, then return a copy of our path.
    if (!lastSeparator)
        return nsCRT::strdup(*this);

    // So there's at least one separator.  What's just after it?
    // If the separator was not the last character, return the trailing string.
    const char* leafPointer = lastSeparator + 1;
    if (*leafPointer)
        return nsCRT::strdup(leafPointer);

    // So now, separator was the last character. Poke in a null instead.
    *(char*)lastSeparator = '\0'; // Should use const_cast, but Unix has old compiler.
    leafPointer = GetLastSeparator(chars, inSeparator);
    char* result = leafPointer ? nsCRT::strdup(++leafPointer) : nsCRT::strdup(chars);
    // Restore the poked null before returning.
    *(char*)lastSeparator = inSeparator;
#if defined(XP_WIN) || defined(XP_OS2)
    // If it's a drive letter use the colon notation.
    if (!leafPointer && result[1] == '|' && result[2] == 0)
        result[1] = ':';
#endif
    return result;
} // nsSimpleCharString::GetLeaf

Here is the call graph for this function:

char* nsSimpleCharString::GetLeaf ( char  inSeparator) const
PRBool nsSimpleCharString::IsEmpty ( void  ) const [inline]

Definition at line 284 of file nsFileSpec.h.

{ return Length() == 0; }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsSimpleCharString::IsEmpty ( void  ) const [inline]

Definition at line 284 of file nsIFileSpec.idl.

void nsSimpleCharString::LeafReplace ( char  inSeparator,
const char *  inLeafName 
)

Definition at line 337 of file nsFileSpec.cpp.

{
    // Find the existing leaf name
    if (IsEmpty())
        return;
    if (!inLeafName)
    {
        SetToEmpty();
        return;
    }
    char* chars = mData->mString;
    char* lastSeparator = GetLastSeparator(chars, inSeparator);
    int oldLength = Length();
    PRBool trailingSeparator = (lastSeparator + 1 == chars + oldLength);
    if (trailingSeparator)
    {
        char savedCh = *lastSeparator;
        char *savedLastSeparator = lastSeparator;
        *lastSeparator = '\0';
        lastSeparator = GetLastSeparator(chars, inSeparator);
        *savedLastSeparator = savedCh;
    }
    if (lastSeparator)
        lastSeparator++; // point at the trailing string
    else
        lastSeparator = chars; // the full monty

    PRUint32 savedLastSeparatorOffset = (lastSeparator - chars);
    int newLength =
        (lastSeparator - chars) + strlen(inLeafName) + (trailingSeparator != 0);
    ReallocData(newLength);

    chars = mData->mString; // it might have moved.
    chars[savedLastSeparatorOffset] = '\0'; // strip the current leaf name

    strcat(chars, inLeafName);
    if (trailingSeparator)
    {
        // If the original ended in a slash, then the new one should, too.
        char sepStr[2] = "/";
        *sepStr = inSeparator;
        strcat(chars, sepStr);
    }
} // nsSimpleCharString::LeafReplace

Here is the call graph for this function:

void nsSimpleCharString::LeafReplace ( char  inSeparator,
const char *  inLeafName 
)

Definition at line 286 of file nsFileSpec.h.

{ return mData ? mData->mLength : 0; }

Here is the caller graph for this function:

Definition at line 286 of file nsIFileSpec.idl.

nsSimpleCharString::operator char * ( ) [inline]

Definition at line 260 of file nsFileSpec.h.

                                 {
                                     ReallocData(Length()); // requires detaching if shared...
                                     return mData ? mData->mString : 0;
                                 }

Here is the call graph for this function:

nsSimpleCharString::operator char * ( ) [inline]

Definition at line 260 of file nsIFileSpec.idl.

nsSimpleCharString::operator const char * ( ) const [inline]

Definition at line 259 of file nsFileSpec.h.

{ return mData ? mData->mString : 0; }
nsSimpleCharString::operator const char * ( ) const [inline]

Definition at line 259 of file nsIFileSpec.idl.

nsSimpleCharString nsSimpleCharString::operator+ ( const char *  inString) const
nsSimpleCharString nsSimpleCharString::operator+ ( const char *  inString) const

Definition at line 179 of file nsFileSpec.cpp.

{
    nsSimpleCharString result(*this);
    result += inOther;
    return result;
} // nsSimpleCharString::operator =
void nsSimpleCharString::operator+= ( const char *  inString)
void nsSimpleCharString::operator+= ( const char *  inString)

Definition at line 168 of file nsFileSpec.cpp.

{
    if (!inOther)
        return;
    int newLength = Length() + strlen(inOther);
    ReallocData(newLength);
    strcat(mData->mString, inOther);
} // nsSimpleCharString::operator =

Here is the call graph for this function:

void nsSimpleCharString::operator= ( const char *  inString)

Definition at line 136 of file nsFileSpec.cpp.

{
    if (inString)
        CopyFrom(inString, strlen(inString));
    else
        SetToEmpty();
} // nsSimpleCharString::operator =

Here is the call graph for this function:

void nsSimpleCharString::operator= ( const char *  )
void nsSimpleCharString::operator= ( const nsString inString)

Definition at line 146 of file nsFileSpec.cpp.

{
    PRUint32 len = inString.Length();
    ReallocData(len);
    if (!mData)
        return;
    inString.ToCString(mData->mString, len + 1);  
} // nsSimpleCharString::operator =

Here is the call graph for this function:

void nsSimpleCharString::operator= ( const nsString )
void nsSimpleCharString::operator= ( const nsSimpleCharString inOther)

Definition at line 157 of file nsFileSpec.cpp.

{
    if (mData == inOther.mData)
        return;
    ReleaseData();
    mData = inOther.mData;
    AddRefData();
} // nsSimpleCharString::operator =

Here is the call graph for this function:

void nsSimpleCharString::operator= ( const nsSimpleCharString )
PRBool nsSimpleCharString::operator== ( const char *  )
PRBool nsSimpleCharString::operator== ( const char *  )
PRBool nsSimpleCharString::operator== ( const nsString )
PRBool nsSimpleCharString::operator== ( const nsString )
PRBool nsSimpleCharString::operator== ( const nsSimpleCharString )
PRBool nsSimpleCharString::operator== ( const nsSimpleCharString )
char nsSimpleCharString::operator[] ( int  i) const [inline]

Definition at line 272 of file nsIFileSpec.idl.

char nsSimpleCharString::operator[] ( int  i) const [inline]

Definition at line 272 of file nsFileSpec.h.

{ return mData ? mData->mString[i] : '\0'; }
char& nsSimpleCharString::operator[] ( int  i) [inline]

Definition at line 273 of file nsIFileSpec.idl.

char& nsSimpleCharString::operator[] ( int  i) [inline]

Definition at line 273 of file nsFileSpec.h.

                                 {
                                     if (i >= (int)Length())
                                         ReallocData((PRUint32)i + 1);
                                     return mData->mString[i]; // caveat appelator
                                 }

Here is the call graph for this function:

char& nsSimpleCharString::operator[] ( unsigned int  i) [inline]

Definition at line 279 of file nsIFileSpec.idl.

char& nsSimpleCharString::operator[] ( unsigned int  i) [inline]

Definition at line 279 of file nsFileSpec.h.

{ return (*this)[(int)i]; }
void nsSimpleCharString::ReallocData ( PRUint32  inLength) [protected]

Definition at line 267 of file nsFileSpec.cpp.

{
    PRUint32 newAllocLength = CalculateAllocLength(inLength);
    PRUint32 oldAllocLength = CalculateAllocLength(Length());
    if (mData)
    {
        NS_ASSERTION(mData->mRefCount > 0, "String deleted too many times!");
        if (mData->mRefCount == 1)
        {
            // We are the sole owner, so just change its length, if necessary.
            if (newAllocLength > oldAllocLength)
                mData = (Data*)PR_Realloc(mData, newAllocLength + sizeof(Data));
            mData->mLength = inLength;
            mData->mString[inLength] = '\0'; // we may be truncating
            return;
        }
    }
    PRUint32 copyLength = Length();
    if (inLength < copyLength)
        copyLength = inLength;
    Data* newData = (Data*)PR_Malloc(newAllocLength + sizeof(Data));
    // If data was already allocated when we get to here, then we are cloning the data
    // from a shared pointer.
    if (mData)
    {
        memcpy(newData, mData, sizeof(Data) + copyLength);
        mData->mRefCount--; // Say goodbye
    }
    else
        newData->mString[0] = '\0';

    mData = newData;
    mData->mRefCount = 1;
    mData->mLength = inLength;
} // nsSimpleCharString::ReleaseData

Here is the call graph for this function:

Here is the caller graph for this function:

void nsSimpleCharString::ReallocData ( PRUint32  inLength) [protected]

Definition at line 247 of file nsFileSpec.cpp.

{
    if (!mData)
        return;
    NS_ASSERTION(mData->mRefCount > 0, "String deleted too many times!");
    if (--mData->mRefCount == 0)
        PR_Free(mData);
    mData = nsnull;
} // nsSimpleCharString::ReleaseData

Here is the caller graph for this function:

Definition at line 287 of file nsFileSpec.h.

{ ReallocData(inLength); }

Here is the call graph for this function:

Definition at line 287 of file nsIFileSpec.idl.

Definition at line 218 of file nsFileSpec.cpp.

{
    ReleaseData();
} // nsSimpleCharString::SetToEmpty

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 225 of file nsFileSpec.cpp.

{
    if (!mData)
        return;
    ReallocData(mData->mLength);
    if (!mData)
        return;
    nsUnescape(mData->mString);
    mData->mLength = strlen(mData->mString);       
} // nsSimpleCharString::Unescape

Here is the call graph for this function:


Member Data Documentation

Definition at line 310 of file nsFileSpec.h.


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