1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-14 00:24:54 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsCRT.h"
|
1998-06-06 01:38:36 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
1999-01-23 09:58:34 +03:00
|
|
|
#include "nsString.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-12-02 01:44:42 +03:00
|
|
|
static const PRInt32 kGrowArrayBy = 8;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-12-01 03:37:11 +03:00
|
|
|
const PRInt32 nsVoidArray::kArrayOwnerMask = 1 << 31;
|
|
|
|
const PRInt32 nsVoidArray::kArraySizeMask = ~nsVoidArray::kArrayOwnerMask;
|
|
|
|
|
|
|
|
inline PRInt32
|
|
|
|
nsVoidArray::GetArraySize() const
|
|
|
|
{
|
|
|
|
return mInfo & kArraySizeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
nsVoidArray::SetArraySize(PRInt32 aSize)
|
|
|
|
{
|
|
|
|
mInfo &= kArrayOwnerMask; // preserve ownership bit
|
|
|
|
mInfo |= (aSize & kArraySizeMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
nsVoidArray::IsArrayOwner() const
|
|
|
|
{
|
|
|
|
return (mInfo & kArrayOwnerMask) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void
|
|
|
|
nsVoidArray::SetArrayOwner(PRBool aOwner)
|
|
|
|
{
|
|
|
|
mInfo &= kArraySizeMask; // preserve array size
|
|
|
|
mInfo |= (aOwner ? kArrayOwnerMask : 0);
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsVoidArray::nsVoidArray()
|
1999-12-01 03:37:11 +03:00
|
|
|
: mArray(nsnull),
|
|
|
|
mInfo(0),
|
|
|
|
mCount(0)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-12-01 03:37:11 +03:00
|
|
|
MOZ_COUNT_CTOR(nsVoidArray);
|
|
|
|
SetArrayOwner(PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-06-12 02:48:25 +04:00
|
|
|
nsVoidArray::nsVoidArray(PRInt32 aCount)
|
2000-01-19 04:18:27 +03:00
|
|
|
: mArray(nsnull),
|
|
|
|
mInfo(0),
|
|
|
|
mCount(0)
|
1998-06-12 02:48:25 +04:00
|
|
|
{
|
1999-12-01 03:37:11 +03:00
|
|
|
MOZ_COUNT_CTOR(nsVoidArray);
|
2000-01-19 04:18:27 +03:00
|
|
|
if ( aCount )
|
|
|
|
{
|
|
|
|
SetArraySize(aCount);
|
|
|
|
mCount = aCount;
|
|
|
|
mArray = new void*[GetArraySize()];
|
|
|
|
nsCRT::memset(mArray, 0, mCount * sizeof(void*));
|
|
|
|
}
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArrayOwner(PR_TRUE);
|
1998-06-12 02:48:25 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsVoidArray& nsVoidArray::operator=(const nsVoidArray& other)
|
|
|
|
{
|
1999-12-01 03:37:11 +03:00
|
|
|
if (IsArrayOwner()) {
|
1999-05-27 01:13:29 +04:00
|
|
|
delete [] mArray;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
PRInt32 otherCount = other.mCount;
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArraySize(otherCount);
|
1998-04-14 00:24:54 +04:00
|
|
|
mCount = otherCount;
|
|
|
|
if (otherCount != 0) {
|
1999-12-01 03:37:11 +03:00
|
|
|
mArray = new void*[GetArraySize()];
|
1998-04-14 00:24:54 +04:00
|
|
|
nsCRT::memcpy(mArray, other.mArray, otherCount * sizeof(void*));
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArrayOwner(PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
|
|
|
mArray = nsnull;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsVoidArray::~nsVoidArray()
|
|
|
|
{
|
1999-12-01 03:37:11 +03:00
|
|
|
MOZ_COUNT_DTOR(nsVoidArray);
|
|
|
|
if (IsArrayOwner()) {
|
1998-06-06 01:38:36 +04:00
|
|
|
delete [] mArray;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-08-31 07:04:37 +04:00
|
|
|
|
1998-06-06 01:38:36 +04:00
|
|
|
void
|
1999-08-31 07:04:37 +04:00
|
|
|
nsVoidArray::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
1998-06-06 01:38:36 +04:00
|
|
|
{
|
1999-08-31 07:04:37 +04:00
|
|
|
if (aResult) {
|
1999-12-01 03:37:11 +03:00
|
|
|
*aResult = sizeof(*this) + sizeof(void*) * GetArraySize();
|
1999-08-31 07:04:37 +04:00
|
|
|
}
|
1998-06-06 01:38:36 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
void* nsVoidArray::ElementAt(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
if (PRUint32(aIndex) >= PRUint32(mCount)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return mArray[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsVoidArray::IndexOf(void* aPossibleElement) const
|
|
|
|
{
|
|
|
|
void** ap = mArray;
|
|
|
|
void** end = ap + mCount;
|
|
|
|
while (ap < end) {
|
|
|
|
if (*ap == aPossibleElement) {
|
|
|
|
return ap - mArray;
|
|
|
|
}
|
|
|
|
ap++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsVoidArray::InsertElementAt(void* aElement, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
PRInt32 oldCount = mCount;
|
|
|
|
if (PRUint32(aIndex) > PRUint32(oldCount)) {
|
|
|
|
// An invalid index causes the insertion to fail
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-12-01 03:37:11 +03:00
|
|
|
if (oldCount >= GetArraySize()) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// We have to grow the array
|
|
|
|
PRInt32 newCount = oldCount + kGrowArrayBy;
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArraySize(newCount);
|
|
|
|
void** newArray = new void*[GetArraySize()];
|
1998-06-06 01:38:36 +04:00
|
|
|
if (mArray != nsnull && aIndex != 0)
|
|
|
|
nsCRT::memcpy(newArray, mArray, aIndex * sizeof(void*));
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 slide = oldCount - aIndex;
|
|
|
|
if (0 != slide) {
|
|
|
|
// Slide data over to make room for the insertion
|
|
|
|
nsCRT::memcpy(newArray + aIndex + 1, mArray + aIndex,
|
|
|
|
slide * sizeof(void*));
|
|
|
|
}
|
1999-12-01 03:37:11 +03:00
|
|
|
if (IsArrayOwner())
|
1998-06-06 01:38:36 +04:00
|
|
|
delete [] mArray;
|
1998-04-14 00:24:54 +04:00
|
|
|
mArray = newArray;
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArrayOwner(PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
|
|
|
// The array is already large enough
|
|
|
|
PRInt32 slide = oldCount - aIndex;
|
|
|
|
if (0 != slide) {
|
|
|
|
// Slide data over to make room for the insertion
|
|
|
|
nsCRT::memmove(mArray + aIndex + 1, mArray + aIndex,
|
|
|
|
slide * sizeof(void*));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mArray[aIndex] = aElement;
|
|
|
|
mCount++;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsVoidArray::ReplaceElementAt(void* aElement, PRInt32 aIndex)
|
|
|
|
{
|
1999-12-01 03:37:11 +03:00
|
|
|
if (PRUint32(aIndex) >= PRUint32(GetArraySize())) {
|
1998-07-02 04:28:56 +04:00
|
|
|
|
|
|
|
PRInt32 requestedCount = aIndex + 1;
|
|
|
|
PRInt32 growDelta = requestedCount - mCount;
|
|
|
|
PRInt32 newCount = mCount + (growDelta > kGrowArrayBy ? growDelta : kGrowArrayBy);
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArraySize(newCount);
|
|
|
|
void** newArray = new void*[GetArraySize()];
|
1998-07-02 04:28:56 +04:00
|
|
|
if (newArray==nsnull)
|
|
|
|
return PR_FALSE;
|
1999-12-01 03:37:11 +03:00
|
|
|
nsCRT::memset(newArray, 0, newCount * sizeof(void*));
|
1998-07-02 04:28:56 +04:00
|
|
|
if (mArray != nsnull && aIndex != 0) {
|
|
|
|
nsCRT::memcpy(newArray, mArray, mCount * sizeof(void*));
|
1999-12-01 03:37:11 +03:00
|
|
|
if (IsArrayOwner())
|
1998-07-02 04:28:56 +04:00
|
|
|
delete [] mArray;
|
|
|
|
}
|
|
|
|
mArray = newArray;
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArrayOwner(PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
mArray[aIndex] = aElement;
|
1998-07-02 04:28:56 +04:00
|
|
|
if (aIndex >= mCount)
|
|
|
|
mCount = aIndex+1;
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsVoidArray::RemoveElementAt(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
PRInt32 oldCount = mCount;
|
|
|
|
if (PRUint32(aIndex) >= PRUint32(oldCount)) {
|
|
|
|
// An invalid index causes the replace to fail
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't need to move any elements if we're removing the
|
|
|
|
// last element in the array
|
|
|
|
if (aIndex < (oldCount - 1)) {
|
|
|
|
nsCRT::memmove(mArray + aIndex, mArray + aIndex + 1,
|
|
|
|
(oldCount - 1 - aIndex) * sizeof(void*));
|
|
|
|
}
|
|
|
|
|
|
|
|
mCount--;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsVoidArray::RemoveElement(void* aElement)
|
|
|
|
{
|
|
|
|
void** ep = mArray;
|
|
|
|
void** end = ep + mCount;
|
|
|
|
while (ep < end) {
|
|
|
|
void* e = *ep++;
|
|
|
|
if (e == aElement) {
|
|
|
|
ep--;
|
|
|
|
return RemoveElementAt(PRInt32(ep - mArray));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsVoidArray::Clear()
|
|
|
|
{
|
|
|
|
mCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsVoidArray::Compact()
|
|
|
|
{
|
|
|
|
PRInt32 count = mCount;
|
1999-12-01 03:37:11 +03:00
|
|
|
if (IsArrayOwner() && (GetArraySize() > count)) {
|
|
|
|
SetArraySize(count);
|
|
|
|
void** newArray = new void*[GetArraySize()];
|
1998-06-06 01:38:36 +04:00
|
|
|
if (nsnull != newArray) {
|
|
|
|
nsCRT::memcpy(newArray, mArray, count * sizeof(void*));
|
|
|
|
delete [] mArray;
|
|
|
|
mArray = newArray;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1998-05-21 00:31:58 +04:00
|
|
|
|
|
|
|
PRBool nsVoidArray::EnumerateForwards(nsVoidArrayEnumFunc aFunc, void* aData)
|
|
|
|
{
|
|
|
|
PRInt32 index = -1;
|
|
|
|
PRBool running = PR_TRUE;
|
|
|
|
|
|
|
|
while (running && (++index < mCount)) {
|
|
|
|
running = (*aFunc)(mArray[index], aData);
|
|
|
|
}
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsVoidArray::EnumerateBackwards(nsVoidArrayEnumFunc aFunc, void* aData)
|
|
|
|
{
|
|
|
|
PRInt32 index = mCount;
|
|
|
|
PRBool running = PR_TRUE;
|
|
|
|
|
|
|
|
while (running && (0 <= --index)) {
|
|
|
|
running = (*aFunc)(mArray[index], aData);
|
|
|
|
}
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
1999-12-01 03:37:11 +03:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
// nsAutoVoidArray
|
|
|
|
|
|
|
|
nsAutoVoidArray::nsAutoVoidArray()
|
|
|
|
: nsVoidArray()
|
|
|
|
{
|
|
|
|
mArray = mElements;
|
|
|
|
SetArraySize(sizeof(mElements) / sizeof(*mElements));
|
|
|
|
SetArrayOwner(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
1999-01-23 09:58:34 +03:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
// nsStringArray
|
|
|
|
|
|
|
|
nsStringArray::nsStringArray(void)
|
|
|
|
: nsVoidArray()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStringArray::~nsStringArray(void)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStringArray&
|
|
|
|
nsStringArray::operator=(const nsStringArray& other)
|
|
|
|
{
|
1999-12-01 03:37:11 +03:00
|
|
|
if (IsArrayOwner()) {
|
1999-01-23 09:58:34 +03:00
|
|
|
delete mArray;
|
|
|
|
}
|
|
|
|
PRInt32 otherCount = other.mCount;
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArraySize(otherCount);
|
1999-01-23 09:58:34 +03:00
|
|
|
mCount = otherCount;
|
|
|
|
if (0 < otherCount) {
|
1999-12-01 03:37:11 +03:00
|
|
|
mArray = new void*[GetArraySize()];
|
1999-01-23 09:58:34 +03:00
|
|
|
while (0 <= --otherCount) {
|
|
|
|
nsString* otherString = (nsString*)(other.mArray[otherCount]);
|
|
|
|
mArray[otherCount] = new nsString(*otherString);
|
|
|
|
}
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArrayOwner(PR_TRUE);
|
1999-01-23 09:58:34 +03:00
|
|
|
} else {
|
|
|
|
mArray = nsnull;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-31 07:04:37 +04:00
|
|
|
nsStringArray::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
1999-01-23 09:58:34 +03:00
|
|
|
{
|
1999-08-31 07:04:37 +04:00
|
|
|
PRUint32 sum = 0;
|
|
|
|
nsVoidArray::SizeOf(aHandler, &sum);
|
1999-01-23 09:58:34 +03:00
|
|
|
PRInt32 index = mCount;
|
|
|
|
while (0 <= --index) {
|
|
|
|
nsString* string = (nsString*)mArray[index];
|
1999-08-31 07:04:37 +04:00
|
|
|
PRUint32 size;
|
|
|
|
string->SizeOf(aHandler, &size);
|
|
|
|
sum += size;
|
1999-01-23 09:58:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStringArray::StringAt(PRInt32 aIndex, nsString& aString) const
|
|
|
|
{
|
|
|
|
nsString* string = (nsString*)nsVoidArray::ElementAt(aIndex);
|
|
|
|
if (nsnull != string) {
|
|
|
|
aString = *string;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aString.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString*
|
|
|
|
nsStringArray::StringAt(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
return (nsString*)nsVoidArray::ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsStringArray::IndexOf(const nsString& aPossibleString) const
|
|
|
|
{
|
|
|
|
void** ap = mArray;
|
|
|
|
void** end = ap + mCount;
|
|
|
|
while (ap < end) {
|
|
|
|
nsString* string = (nsString*)*ap;
|
|
|
|
if (string->Equals(aPossibleString)) {
|
|
|
|
return ap - mArray;
|
|
|
|
}
|
|
|
|
ap++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsStringArray::IndexOfIgnoreCase(const nsString& aPossibleString) const
|
|
|
|
{
|
|
|
|
void** ap = mArray;
|
|
|
|
void** end = ap + mCount;
|
|
|
|
while (ap < end) {
|
|
|
|
nsString* string = (nsString*)*ap;
|
|
|
|
if (string->EqualsIgnoreCase(aPossibleString)) {
|
|
|
|
return ap - mArray;
|
|
|
|
}
|
|
|
|
ap++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsStringArray::InsertStringAt(const nsString& aString, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsString* string = new nsString(aString);
|
|
|
|
if (nsVoidArray::InsertElementAt(string, aIndex)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
delete string;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsStringArray::ReplaceStringAt(const nsString& aString, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsString* string = (nsString*)nsVoidArray::ElementAt(aIndex);
|
|
|
|
if (nsnull != string) {
|
|
|
|
*string = aString;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsStringArray::RemoveString(const nsString& aString)
|
|
|
|
{
|
|
|
|
PRInt32 index = IndexOf(aString);
|
|
|
|
if (-1 < index) {
|
|
|
|
return RemoveStringAt(index);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsStringArray::RemoveStringIgnoreCase(const nsString& aString)
|
|
|
|
{
|
|
|
|
PRInt32 index = IndexOfIgnoreCase(aString);
|
|
|
|
if (-1 < index) {
|
|
|
|
return RemoveStringAt(index);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsStringArray::RemoveStringAt(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsString* string = StringAt(aIndex);
|
|
|
|
if (nsnull != string) {
|
|
|
|
nsVoidArray::RemoveElementAt(aIndex);
|
|
|
|
delete string;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStringArray::Clear(void)
|
|
|
|
{
|
|
|
|
PRInt32 index = mCount;
|
|
|
|
while (0 <= --index) {
|
|
|
|
nsString* string = (nsString*)mArray[index];
|
|
|
|
delete string;
|
|
|
|
}
|
|
|
|
nsVoidArray::Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsStringArray::EnumerateForwards(nsStringArrayEnumFunc aFunc, void* aData)
|
|
|
|
{
|
|
|
|
PRInt32 index = -1;
|
|
|
|
PRBool running = PR_TRUE;
|
|
|
|
|
|
|
|
while (running && (++index < mCount)) {
|
|
|
|
running = (*aFunc)(*((nsString*)mArray[index]), aData);
|
|
|
|
}
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsStringArray::EnumerateBackwards(nsStringArrayEnumFunc aFunc, void* aData)
|
|
|
|
{
|
|
|
|
PRInt32 index = mCount;
|
|
|
|
PRBool running = PR_TRUE;
|
|
|
|
|
|
|
|
while (running && (0 <= --index)) {
|
|
|
|
running = (*aFunc)(*((nsString*)mArray[index]), aData);
|
|
|
|
}
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
1999-10-30 00:47:17 +04:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
// nsCStringArray
|
|
|
|
|
|
|
|
nsCStringArray::nsCStringArray(void)
|
|
|
|
: nsVoidArray()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCStringArray::~nsCStringArray(void)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCStringArray&
|
|
|
|
nsCStringArray::operator=(const nsCStringArray& other)
|
|
|
|
{
|
1999-12-01 03:37:11 +03:00
|
|
|
if (IsArrayOwner()) {
|
1999-10-30 00:47:17 +04:00
|
|
|
delete mArray;
|
|
|
|
}
|
|
|
|
PRInt32 otherCount = other.mCount;
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArraySize(otherCount);
|
1999-10-30 00:47:17 +04:00
|
|
|
mCount = otherCount;
|
|
|
|
if (0 < otherCount) {
|
1999-12-01 03:37:11 +03:00
|
|
|
mArray = new void*[GetArraySize()];
|
1999-10-30 00:47:17 +04:00
|
|
|
while (0 <= --otherCount) {
|
|
|
|
nsCString* otherString = (nsCString*)(other.mArray[otherCount]);
|
|
|
|
mArray[otherCount] = new nsCString(*otherString);
|
|
|
|
}
|
1999-12-01 03:37:11 +03:00
|
|
|
SetArrayOwner(PR_TRUE);
|
1999-10-30 00:47:17 +04:00
|
|
|
} else {
|
|
|
|
mArray = nsnull;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCStringArray::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
PRUint32 sum = 0;
|
|
|
|
nsVoidArray::SizeOf(aHandler, &sum);
|
|
|
|
PRInt32 index = mCount;
|
|
|
|
while (0 <= --index) {
|
|
|
|
nsCString* string = (nsCString*)mArray[index];
|
|
|
|
PRUint32 size;
|
|
|
|
string->SizeOf(aHandler, &size);
|
|
|
|
sum += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCStringArray::CStringAt(PRInt32 aIndex, nsCString& aCString) const
|
|
|
|
{
|
|
|
|
nsCString* string = (nsCString*)nsVoidArray::ElementAt(aIndex);
|
|
|
|
if (nsnull != string) {
|
|
|
|
aCString = *string;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aCString.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString*
|
|
|
|
nsCStringArray::CStringAt(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
return (nsCString*)nsVoidArray::ElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsCStringArray::IndexOf(const nsCString& aPossibleString) const
|
|
|
|
{
|
|
|
|
void** ap = mArray;
|
|
|
|
void** end = ap + mCount;
|
|
|
|
while (ap < end) {
|
|
|
|
nsCString* string = (nsCString*)*ap;
|
|
|
|
if (string->Equals(aPossibleString)) {
|
|
|
|
return ap - mArray;
|
|
|
|
}
|
|
|
|
ap++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsCStringArray::IndexOfIgnoreCase(const nsCString& aPossibleString) const
|
|
|
|
{
|
|
|
|
void** ap = mArray;
|
|
|
|
void** end = ap + mCount;
|
|
|
|
while (ap < end) {
|
|
|
|
nsCString* string = (nsCString*)*ap;
|
|
|
|
if (string->EqualsIgnoreCase(aPossibleString)) {
|
|
|
|
return ap - mArray;
|
|
|
|
}
|
|
|
|
ap++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCStringArray::InsertCStringAt(const nsCString& aCString, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsCString* string = new nsCString(aCString);
|
|
|
|
if (nsVoidArray::InsertElementAt(string, aIndex)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
delete string;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCStringArray::ReplaceCStringAt(const nsCString& aCString, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsCString* string = (nsCString*)nsVoidArray::ElementAt(aIndex);
|
|
|
|
if (nsnull != string) {
|
|
|
|
*string = aCString;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCStringArray::RemoveCString(const nsCString& aCString)
|
|
|
|
{
|
|
|
|
PRInt32 index = IndexOf(aCString);
|
|
|
|
if (-1 < index) {
|
|
|
|
return RemoveCStringAt(index);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCStringArray::RemoveCStringIgnoreCase(const nsCString& aCString)
|
|
|
|
{
|
|
|
|
PRInt32 index = IndexOfIgnoreCase(aCString);
|
|
|
|
if (-1 < index) {
|
|
|
|
return RemoveCStringAt(index);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsCStringArray::RemoveCStringAt(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
nsCString* string = CStringAt(aIndex);
|
|
|
|
if (nsnull != string) {
|
|
|
|
nsVoidArray::RemoveElementAt(aIndex);
|
|
|
|
delete string;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCStringArray::Clear(void)
|
|
|
|
{
|
|
|
|
PRInt32 index = mCount;
|
|
|
|
while (0 <= --index) {
|
|
|
|
nsCString* string = (nsCString*)mArray[index];
|
|
|
|
delete string;
|
|
|
|
}
|
|
|
|
nsVoidArray::Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCStringArray::EnumerateForwards(nsCStringArrayEnumFunc aFunc, void* aData)
|
|
|
|
{
|
|
|
|
PRInt32 index = -1;
|
|
|
|
PRBool running = PR_TRUE;
|
|
|
|
|
|
|
|
while (running && (++index < mCount)) {
|
|
|
|
running = (*aFunc)(*((nsCString*)mArray[index]), aData);
|
|
|
|
}
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCStringArray::EnumerateBackwards(nsCStringArrayEnumFunc aFunc, void* aData)
|
|
|
|
{
|
|
|
|
PRInt32 index = mCount;
|
|
|
|
PRBool running = PR_TRUE;
|
|
|
|
|
|
|
|
while (running && (0 <= --index)) {
|
|
|
|
running = (*aFunc)(*((nsCString*)mArray[index]), aData);
|
|
|
|
}
|
|
|
|
return running;
|
|
|
|
}
|