1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include <iostream.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prdtoa.h"
|
1998-06-06 01:38:36 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
1999-05-06 09:13:08 +04:00
|
|
|
#include "nsStr.h"
|
1999-02-08 21:57:21 +03:00
|
|
|
|
|
|
|
#include "nsUnicharUtilCIID.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsICaseConversion.h"
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
const PRInt32 kGrowthDelta = 8;
|
|
|
|
PRUnichar gBadChar = 0;
|
|
|
|
const char* kOutOfBoundsError = "Error: out of bounds";
|
|
|
|
const char* kNullPointerError = "Error: unexpected null ptr";
|
1998-08-04 00:46:38 +04:00
|
|
|
const char* kFoolMsg = "Error: Some fool overwrote the shared buffer.";
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
PRUnichar kCommonEmptyBuffer[100]; //shared by all strings; NEVER WRITE HERE!!!
|
|
|
|
|
1999-04-25 05:27:51 +04:00
|
|
|
#ifdef RICKG_DEBUG
|
1999-04-25 05:24:10 +04:00
|
|
|
PRBool nsString1::mSelfTested = PR_FALSE;
|
1999-03-19 11:47:20 +03:00
|
|
|
#endif
|
1998-08-04 00:46:38 +04:00
|
|
|
|
1999-01-09 04:09:39 +03:00
|
|
|
|
|
|
|
#define NOT_USED 0xfffd
|
|
|
|
|
|
|
|
static PRUint16 PA_HackTable[] = {
|
|
|
|
NOT_USED,
|
|
|
|
NOT_USED,
|
|
|
|
0x201a, /* SINGLE LOW-9 QUOTATION MARK */
|
|
|
|
0x0192, /* LATIN SMALL LETTER F WITH HOOK */
|
|
|
|
0x201e, /* DOUBLE LOW-9 QUOTATION MARK */
|
|
|
|
0x2026, /* HORIZONTAL ELLIPSIS */
|
|
|
|
0x2020, /* DAGGER */
|
|
|
|
0x2021, /* DOUBLE DAGGER */
|
|
|
|
0x02c6, /* MODIFIER LETTER CIRCUMFLEX ACCENT */
|
|
|
|
0x2030, /* PER MILLE SIGN */
|
|
|
|
0x0160, /* LATIN CAPITAL LETTER S WITH CARON */
|
|
|
|
0x2039, /* SINGLE LEFT-POINTING ANGLE QUOTATION MARK */
|
|
|
|
0x0152, /* LATIN CAPITAL LIGATURE OE */
|
|
|
|
NOT_USED,
|
|
|
|
NOT_USED,
|
|
|
|
NOT_USED,
|
|
|
|
|
|
|
|
NOT_USED,
|
|
|
|
0x2018, /* LEFT SINGLE QUOTATION MARK */
|
|
|
|
0x2019, /* RIGHT SINGLE QUOTATION MARK */
|
|
|
|
0x201c, /* LEFT DOUBLE QUOTATION MARK */
|
|
|
|
0x201d, /* RIGHT DOUBLE QUOTATION MARK */
|
|
|
|
0x2022, /* BULLET */
|
|
|
|
0x2013, /* EN DASH */
|
|
|
|
0x2014, /* EM DASH */
|
|
|
|
0x02dc, /* SMALL TILDE */
|
|
|
|
0x2122, /* TRADE MARK SIGN */
|
|
|
|
0x0161, /* LATIN SMALL LETTER S WITH CARON */
|
|
|
|
0x203a, /* SINGLE RIGHT-POINTING ANGLE QUOTATION MARK */
|
|
|
|
0x0153, /* LATIN SMALL LIGATURE OE */
|
|
|
|
NOT_USED,
|
|
|
|
NOT_USED,
|
|
|
|
0x0178 /* LATIN CAPITAL LETTER Y WITH DIAERESIS */
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRUnichar gToUCS2[256];
|
|
|
|
|
|
|
|
class CTableConstructor {
|
|
|
|
public:
|
|
|
|
CTableConstructor(){
|
|
|
|
PRUnichar* cp = gToUCS2;
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
*cp++ = PRUnichar(i);
|
|
|
|
}
|
|
|
|
cp = gToUCS2;
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
cp[0x80 + i] = PA_HackTable[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static CTableConstructor gTableConstructor;
|
|
|
|
|
1999-02-08 21:57:21 +03:00
|
|
|
//---- XPCOM code to connect with UnicharUtil
|
|
|
|
|
|
|
|
class HandleCaseConversionShutdown2 : public nsIShutdownListener {
|
|
|
|
public :
|
|
|
|
NS_IMETHOD OnShutdown(const nsCID& cid, nsISupports* service);
|
|
|
|
HandleCaseConversionShutdown2(void) { NS_INIT_REFCNT(); }
|
|
|
|
virtual ~HandleCaseConversionShutdown2(void) {}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
};
|
|
|
|
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
|
|
|
static NS_DEFINE_IID(kICaseConversionIID, NS_ICASECONVERSION_IID);
|
|
|
|
|
|
|
|
static nsICaseConversion * gCaseConv = NULL;
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIShutdownListenerIID, NS_ISHUTDOWNLISTENER_IID);
|
|
|
|
NS_IMPL_ISUPPORTS(HandleCaseConversionShutdown2, kIShutdownListenerIID);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HandleCaseConversionShutdown2::OnShutdown(const nsCID& cid, nsISupports* service)
|
|
|
|
{
|
|
|
|
if (cid.Equals(kUnicharUtilCID)) {
|
|
|
|
NS_ASSERTION(service == gCaseConv, "wrong service!");
|
1999-03-23 03:28:36 +03:00
|
|
|
gCaseConv->Release();
|
1999-02-08 21:57:21 +03:00
|
|
|
gCaseConv = NULL;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HandleCaseConversionShutdown2* gListener = NULL;
|
|
|
|
|
|
|
|
static void StartUpCaseConversion()
|
|
|
|
{
|
|
|
|
nsresult err;
|
|
|
|
|
|
|
|
if ( NULL == gListener )
|
|
|
|
{
|
|
|
|
gListener = new HandleCaseConversionShutdown2();
|
|
|
|
gListener->AddRef();
|
|
|
|
}
|
|
|
|
err = nsServiceManager::GetService(kUnicharUtilCID, kICaseConversionIID,
|
|
|
|
(nsISupports**) &gCaseConv, gListener);
|
|
|
|
}
|
|
|
|
static void CheckCaseConversion()
|
|
|
|
{
|
|
|
|
if(NULL == gCaseConv )
|
|
|
|
StartUpCaseConversion();
|
|
|
|
|
1999-03-07 22:23:28 +03:00
|
|
|
// NS_ASSERTION( gCaseConv != NULL , "cannot obtain UnicharUtil");
|
1999-02-08 21:57:21 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/***********************************************************************
|
1998-09-04 21:26:37 +04:00
|
|
|
IMPLEMENTATION NOTES:
|
1998-08-04 00:46:38 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
Man I hate writing string classes.
|
|
|
|
You'd think after about a qintrillion lines of code have been written,
|
|
|
|
that no poor soul would ever have to do this again. Sigh.
|
1998-08-04 00:46:38 +04:00
|
|
|
***********************************************************************/
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-05-20 20:21:48 +04:00
|
|
|
/**
|
1998-08-04 00:46:38 +04:00
|
|
|
* Default constructor. Note that we actually allocate a small buffer
|
|
|
|
* to begin with. This is because the "philosophy" of the string class
|
|
|
|
* was to allow developers direct access to the underlying buffer for
|
|
|
|
* performance reasons.
|
1998-05-20 20:21:48 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1::nsString1() {
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(kCommonEmptyBuffer[0]==0,kFoolMsg);
|
1998-05-20 20:21:48 +04:00
|
|
|
mLength = mCapacity = 0;
|
1998-08-04 00:46:38 +04:00
|
|
|
mStr = kCommonEmptyBuffer;
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1999-04-25 05:27:51 +04:00
|
|
|
#ifdef RICKG_DEBUG
|
1998-08-04 01:03:49 +04:00
|
|
|
if(!mSelfTested) {
|
|
|
|
mSelfTested=PR_TRUE;
|
1998-08-04 00:46:38 +04:00
|
|
|
SelfTest();
|
1998-08-04 01:03:49 +04:00
|
|
|
}
|
1999-03-19 11:47:20 +03:00
|
|
|
#endif
|
1998-05-20 20:21:48 +04:00
|
|
|
}
|
|
|
|
|
1998-07-30 22:35:58 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor accepts an isolatin string
|
|
|
|
* @update gess7/30/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString is a ptr to a 1-byte cstr
|
1998-07-30 22:35:58 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1::nsString1(const char* aCString) {
|
1998-04-14 00:24:54 +04:00
|
|
|
mLength=mCapacity=0;
|
1998-08-04 00:46:38 +04:00
|
|
|
mStr = kCommonEmptyBuffer;
|
1998-11-21 01:11:09 +03:00
|
|
|
if(aCString) {
|
|
|
|
PRInt32 len=strlen(aCString);
|
1998-08-04 00:46:38 +04:00
|
|
|
EnsureCapacityFor(len);
|
1998-11-21 01:11:09 +03:00
|
|
|
this->SetString(aCString,len);
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-07-30 22:35:58 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is our copy constructor
|
|
|
|
* @update gess7/30/98
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param reference to another nsString1
|
1998-07-30 22:35:58 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1::nsString1(const nsString1 &aString) {
|
1998-04-14 00:24:54 +04:00
|
|
|
mLength=mCapacity=0;
|
1998-08-04 00:46:38 +04:00
|
|
|
mStr = kCommonEmptyBuffer;
|
|
|
|
if(aString.mLength) {
|
|
|
|
EnsureCapacityFor(aString.mLength);
|
|
|
|
this->SetString(aString.mStr,aString.mLength);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor from a unicode string
|
|
|
|
* @update gess7/30/98
|
|
|
|
* @param anicodestr pts to a unicode string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1::nsString1(const PRUnichar* aUnicodeStr) {
|
1998-04-14 00:24:54 +04:00
|
|
|
mLength=mCapacity=0;
|
1998-08-04 00:46:38 +04:00
|
|
|
mStr = kCommonEmptyBuffer;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 len=(aUnicodeStr) ? nsCRT::strlen(aUnicodeStr) : 0;
|
1998-08-04 00:46:38 +04:00
|
|
|
if(len>0) {
|
|
|
|
EnsureCapacityFor(len);
|
|
|
|
this->SetString(aUnicodeStr,len);
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
* @update gess7/30/98
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1::~nsString1()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-08-04 00:46:38 +04:00
|
|
|
if(mStr && (mStr!=kCommonEmptyBuffer))
|
|
|
|
delete [] mStr;
|
1998-04-14 00:24:54 +04:00
|
|
|
mStr=0;
|
|
|
|
mCapacity=mLength=0;
|
|
|
|
}
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method truncates this string to given length.
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param anIndex -- new length of string
|
|
|
|
* @return nada
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::Truncate(PRInt32 anIndex) {
|
1998-09-04 21:26:37 +04:00
|
|
|
if((anIndex>-1) && (anIndex<mLength)) {
|
|
|
|
mLength=anIndex;
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::SizeOf(nsISizeOfHandler* aHandler) const
|
1998-06-06 01:38:36 +04:00
|
|
|
{
|
|
|
|
aHandler->Add(sizeof(*this));
|
|
|
|
aHandler->Add(mCapacity * sizeof(chartype));
|
|
|
|
}
|
|
|
|
|
1998-08-29 09:06:50 +04:00
|
|
|
/**
|
|
|
|
* Determine whether or not the characters in this
|
|
|
|
* string are in sorted order.
|
|
|
|
*
|
|
|
|
* @update gess 8/25/98
|
|
|
|
* @return TRUE if ordered.
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::IsOrdered(void) const {
|
1998-08-29 09:06:50 +04:00
|
|
|
PRBool result=PR_TRUE;
|
|
|
|
if(mLength>1) {
|
|
|
|
PRInt32 theIndex;
|
|
|
|
for(theIndex=1;theIndex<mLength;theIndex++) {
|
1998-10-27 01:33:39 +03:00
|
|
|
if(mStr[theIndex-1]>mStr[theIndex]) {
|
1998-08-29 09:06:50 +04:00
|
|
|
result=PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* This method gets called when the internal buffer needs
|
|
|
|
* to grow to a given size.
|
|
|
|
* @update gess 3/30/98
|
|
|
|
* @param aNewLength -- new capacity of string
|
|
|
|
* @return void
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::EnsureCapacityFor(PRInt32 aNewLength)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 newCapacity;
|
|
|
|
|
|
|
|
if (mCapacity > 64) {
|
|
|
|
// When the string starts getting large, double the capacity as we
|
|
|
|
// grow.
|
|
|
|
newCapacity = mCapacity * 2;
|
|
|
|
if (newCapacity < aNewLength) {
|
|
|
|
newCapacity = mCapacity + aNewLength;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// When the string is small, keep it's capacity a multiple of
|
|
|
|
// kGrowthDelta
|
|
|
|
PRInt32 size =aNewLength+kGrowthDelta;
|
|
|
|
newCapacity=size-(size % kGrowthDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mCapacity<newCapacity) {
|
|
|
|
mCapacity=newCapacity;
|
|
|
|
chartype* temp = new chartype[newCapacity+1];
|
|
|
|
if (mLength > 0) {
|
1998-08-27 12:15:40 +04:00
|
|
|
nsCRT::memcpy(temp, mStr, mLength * sizeof(chartype) + sizeof(chartype));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
if(mStr && (mStr!=kCommonEmptyBuffer))
|
1998-04-14 00:24:54 +04:00
|
|
|
delete [] mStr;
|
|
|
|
mStr = temp;
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method if you want string to report a shorter length.
|
|
|
|
* @update gess7/30/98
|
|
|
|
* @param aLength -- contains new length for mStr
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::SetLength(PRInt32 aLength) {
|
1998-08-04 00:46:38 +04:00
|
|
|
if(aLength>mLength) {
|
|
|
|
EnsureCapacityFor(aLength);
|
1998-04-14 00:24:54 +04:00
|
|
|
nsCRT::zero(mStr + mLength, (aLength - mLength) * sizeof(chartype));
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
if((aLength>=0) && (aLength<mLength))
|
1998-08-04 00:46:38 +04:00
|
|
|
mStr[aLength]=0;
|
1998-04-14 00:24:54 +04:00
|
|
|
mLength=aLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/*********************************************************
|
|
|
|
ACCESSOR METHODS....
|
|
|
|
*********************************************************/
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Retrieve pointer to internal string value
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return PRUnichar* to internal string
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
const PRUnichar* nsString1::GetUnicode(void) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
return mStr;
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1::operator const PRUnichar*() const{
|
1998-04-14 00:24:54 +04:00
|
|
|
return mStr;
|
|
|
|
}
|
1999-04-25 07:10:44 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Retrieve unicode char at given index
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param offset into string
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return PRUnichar* to internal string
|
1999-05-06 09:13:08 +04:00
|
|
|
|
|
|
|
PRUnichar nsString1::operator()(int anIndex) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(anIndex<mLength,kOutOfBoundsError);
|
|
|
|
if((anIndex<mLength) && (mStr))
|
|
|
|
return mStr[anIndex];
|
|
|
|
else return gBadChar;
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
*/
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Retrieve reference to unicode char at given index
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param offset into string
|
|
|
|
* @return PRUnichar& from internal string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRUnichar& nsString1::operator[](PRInt32 anIndex) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
// NS_ASSERTION(anIndex<mLength,kOutOfBoundsError);
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
if((anIndex<mLength) && (mStr))
|
|
|
|
return mStr[anIndex];
|
|
|
|
else return gBadChar;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Retrieve reference to unicode char at given index
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param offset into string
|
|
|
|
* @return PRUnichar& from internal string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRUnichar& nsString1::CharAt(PRInt32 anIndex) const{
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(anIndex<mLength,kOutOfBoundsError);
|
|
|
|
if((anIndex<mLength) && (mStr))
|
|
|
|
return mStr[anIndex];
|
|
|
|
else return gBadChar;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Retrieve reference to first unicode char in string
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @return PRUnichar from internal string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRUnichar& nsString1::First() const{
|
1998-04-14 00:24:54 +04:00
|
|
|
if((mLength) && (mStr))
|
|
|
|
return mStr[0];
|
|
|
|
else return gBadChar;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Retrieve reference to last unicode char in string
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @return PRUnichar from internal string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRUnichar& nsString1::Last() const{
|
1998-04-14 00:24:54 +04:00
|
|
|
if((mLength) && (mStr))
|
|
|
|
return mStr[mLength-1];
|
|
|
|
else return gBadChar;
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::SetCharAt(PRUnichar aChar,PRInt32 anIndex){
|
1999-03-22 11:29:26 +03:00
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if(anIndex<mLength){
|
|
|
|
PRUnichar* theStr=(PRUnichar*)mStr;
|
|
|
|
theStr[anIndex]=aChar;
|
|
|
|
result=PR_TRUE;
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1999-03-22 11:29:26 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Create a new string by appending given string to this
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aString -- 2nd string to be appended
|
1998-08-04 00:46:38 +04:00
|
|
|
* @return new string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 nsString1::operator+(const nsString1& aString){
|
|
|
|
|
|
|
|
nsString1 temp(*this);
|
1998-04-14 00:24:54 +04:00
|
|
|
temp.Append(aString.mStr,aString.mLength);
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* create a new string by adding this to the given buffer.
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString is a ptr to cstring to be added to this
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return newly created string
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 nsString1::operator+(const char* aCString) {
|
|
|
|
nsString1 temp(*this);
|
1998-11-21 01:11:09 +03:00
|
|
|
temp.Append(aCString);
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* create a new string by adding this to the given char.
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aChar is a char to be added to this
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return newly created string
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 nsString1::operator+(char aChar) {
|
|
|
|
nsString1 temp(*this);
|
1998-04-14 00:24:54 +04:00
|
|
|
temp.Append(chartype(aChar));
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* create a new string by adding this to the given buffer.
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aStr unichar buffer to be added to this
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return newly created string
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 nsString1::operator+(const PRUnichar* aStr) {
|
|
|
|
nsString1 temp(*this);
|
1998-04-14 00:24:54 +04:00
|
|
|
temp.Append(aStr);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* create a new string by adding this to the given char.
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aChar is a unichar to be added to this
|
|
|
|
* @return newly created string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 nsString1::operator+(PRUnichar aChar) {
|
|
|
|
nsString1 temp(*this);
|
1998-04-14 00:24:54 +04:00
|
|
|
temp.Append(aChar);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Converts all chars in internal string to lower
|
|
|
|
* @update gess 7/27/98
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::ToLowerCase()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-08 21:57:21 +03:00
|
|
|
// I18N code begin
|
|
|
|
CheckCaseConversion();
|
1999-03-07 22:23:28 +03:00
|
|
|
if(gCaseConv) {
|
|
|
|
nsresult err = gCaseConv->ToLower(mStr, mStr, mLength);
|
|
|
|
if( NS_SUCCEEDED(err))
|
|
|
|
return;
|
|
|
|
}
|
1999-02-08 21:57:21 +03:00
|
|
|
// I18N code end
|
|
|
|
|
|
|
|
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
1998-04-14 00:24:54 +04:00
|
|
|
chartype* cp = mStr;
|
|
|
|
chartype* end = cp + mLength;
|
|
|
|
while (cp < end) {
|
|
|
|
chartype ch = *cp;
|
|
|
|
if ((ch >= 'A') && (ch <= 'Z')) {
|
|
|
|
*cp = 'a' + (ch - 'A');
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Converts all chars in internal string to upper
|
|
|
|
* @update gess 7/27/98
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::ToUpperCase()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-02-08 21:57:21 +03:00
|
|
|
// I18N code begin
|
|
|
|
CheckCaseConversion();
|
1999-03-07 22:23:28 +03:00
|
|
|
if(gCaseConv) {
|
|
|
|
nsresult err = gCaseConv->ToUpper(mStr, mStr, mLength);
|
|
|
|
if( NS_SUCCEEDED(err))
|
|
|
|
return;
|
|
|
|
}
|
1999-02-08 21:57:21 +03:00
|
|
|
// I18N code end
|
|
|
|
|
|
|
|
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
1998-04-14 00:24:54 +04:00
|
|
|
chartype* cp = mStr;
|
|
|
|
chartype* end = cp + mLength;
|
|
|
|
while (cp < end) {
|
|
|
|
chartype ch = *cp;
|
|
|
|
if ((ch >= 'a') && (ch <= 'z')) {
|
|
|
|
*cp = 'A' + (ch - 'a');
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 04:09:39 +03:00
|
|
|
/**
|
|
|
|
* Converts all chars in given string to UCS2
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::ToUCS2(PRInt32 aStartOffset){
|
1999-01-09 04:09:39 +03:00
|
|
|
if(aStartOffset<mLength){
|
|
|
|
chartype* cp = &mStr[aStartOffset];
|
|
|
|
chartype* end = cp + mLength;
|
|
|
|
while (cp < end) {
|
|
|
|
unsigned char ch = (unsigned char)*cp;
|
1999-01-29 21:08:36 +03:00
|
|
|
if( 0x0080 == (0xFFE0 & (*cp)) ) // limit to only 0x0080 to 0x009F
|
|
|
|
*cp=gToUCS2[ch];
|
1999-01-09 04:09:39 +03:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Converts chars in this to lowercase, and
|
|
|
|
* stores them in aOut
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aOut is a string to contain result
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::ToLowerCase(nsString1& aOut) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-20 20:21:48 +04:00
|
|
|
aOut.EnsureCapacityFor(mLength);
|
|
|
|
aOut.mLength = mLength;
|
1999-02-08 21:57:21 +03:00
|
|
|
|
|
|
|
// I18N code begin
|
|
|
|
CheckCaseConversion();
|
1999-03-07 22:23:28 +03:00
|
|
|
if(gCaseConv) {
|
|
|
|
nsresult err = gCaseConv->ToLower(mStr, aOut.mStr, mLength);
|
|
|
|
(*(aOut.mStr+mLength)) = 0;
|
|
|
|
if( NS_SUCCEEDED(err))
|
|
|
|
return;
|
|
|
|
}
|
1999-02-08 21:57:21 +03:00
|
|
|
// I18N code end
|
|
|
|
|
|
|
|
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
chartype* to = aOut.mStr;
|
|
|
|
chartype* from = mStr;
|
|
|
|
chartype* end = from + mLength;
|
|
|
|
while (from < end) {
|
|
|
|
chartype ch = *from++;
|
|
|
|
if ((ch >= 'A') && (ch <= 'Z')) {
|
|
|
|
ch = 'a' + (ch - 'A');
|
|
|
|
}
|
|
|
|
*to++ = ch;
|
|
|
|
}
|
|
|
|
*to = 0;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Converts chars in this to lowercase, and
|
|
|
|
* stores them in a given output string
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aOut is a string to contain result
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::ToUpperCase(nsString1& aOut) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-20 20:21:48 +04:00
|
|
|
aOut.EnsureCapacityFor(mLength);
|
|
|
|
aOut.mLength = mLength;
|
1999-02-08 21:57:21 +03:00
|
|
|
|
|
|
|
// I18N code begin
|
|
|
|
CheckCaseConversion();
|
1999-03-07 22:23:28 +03:00
|
|
|
if(gCaseConv) {
|
|
|
|
nsresult err = gCaseConv->ToUpper(mStr, aOut.mStr, mLength);
|
|
|
|
(*(aOut.mStr+mLength)) = 0;
|
|
|
|
if( NS_SUCCEEDED(err))
|
|
|
|
return;
|
|
|
|
}
|
1999-02-08 21:57:21 +03:00
|
|
|
// I18N code end
|
|
|
|
|
|
|
|
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
1998-04-14 00:24:54 +04:00
|
|
|
chartype* to = aOut.mStr;
|
|
|
|
chartype* from = mStr;
|
|
|
|
chartype* end = from + mLength;
|
|
|
|
while (from < end) {
|
|
|
|
chartype ch = *from++;
|
|
|
|
if ((ch >= 'a') && (ch <= 'z')) {
|
|
|
|
ch = 'A' + (ch - 'a');
|
|
|
|
}
|
|
|
|
*to++ = ch;
|
|
|
|
}
|
|
|
|
*to = 0;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Creates a duplicate clone (ptr) of this string.
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @return ptr to clone of this string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1* nsString1::ToNewString() const {
|
|
|
|
return new nsString1(mStr);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-11-21 01:11:09 +03:00
|
|
|
* Creates an aCString clone of this string
|
|
|
|
* NOTE: Call delete[] when you're done with this copy. NOT free!
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @return ptr to new aCString string
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
char* nsString1::ToNewCString() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
char* rv = new char[mLength + 1];
|
|
|
|
return ToCString(rv,mLength+1);
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Creates an unichar clone of this string
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @return ptr to new unichar string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRUnichar* nsString1::ToNewUnicode() const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 len = mLength;
|
|
|
|
chartype* rv = new chartype[len + 1];
|
|
|
|
chartype* to = rv;
|
|
|
|
chartype* from = mStr;
|
|
|
|
while (--len >= 0) {
|
|
|
|
*to++ = *from++;
|
|
|
|
}
|
|
|
|
*to++ = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Copies contents of this onto given string.
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aString to hold copy of this
|
|
|
|
* @return nada.
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::Copy(nsString1& aString) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-20 20:21:48 +04:00
|
|
|
aString.mLength = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
aString.Append(mStr, mLength);
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
char* nsString1::ToCString(char* aBuf, PRInt32 aBufLength) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
aBufLength--; // leave room for the \0
|
1998-08-04 00:46:38 +04:00
|
|
|
PRInt32 len = (mLength > aBufLength) ? aBufLength : mLength;
|
1998-04-14 00:24:54 +04:00
|
|
|
char* to = aBuf;
|
|
|
|
chartype* from = mStr;
|
|
|
|
while (--len >= 0) {
|
|
|
|
*to++ = char(*from++);
|
|
|
|
}
|
|
|
|
*to++ = '\0';
|
|
|
|
return aBuf;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Perform string to float conversion.
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return float rep of string value
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
float nsString1::ToFloat(PRInt32* aErrorCode) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
char buf[40];
|
1998-07-25 06:11:02 +04:00
|
|
|
if (mLength > PRInt32(sizeof(buf)-1)) {
|
1998-04-26 07:13:20 +04:00
|
|
|
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
char* cp = ToCString(buf, sizeof(buf));
|
|
|
|
float f = (float) PR_strtod(cp, &cp);
|
|
|
|
if (*cp != 0) {
|
1998-04-26 07:13:20 +04:00
|
|
|
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-04-26 07:13:20 +04:00
|
|
|
*aErrorCode = (PRInt32) NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-10-04 08:52:10 +04:00
|
|
|
* Perform numeric string to int conversion with given radix.
|
|
|
|
* @update gess 10/01/98
|
1998-08-04 00:46:38 +04:00
|
|
|
* @param aErrorCode will contain error if one occurs
|
1998-10-04 08:52:10 +04:00
|
|
|
* @param aRadix tells us what base to expect the string in.
|
1998-11-24 05:38:21 +03:00
|
|
|
* @return int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const {
|
1998-10-04 08:52:10 +04:00
|
|
|
PRInt32 result = 0;
|
1999-01-10 11:17:40 +03:00
|
|
|
PRInt32 decPt=Find(PRUnichar('.'),0);
|
|
|
|
PRUnichar* cp = (-1==decPt) ? mStr + mLength-1 : mStr+decPt-1;
|
1998-10-04 08:52:10 +04:00
|
|
|
char digit=0;
|
|
|
|
PRUnichar theChar;
|
1999-03-23 03:28:36 +03:00
|
|
|
// PRInt32 theShift=0;
|
1998-10-04 08:52:10 +04:00
|
|
|
PRInt32 theMult=1;
|
|
|
|
|
1998-11-24 05:38:21 +03:00
|
|
|
*aErrorCode = (0<mLength) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
1999-01-10 11:17:40 +03:00
|
|
|
|
1998-10-04 08:52:10 +04:00
|
|
|
// Skip trailing non-numeric...
|
|
|
|
while (cp >= mStr) {
|
|
|
|
theChar = *cp;
|
|
|
|
if((theChar>='0') && (theChar<='9')){
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-10-04 08:52:10 +04:00
|
|
|
else if((theChar>='a') && (theChar<='f')) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if((theChar>='A') && (theChar<='F')) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-10-04 08:52:10 +04:00
|
|
|
cp--;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-10-04 08:52:10 +04:00
|
|
|
//now iterate the numeric chars and build our result
|
|
|
|
while(cp>=mStr) {
|
|
|
|
theChar=*cp--;
|
|
|
|
if((theChar>='0') && (theChar<='9')){
|
|
|
|
digit=theChar-'0';
|
|
|
|
}
|
|
|
|
else if((theChar>='a') && (theChar<='f')) {
|
|
|
|
digit=(theChar-'a')+10;
|
|
|
|
}
|
|
|
|
else if((theChar>='A') && (theChar<='F')) {
|
|
|
|
digit=(theChar-'A')+10;
|
|
|
|
}
|
|
|
|
else if('-'==theChar) {
|
|
|
|
result=-result;
|
|
|
|
break;
|
|
|
|
}
|
1999-03-25 04:27:27 +03:00
|
|
|
else if(('+'==theChar) || (' '==theChar) || ('#'==theChar)) { //stop in a good state if you see this...
|
1999-01-15 22:20:51 +03:00
|
|
|
break;
|
|
|
|
}
|
1999-02-19 09:32:40 +03:00
|
|
|
else if((('x'==theChar) || ('X'==theChar)) && (16==aRadix)) {
|
|
|
|
//stop in a good state.
|
1998-11-24 23:23:46 +03:00
|
|
|
break;
|
|
|
|
}
|
1998-10-04 08:52:10 +04:00
|
|
|
else{
|
1998-11-24 05:38:21 +03:00
|
|
|
*aErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
result=0;
|
1998-10-04 08:52:10 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
result+=digit*theMult;
|
|
|
|
theMult*=aRadix;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-10-04 08:52:10 +04:00
|
|
|
|
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* assign given PRUnichar* to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param PRUnichar: buffer to be assigned to this
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::SetString(const PRUnichar* aStr,PRInt32 aLength) {
|
1998-07-31 00:36:51 +04:00
|
|
|
if((0 == aLength) || (nsnull == aStr)) {
|
|
|
|
mLength=0;
|
|
|
|
if (nsnull != mStr) {
|
|
|
|
mStr[0]=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
1998-08-05 05:31:14 +04:00
|
|
|
PRInt32 len=(aLength<0) ? nsCRT::strlen(aStr) : aLength;
|
|
|
|
if(mCapacity<=len)
|
1998-04-14 00:24:54 +04:00
|
|
|
EnsureCapacityFor(len);
|
|
|
|
nsCRT::memcpy(mStr,aStr,len*sizeof(chartype));
|
|
|
|
mLength=len;
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
1998-07-31 00:36:51 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* assign given char* to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString: buffer to be assigned to this
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::SetString(const char* aCString,PRInt32 aLength) {
|
1998-11-21 01:11:09 +03:00
|
|
|
if(aCString!=0) {
|
|
|
|
PRInt32 len=(aLength<0) ? nsCRT::strlen(aCString) : aLength;
|
1998-08-05 05:31:14 +04:00
|
|
|
if(mCapacity<=len)
|
1998-04-14 00:24:54 +04:00
|
|
|
EnsureCapacityFor(len);
|
1998-11-21 01:11:09 +03:00
|
|
|
const unsigned char* from = (const unsigned char*) aCString;
|
1998-10-10 19:28:53 +04:00
|
|
|
const unsigned char* end = from + len;
|
|
|
|
PRUnichar* dst = mStr;
|
|
|
|
while (from < end) {
|
|
|
|
*dst++ = PRUnichar(*from++);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
mLength=len;
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLength=0; //This little bit of code handles the case
|
|
|
|
mStr[0]=0; //where some blockhead hands us a null string
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char* to this string
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aCString: buffer to be assigned to this
|
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
nsString1& nsString1::SetString(const nsString1& aString) {
|
|
|
|
|
|
|
|
if(mCapacity<=aString.mLength)
|
|
|
|
EnsureCapacityFor(aString.mLength);
|
|
|
|
PRUnichar* from = (PRUnichar*) aString.mStr;
|
|
|
|
PRUnichar* end = from + aString.mLength;
|
|
|
|
PRUnichar* dst = (PRUnichar*) mStr;
|
|
|
|
while(from<end){
|
|
|
|
*dst++=*from++;
|
|
|
|
}
|
|
|
|
mLength=aString.mLength;
|
|
|
|
*dst=0;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* assign given char* to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param PRUnichar: buffer to be assigned to this
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator=(const PRUnichar* aStr) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return this->SetString(aStr);
|
|
|
|
}
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
/**
|
|
|
|
* assign given string to this one
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aString: string to be added to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator=(const nsString1& aString) {
|
|
|
|
return this->SetString(aString);
|
1998-09-04 21:26:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char* to this string
|
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString: buffer to be assigned to this
|
1998-09-04 21:26:37 +04:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator=(const char* aCString) {
|
1998-11-21 01:11:09 +03:00
|
|
|
return SetString(aCString);
|
1998-09-04 21:26:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char to this string
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aChar: char to be assignd to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator=(char aChar) {
|
1998-09-04 21:26:37 +04:00
|
|
|
return this->operator=(PRUnichar(aChar));
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* assign given char to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aChar: char to be assignd to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator=(PRUnichar aChar) {
|
1998-04-14 00:24:54 +04:00
|
|
|
if(mCapacity<1)
|
|
|
|
EnsureCapacityFor(kGrowthDelta);
|
|
|
|
mStr[0]=aChar;
|
1998-07-30 22:35:58 +04:00
|
|
|
mLength=1;
|
|
|
|
mStr[mLength]=0;
|
1998-04-14 00:24:54 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given string to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Append(const nsString1& aString,PRInt32 aLength) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return Append(aString.mStr,aString.mLength);
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given string to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Append(const char* aCString,PRInt32 aLength) {
|
|
|
|
|
1998-11-21 01:11:09 +03:00
|
|
|
if(aCString!=0) {
|
|
|
|
PRInt32 len=(aLength<0) ? strlen(aCString) : aLength;
|
1998-08-05 05:31:14 +04:00
|
|
|
if(mLength+len >= mCapacity) {
|
1998-04-14 00:24:54 +04:00
|
|
|
EnsureCapacityFor(mLength+len);
|
|
|
|
}
|
1998-11-21 01:11:09 +03:00
|
|
|
const unsigned char* from = (const unsigned char*) aCString;
|
1998-10-10 19:28:53 +04:00
|
|
|
const unsigned char* end = from + len;
|
|
|
|
PRUnichar* to = mStr + mLength;
|
|
|
|
while (from < end) {
|
|
|
|
*to++ = PRUnichar(*from++);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
mLength+=len;
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given string to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Append(char aChar) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return Append(PRUnichar(aChar));
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given string to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Append(const PRUnichar* aString,PRInt32 aLength) {
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
if(aString!=0) {
|
1998-08-05 05:31:14 +04:00
|
|
|
PRInt32 len=(aLength<0) ? nsCRT::strlen(aString) : aLength;
|
|
|
|
if(mLength+len >= mCapacity) {
|
1998-04-14 00:24:54 +04:00
|
|
|
EnsureCapacityFor(mLength+len);
|
|
|
|
}
|
|
|
|
if(len>0)
|
|
|
|
nsCRT::memcpy(&mStr[mLength],aString,len*sizeof(chartype));
|
|
|
|
mLength+=len;
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given string to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Append(PRUnichar aChar) {
|
1998-04-14 00:24:54 +04:00
|
|
|
if(mLength < mCapacity) {
|
|
|
|
mStr[mLength++]=aChar; // the new string len < capacity, so just copy
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
|
|
|
else { // The new string exceeds our capacity
|
|
|
|
EnsureCapacityFor(mLength+1);
|
|
|
|
mStr[mLength++]=aChar;
|
|
|
|
mStr[mLength]=0;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given string to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator+=(const nsString1 &aString) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return this->Append(aString.mStr,aString.mLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given buffer to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString: buffer to be appended to this
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator+=(const char* aCString) {
|
1998-11-21 01:11:09 +03:00
|
|
|
return Append(aCString);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given buffer to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aBuffer: buffer to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator+=(const PRUnichar* aBuffer) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return Append(aBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* append given char to this string
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aChar: char to be appended to this
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::operator+=(PRUnichar aChar) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return Append(aChar);
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Append(PRInt32 aInteger,PRInt32 aRadix) {
|
1998-04-14 00:24:54 +04:00
|
|
|
char* fmt = "%d";
|
|
|
|
if (8 == aRadix) {
|
|
|
|
fmt = "%o";
|
|
|
|
} else if (16 == aRadix) {
|
|
|
|
fmt = "%x";
|
|
|
|
}
|
|
|
|
char buf[40];
|
|
|
|
PR_snprintf(buf, sizeof(buf), fmt, aInteger);
|
|
|
|
Append(buf);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Append(float aFloat){
|
1998-04-14 00:24:54 +04:00
|
|
|
char buf[40];
|
|
|
|
PR_snprintf(buf, sizeof(buf), "%g", aFloat);
|
|
|
|
Append(buf);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/*
|
1998-04-14 00:24:54 +04:00
|
|
|
* Copies n characters from this string to given string,
|
|
|
|
* starting at the leftmost offset.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
|
|
|
* @param aCopy -- Receiving string
|
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Left(nsString1& aCopy,PRInt32 aCount) const {
|
1998-04-14 00:24:54 +04:00
|
|
|
return Mid(aCopy,0,aCount);
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/*
|
1998-04-14 00:24:54 +04:00
|
|
|
* Copies n characters from this string to given string,
|
|
|
|
* starting at the given offset.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
|
|
|
* @param aCopy -- Receiving string
|
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @param anOffset -- position where copying begins
|
|
|
|
* @return number of chars copied
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Mid(nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) const {
|
1999-03-23 10:26:27 +03:00
|
|
|
aCopy.Truncate();
|
1998-04-14 00:24:54 +04:00
|
|
|
if(anOffset<mLength) {
|
|
|
|
aCount=(anOffset+aCount<=mLength) ? aCount : mLength-anOffset;
|
|
|
|
|
|
|
|
PRUnichar* from = mStr + anOffset;
|
|
|
|
PRUnichar* end = mStr + anOffset + aCount;
|
|
|
|
|
|
|
|
while (from < end) {
|
|
|
|
PRUnichar ch = *from;
|
|
|
|
aCopy.Append(ch);
|
|
|
|
from++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else aCount=0;
|
|
|
|
return aCount;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/*
|
1998-04-14 00:24:54 +04:00
|
|
|
* Copies n characters from this string to given string,
|
|
|
|
* starting at rightmost char.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
|
|
|
* @param aCopy -- Receiving string
|
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Right(nsString1& aCopy,PRInt32 aCount) const {
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 offset=(mLength-aCount<0) ? 0 : mLength-aCount;
|
|
|
|
return Mid(aCopy,offset,aCount);
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/*
|
1998-04-14 00:24:54 +04:00
|
|
|
* This method inserts n chars from given string into this
|
|
|
|
* string at str[anOffset].
|
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
|
|
|
* @param aCopy -- String to be inserted into this
|
|
|
|
* @param anOffset -- insertion position within this str
|
|
|
|
* @param aCount -- number of chars to be copied from aCopy
|
|
|
|
* @return number of chars inserted into this.
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Insert(const nsString1& aCopy,PRInt32 anOffset,PRInt32 aCount) {
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
aCount=(aCount>aCopy.mLength) ? aCopy.mLength : aCount; //don't try to copy more than you are given
|
1998-11-19 20:58:30 +03:00
|
|
|
if (aCount < 0) aCount = aCopy.mLength;
|
1998-09-04 22:49:50 +04:00
|
|
|
if(0<=anOffset) {
|
1998-09-04 21:26:37 +04:00
|
|
|
if(aCount>0) {
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
//1st optimization: If you're inserting at end, then simply append!
|
|
|
|
if(anOffset>=mLength){
|
|
|
|
Append(aCopy,aCopy.mLength);
|
|
|
|
return aCopy.mLength;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
if(mLength+aCount >= mCapacity) {
|
|
|
|
EnsureCapacityFor(mLength+aCount);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
PRUnichar* last = mStr + mLength;
|
|
|
|
PRUnichar* first = mStr + anOffset-1;
|
|
|
|
PRUnichar* next = mStr + mLength + aCount;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
//Copy rightmost chars, up to offset+aCount...
|
|
|
|
while(first<last) {
|
|
|
|
*next=*last;
|
|
|
|
next--;
|
|
|
|
last--;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
//now insert new chars, starting at offset
|
|
|
|
next = last;
|
|
|
|
first = aCopy.mStr - 1;
|
|
|
|
last = aCopy.mStr + aCount;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
while (++first<last) {
|
|
|
|
*(++next)=*first;
|
|
|
|
}
|
|
|
|
mLength+=aCount;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-09-04 21:26:37 +04:00
|
|
|
else aCount=0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return aCount;
|
|
|
|
}
|
|
|
|
|
1998-04-25 23:44:35 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a single unicode char into this string at
|
|
|
|
* a specified offset.
|
|
|
|
*
|
|
|
|
* @update gess4/22/98
|
|
|
|
* @param aChar char to be inserted into this string
|
|
|
|
* @param anOffset is insert pos in str
|
|
|
|
* @return the number of chars inserted into this string
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Insert(PRUnichar aChar,PRInt32 anOffset){
|
1998-04-25 23:44:35 +04:00
|
|
|
|
|
|
|
//1st optimization: If you're inserting at end, then simply append!
|
|
|
|
if(anOffset<mLength){
|
|
|
|
|
1998-08-05 05:31:14 +04:00
|
|
|
if(mLength+1>=mCapacity) {
|
1998-04-25 23:44:35 +04:00
|
|
|
EnsureCapacityFor(mLength+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar* last = mStr + mLength;
|
|
|
|
PRUnichar* first = mStr + anOffset-1;
|
|
|
|
PRUnichar* next = mStr + mLength + 1;
|
|
|
|
|
|
|
|
//Copy rightmost chars, up to offset+aCount...
|
|
|
|
while(first<last) {
|
|
|
|
*next=*last;
|
|
|
|
next--;
|
|
|
|
last--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//now insert new chars, starting at offset
|
|
|
|
mStr[anOffset]=aChar;
|
|
|
|
mLength+=1;
|
|
|
|
}
|
|
|
|
else Append(aChar);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/*
|
1998-04-14 00:24:54 +04:00
|
|
|
* This method is used to cut characters in this string
|
|
|
|
* starting at anOffset, continuing for aCount chars.
|
|
|
|
*
|
|
|
|
* @update gess 3/26/98
|
|
|
|
* @param anOffset -- start pos for cut operation
|
|
|
|
* @param aCount -- number of chars to be cut
|
|
|
|
* @return *this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1&
|
|
|
|
nsString1::Cut(PRInt32 anOffset, PRInt32 aCount)
|
1998-05-21 03:18:25 +04:00
|
|
|
{
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-05-21 03:18:25 +04:00
|
|
|
if (PRUint32(anOffset) < PRUint32(mLength)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 spos=anOffset+aCount;
|
|
|
|
PRInt32 delcnt=(spos<mLength) ? aCount : mLength-anOffset;
|
1998-05-21 03:18:25 +04:00
|
|
|
if (spos < mLength) {
|
|
|
|
nsCRT::memmove(&mStr[anOffset], &mStr[spos],
|
|
|
|
sizeof(chartype) * (mLength - spos));
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-05-21 03:18:25 +04:00
|
|
|
mLength -= delcnt;
|
|
|
|
mStr[mLength] = 0; // restore zero terminator
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* This method is used to remove all occurances of the
|
|
|
|
* characters found in aSet from this string.
|
|
|
|
*
|
|
|
|
* @update gess 3/26/98
|
|
|
|
* @param aSet -- characters to be cut from this
|
|
|
|
* @return *this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::StripChars(const char* aSet){
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PRUnichar* from = mStr;
|
|
|
|
PRUnichar* end = mStr + mLength;
|
|
|
|
PRUnichar* to = mStr;
|
|
|
|
|
|
|
|
while (from < end) {
|
|
|
|
PRUnichar ch = *from;
|
|
|
|
if(0==strchr(aSet,char(ch))) {
|
|
|
|
*to++=*from;
|
|
|
|
}
|
|
|
|
from++;
|
|
|
|
}
|
|
|
|
*to = '\0';
|
|
|
|
mLength = to - mStr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Determine if given char in valid alpha range
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
1998-08-04 00:46:38 +04:00
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if in alpha range
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::IsAlpha(PRUnichar aChar) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// XXX i18n
|
1998-08-04 00:46:38 +04:00
|
|
|
if (((aChar >= 'A') && (aChar <= 'Z')) || ((aChar >= 'a') && (aChar <= 'z'))) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Determine if given char is a valid space character
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
1998-08-04 00:46:38 +04:00
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if is valid space char
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::IsSpace(PRUnichar aChar) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// XXX i18n
|
1998-08-04 00:46:38 +04:00
|
|
|
if ((aChar == ' ') || (aChar == '\r') || (aChar == '\n') || (aChar == '\t')) {
|
1998-04-14 00:24:54 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Determine if given char is valid digit
|
1998-05-12 03:27:35 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
1998-08-04 00:46:38 +04:00
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if char is a valid digit
|
1999-05-06 09:13:08 +04:00
|
|
|
*/PRBool nsString1::IsDigit(PRUnichar aChar) {
|
1998-05-12 03:27:35 +04:00
|
|
|
// XXX i18n
|
1998-08-04 00:46:38 +04:00
|
|
|
return PRBool((aChar >= '0') && (aChar <= '9'));
|
1998-05-12 03:27:35 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* This method trims characters found in aTrimSet from
|
|
|
|
* either end of the underlying string.
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param aTrimSet -- contains chars to be trimmed from
|
|
|
|
* both ends
|
|
|
|
* @return this
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::Trim(const char* aTrimSet,
|
1998-10-10 19:28:53 +04:00
|
|
|
PRBool aEliminateLeading,
|
|
|
|
PRBool aEliminateTrailing)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PRUnichar* from = mStr;
|
|
|
|
PRUnichar* end = mStr + mLength-1;
|
|
|
|
PRUnichar* to = mStr;
|
|
|
|
|
|
|
|
//begin by find the first char not in aTrimSet
|
|
|
|
if(aEliminateLeading) {
|
|
|
|
while (from < end) {
|
|
|
|
PRUnichar ch = *from;
|
|
|
|
if(!strchr(aTrimSet,char(ch))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
from++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now, find last char not in aTrimSet
|
|
|
|
if(aEliminateTrailing) {
|
|
|
|
while(end> from) {
|
|
|
|
PRUnichar ch = *end;
|
|
|
|
if(!strchr(aTrimSet,char(ch))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
end--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//now rewrite your string without unwanted
|
|
|
|
//leading or trailing characters.
|
1998-08-07 06:11:13 +04:00
|
|
|
if (from != to) {
|
|
|
|
while (from <= end) {
|
|
|
|
*to++ = *from++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
to = ++end;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*to = '\0';
|
|
|
|
mLength = to - mStr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* This method strips whitespace from string.
|
|
|
|
* You can control whether whitespace is yanked from
|
|
|
|
* start and end of string as well.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
1998-08-04 00:46:38 +04:00
|
|
|
* @param aEliminateLeading controls stripping of leading ws
|
|
|
|
* @param aEliminateTrailing controls stripping of trailing ws
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::CompressWhitespace( PRBool aEliminateLeading,
|
1998-04-14 00:24:54 +04:00
|
|
|
PRBool aEliminateTrailing)
|
|
|
|
{
|
1999-02-11 09:22:03 +03:00
|
|
|
Trim(" \r\n\t",aEliminateLeading,aEliminateTrailing);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PRUnichar* from = mStr;
|
|
|
|
PRUnichar* end = mStr + mLength;
|
|
|
|
PRUnichar* to = from;
|
|
|
|
|
|
|
|
//this code converts /n, /t, /r into normal space ' ';
|
|
|
|
//it also eliminates runs of whitespace...
|
|
|
|
while (from < end) {
|
|
|
|
PRUnichar ch = *from++;
|
|
|
|
if (IsSpace(ch)) {
|
|
|
|
*to++ = ' ';
|
|
|
|
while (from < end) {
|
|
|
|
ch = *from++;
|
|
|
|
if (!IsSpace(ch)) {
|
|
|
|
*to++ = ch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*to++ = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*to = '\0';
|
|
|
|
mLength = to - mStr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* This method strips whitespace throughout the string
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::StripWhitespace()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
Trim(" \r\n\t");
|
|
|
|
return StripChars("\r\t\n");
|
|
|
|
}
|
|
|
|
|
1999-02-16 09:47:00 +03:00
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1& nsString1::ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar) {
|
|
|
|
|
1999-02-16 09:47:00 +03:00
|
|
|
PRUnichar* from = mStr;
|
|
|
|
PRUnichar* end = mStr + mLength;
|
|
|
|
|
|
|
|
while (from < end) {
|
|
|
|
PRUnichar ch = *from;
|
|
|
|
if(ch==aSourceChar) {
|
|
|
|
*from = aDestChar;
|
|
|
|
}
|
|
|
|
from++;
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
return *this;
|
1999-02-16 09:47:00 +03:00
|
|
|
}
|
|
|
|
|
1998-08-29 09:06:50 +04:00
|
|
|
/**
|
|
|
|
* Search for given character within this string.
|
|
|
|
* This method does so by using a binary search,
|
|
|
|
* so your string HAD BETTER BE ORDERED!
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param aChar is the unicode char to be found
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::BinarySearch(PRUnichar aChar) const {
|
1998-08-29 09:06:50 +04:00
|
|
|
PRInt32 low=0;
|
|
|
|
PRInt32 high=mLength-1;
|
|
|
|
|
|
|
|
while (low <= high) {
|
|
|
|
int middle = (low + high) >> 1;
|
|
|
|
if (mStr[middle]==aChar)
|
|
|
|
return middle;
|
|
|
|
if (mStr[middle]>aChar)
|
|
|
|
high = middle - 1;
|
|
|
|
else
|
|
|
|
low = middle + 1;
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Search for given buffer within this string
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCStringBuf - charstr to be found
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Find(const char* aCStringBuf) const{
|
1998-11-21 01:11:09 +03:00
|
|
|
NS_ASSERTION(0!=aCStringBuf,kNullPointerError);
|
1998-08-29 09:06:50 +04:00
|
|
|
PRInt32 result=kNotFound;
|
1998-11-21 01:11:09 +03:00
|
|
|
if(aCStringBuf) {
|
|
|
|
PRInt32 len=strlen(aCStringBuf);
|
1998-09-04 21:26:37 +04:00
|
|
|
if((0<len) && (len<=mLength)) { //only enter if abuffer length is <= mStr length.
|
|
|
|
PRInt32 max=mLength-len;
|
|
|
|
for(PRInt32 offset=0;offset<=max;offset++)
|
1998-11-21 01:11:09 +03:00
|
|
|
if(0==nsCRT::strncmp(&mStr[offset],aCStringBuf,len))
|
1998-04-14 00:24:54 +04:00
|
|
|
return offset; //in this case, 0 means they match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Search for given buffer within this string
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param aString - PUnichar* to be found
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Find(const PRUnichar* aString) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
1998-08-29 09:06:50 +04:00
|
|
|
PRInt32 result=kNotFound;
|
1998-04-14 00:24:54 +04:00
|
|
|
if(aString) {
|
|
|
|
PRInt32 len=nsCRT::strlen(aString);
|
1998-09-04 21:26:37 +04:00
|
|
|
if((0<len) && (len<=mLength)) { //only enter if abuffer length is <= mStr length.
|
|
|
|
PRInt32 max=mLength-len;
|
|
|
|
for(PRInt32 offset=0;offset<=max;offset++)
|
1998-04-14 00:24:54 +04:00
|
|
|
if(0==nsCRT::strncmp(&mStr[offset],aString,len))
|
|
|
|
return offset; //in this case, 0 means they match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Search for given buffer within this string
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param nsString1 -- buffer to be found
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Find(const nsString1& aString) const{
|
1998-08-29 09:06:50 +04:00
|
|
|
PRInt32 result=kNotFound;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
PRInt32 len=aString.mLength;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRInt32 offset=0;
|
|
|
|
if((0<len) && (len<=mLength)) { //only enter if abuffer length is <= mStr length.
|
|
|
|
PRInt32 max=mLength-len;
|
|
|
|
for(offset=0;offset<=max;offset++) {
|
1998-04-14 00:24:54 +04:00
|
|
|
if(0==nsCRT::strncmp(&mStr[offset],aString.mStr,len)) {
|
|
|
|
return offset; //in this case, 0 means they match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Search for a given char, starting at given offset
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Find(PRUnichar aChar, PRInt32 anOffset) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
for(PRInt32 i=anOffset;i<mLength;i++)
|
|
|
|
if(aChar==mStr[i])
|
|
|
|
return i;
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::FindCharInSet(const char* anAsciiSet,PRInt32 anOffset) const{
|
1998-11-21 01:11:09 +03:00
|
|
|
NS_ASSERTION(0!=anAsciiSet,kNullPointerError);
|
|
|
|
if(anAsciiSet && (strlen(anAsciiSet))) {
|
1998-04-14 00:24:54 +04:00
|
|
|
for(PRInt32 i=anOffset;i<mLength;i++){
|
1998-11-21 01:11:09 +03:00
|
|
|
char* pos=strchr(anAsciiSet,char(mStr[i]));
|
1998-04-14 00:24:54 +04:00
|
|
|
if(pos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::FindCharInSet(nsString1& aSet,PRInt32 anOffset) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
if(aSet.Length()) {
|
|
|
|
for(PRInt32 i=anOffset;i<mLength;i++){
|
|
|
|
PRInt32 pos=aSet.Find(mStr[i]);
|
|
|
|
if(kNotFound!=pos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::RFindCharInSet(const char* anAsciiSet,PRInt32 anOffset) const{
|
1998-11-21 01:11:09 +03:00
|
|
|
NS_ASSERTION(0!=anAsciiSet,kNullPointerError);
|
|
|
|
if(anAsciiSet && strlen(anAsciiSet)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
for(PRInt32 i=mLength-1;i>0;i--){
|
1998-11-21 01:11:09 +03:00
|
|
|
char* pos=strchr(anAsciiSet,char(mStr[i]));
|
1998-04-14 00:24:54 +04:00
|
|
|
if(pos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::RFindCharInSet(nsString1& aSet,PRInt32 anOffset) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
if(aSet.Length()) {
|
|
|
|
for(PRInt32 i=mLength-1;i>0;i--){
|
|
|
|
PRInt32 pos=aSet.Find(mStr[i]);
|
|
|
|
if(kNotFound!=pos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::RFind(const PRUnichar* aString,PRBool aIgnoreCase) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
|
|
|
|
|
|
|
if(aString) {
|
|
|
|
PRInt32 len=nsCRT::strlen(aString);
|
|
|
|
if((len) && (len<=mLength)) { //only enter if abuffer length is <= mStr length.
|
|
|
|
for(PRInt32 offset=mLength-len;offset>=0;offset--) {
|
|
|
|
PRInt32 result=0;
|
|
|
|
if(aIgnoreCase)
|
|
|
|
result=nsCRT::strncasecmp(&mStr[offset],aString,len);
|
|
|
|
else result=nsCRT::strncmp(&mStr[offset],aString,len);
|
|
|
|
if(0==result)
|
|
|
|
return offset; //in this case, 0 means they match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::RFind(const nsString1& aString,PRBool aIgnoreCase) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 len=aString.mLength;
|
|
|
|
if((len) && (len<=mLength)) { //only enter if abuffer length is <= mStr length.
|
|
|
|
for(PRInt32 offset=mLength-len;offset>=0;offset--) {
|
|
|
|
PRInt32 result=0;
|
|
|
|
if(aIgnoreCase)
|
|
|
|
result=nsCRT::strncasecmp(&mStr[offset],aString.mStr,len);
|
|
|
|
else result=nsCRT::strncmp(&mStr[offset],aString.mStr,len);
|
|
|
|
if(0==result)
|
|
|
|
return offset; //in this case, 0 means they match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::RFind(const char* anAsciiSet,PRBool aIgnoreCase) const{
|
1998-11-21 01:11:09 +03:00
|
|
|
NS_ASSERTION(0!=anAsciiSet,kNullPointerError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-11-21 01:11:09 +03:00
|
|
|
if(anAsciiSet) {
|
|
|
|
PRInt32 len=strlen(anAsciiSet);
|
1998-04-14 00:24:54 +04:00
|
|
|
if((len) && (len<=mLength)) { //only enter if abuffer length is <= mStr length.
|
|
|
|
for(PRInt32 offset=mLength-len;offset>=0;offset--) {
|
|
|
|
PRInt32 result=0;
|
|
|
|
if(aIgnoreCase)
|
1998-11-21 01:11:09 +03:00
|
|
|
result=nsCRT::strncasecmp(&mStr[offset],anAsciiSet,len);
|
|
|
|
else result=nsCRT::strncmp(&mStr[offset],anAsciiSet,len);
|
1998-04-14 00:24:54 +04:00
|
|
|
if(0==result)
|
|
|
|
return offset; //in this case, 0 means they match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Scans this string backwards for first occurance of
|
|
|
|
* the given char.
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
|
|
|
* @param
|
|
|
|
* @return offset of char in string, or -1 (kNotFound)
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::RFind(PRUnichar aChar,PRBool aIgnoreCase) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
chartype uc=nsCRT::ToUpper(aChar);
|
1999-03-05 03:03:46 +03:00
|
|
|
for(PRInt32 offset=mLength-1;offset>=0;offset--)
|
1998-04-14 00:24:54 +04:00
|
|
|
if(aIgnoreCase) {
|
|
|
|
if(nsCRT::ToUpper(mStr[offset])==uc)
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
else if(mStr[offset]==aChar)
|
|
|
|
return offset; //in this case, 0 means they match
|
|
|
|
return kNotFound;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**************************************************************
|
|
|
|
COMPARISON METHODS...
|
|
|
|
**************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares given cstring to this string.
|
|
|
|
* @update gess 7/27/98
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString pts to a cstring
|
1998-08-04 00:46:38 +04:00
|
|
|
* @param aIgnoreCase tells us how to treat case
|
|
|
|
* @return -1,0,1
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aLength) const {
|
1998-11-21 01:11:09 +03:00
|
|
|
NS_ASSERTION(0!=aCString,kNullPointerError);
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
if(-1!=aLength) {
|
|
|
|
|
|
|
|
//if you're given a length, use it to determine the max # of bytes to compare.
|
|
|
|
//In some cases, this can speed up the string comparison.
|
|
|
|
|
|
|
|
int maxlen=(aLength<mLength) ? aLength : mLength;
|
1998-11-04 09:48:11 +03:00
|
|
|
if (maxlen == 0) {
|
|
|
|
if ((mLength == 0) && (aLength == 0))
|
|
|
|
return 0;
|
|
|
|
if (mLength == 0)
|
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
if (aIgnoreCase) {
|
1998-11-21 01:11:09 +03:00
|
|
|
return nsCRT::strncasecmp(mStr,aCString,maxlen);
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
1998-11-21 01:11:09 +03:00
|
|
|
return nsCRT::strncmp(mStr,aCString,maxlen);
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
if (aIgnoreCase) {
|
1998-11-21 01:11:09 +03:00
|
|
|
return nsCRT::strcasecmp(mStr,aCString);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-11-21 01:11:09 +03:00
|
|
|
return nsCRT::strcmp(mStr,aCString);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* LAST MODS: gess
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Compare(const nsString1 &S,PRBool aIgnoreCase) const {
|
1998-08-04 00:46:38 +04:00
|
|
|
int maxlen=(S.mLength<mLength) ? S.mLength : mLength;
|
1998-11-04 09:48:11 +03:00
|
|
|
if (maxlen == 0) {
|
|
|
|
if ((mLength == 0) && (S.mLength == 0))
|
|
|
|
return 0;
|
|
|
|
if (mLength == 0)
|
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if (aIgnoreCase) {
|
1999-01-10 11:17:40 +03:00
|
|
|
return nsCRT::strcasecmp(mStr,S.mStr);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-01-10 11:17:40 +03:00
|
|
|
return nsCRT::strcmp(mStr,S.mStr);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 nsString1::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aLength) const {
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
|
|
|
if(-1!=aLength) {
|
|
|
|
|
|
|
|
//if you're given a length, use it to determine the max # of bytes to compare.
|
|
|
|
//In some cases, this can speed up the string comparison.
|
|
|
|
|
|
|
|
int maxlen=(aLength<mLength) ? aLength : mLength;
|
1998-11-04 09:48:11 +03:00
|
|
|
if (maxlen == 0) {
|
|
|
|
if ((mLength == 0) && (aLength == 0))
|
|
|
|
return 0;
|
|
|
|
if (mLength == 0)
|
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
if (aIgnoreCase) {
|
|
|
|
return nsCRT::strncasecmp(mStr,aString,maxlen);
|
|
|
|
}
|
|
|
|
return nsCRT::strncmp(mStr,aString,maxlen);
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
if (aIgnoreCase) {
|
|
|
|
return nsCRT::strcasecmp(mStr,aString);
|
|
|
|
}
|
|
|
|
return nsCRT::strcmp(mStr,aString);
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::operator==(const nsString1 &S) const {return Equals(S);}
|
|
|
|
PRBool nsString1::operator==(const char *s) const {return Equals(s);}
|
|
|
|
PRBool nsString1::operator==(const PRUnichar *s) const {return Equals(s);}
|
|
|
|
PRBool nsString1::operator==(PRUnichar *s) const {return Equals(s);}
|
|
|
|
PRBool nsString1::operator!=(const nsString1 &S) const {return PRBool(Compare(S)!=0);}
|
|
|
|
PRBool nsString1::operator!=(const char *s) const {return PRBool(Compare(s)!=0);}
|
|
|
|
PRBool nsString1::operator!=(const PRUnichar *s) const {return PRBool(Compare(s)!=0);}
|
|
|
|
PRBool nsString1::operator<(const nsString1 &S) const {return PRBool(Compare(S)<0);}
|
|
|
|
PRBool nsString1::operator<(const char *s) const {return PRBool(Compare(s)<0);}
|
|
|
|
PRBool nsString1::operator<(const PRUnichar *s) const {return PRBool(Compare(s)<0);}
|
|
|
|
PRBool nsString1::operator>(const nsString1 &S) const {return PRBool(Compare(S)>0);}
|
|
|
|
PRBool nsString1::operator>(const char *s) const {return PRBool(Compare(s)>0);}
|
|
|
|
PRBool nsString1::operator>(const PRUnichar *s) const {return PRBool(Compare(s)>0);}
|
|
|
|
PRBool nsString1::operator<=(const nsString1 &S) const {return PRBool(Compare(S)<=0);}
|
|
|
|
PRBool nsString1::operator<=(const char *s) const {return PRBool(Compare(s)<=0);}
|
|
|
|
PRBool nsString1::operator<=(const PRUnichar *s) const {return PRBool(Compare(s)<=0);}
|
|
|
|
PRBool nsString1::operator>=(const nsString1 &S) const {return PRBool(Compare(S)>=0);}
|
|
|
|
PRBool nsString1::operator>=(const char *s) const {return PRBool(Compare(s)>=0);}
|
|
|
|
PRBool nsString1::operator>=(const PRUnichar *s) const {return PRBool(Compare(s)>=0);}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare this to given string; note that we compare full strings here.
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param aString is the other nsString1 to be compared to
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return TRUE if equal
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::Equals(const nsString1& aString) const {
|
1998-08-04 00:46:38 +04:00
|
|
|
if(aString.mLength==mLength) {
|
|
|
|
PRInt32 result=nsCRT::strcmp(mStr,aString.mStr);
|
|
|
|
return PRBool(0==result);
|
1998-07-31 00:36:51 +04:00
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Compare this to given string; note that we compare full strings here.
|
|
|
|
* The optional length argument just lets us know how long the given string is.
|
|
|
|
* If you provide a length, it is compared to length of this string as an
|
|
|
|
* optimization.
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aCString -- Cstr to compare to this
|
1998-08-04 00:46:38 +04:00
|
|
|
* @param aLength -- length of given string.
|
1998-04-14 00:24:54 +04:00
|
|
|
* @return TRUE if equal
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::Equals(const char* aCString,PRInt32 aLength) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(0!=aCString,kNullPointerError);
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
if((aLength>0) && (aLength!=mLength))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 result=nsCRT::strcmp(mStr,aCString);
|
|
|
|
return PRBool(0==result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Compare this to given atom
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aAtom -- atom to compare to this
|
|
|
|
* @return TRUE if equal
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::Equals(const nsIAtom* aAtom) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
|
|
|
PRInt32 result=nsCRT::strcmp(mStr,aAtom->GetUnicode());
|
|
|
|
return PRBool(0==result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
* Compare given strings
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param s1 -- first string to be compared
|
|
|
|
* @param s2 -- second string to be compared
|
|
|
|
* @return TRUE if equal
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::Equals(const PRUnichar* s1, const PRUnichar* s2) const {
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(0!=s1,kNullPointerError);
|
|
|
|
NS_ASSERTION(0!=s2,kNullPointerError);
|
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if((s1) && (s2)){
|
|
|
|
PRInt32 cmp=nsCRT::strcmp(s1,s2);
|
|
|
|
result=PRBool(0==cmp);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Compares all chars in both strings w/o regard to case
|
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::EqualsIgnoreCase(const nsString1& aString) const{
|
1998-08-04 00:46:38 +04:00
|
|
|
if(aString.mLength==mLength) {
|
|
|
|
PRInt32 result=nsCRT::strcasecmp(mStr,aString.mStr);
|
|
|
|
return PRBool(0==result);
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::EqualsIgnoreCase(const nsIAtom *aAtom) const{
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if(aAtom){
|
|
|
|
PRInt32 cmp=nsCRT::strcasecmp(mStr,aAtom->GetUnicode());
|
|
|
|
result=PRBool(0==cmp);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Compares given unicode string to this w/o regard to case
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param s1 is the unicode string to be compared with this
|
|
|
|
* @param aLength is the length of s1, not # of bytes to compare
|
|
|
|
* @return true if full length of both strings are equal (modulo case)
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const {
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(0!=s1,kNullPointerError);
|
|
|
|
NS_ASSERTION(0!=s2,kNullPointerError);
|
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if((s1) && (s2)){
|
|
|
|
PRInt32 cmp=nsCRT::strcasecmp(s1,s2);
|
|
|
|
result=PRBool(0==cmp);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
* Compare this to given string w/o regard to case; note that we compare full strings here.
|
|
|
|
* The optional length argument just lets us know how long the given string is.
|
|
|
|
* If you provide a length, it is compared to length of this string as an optimization.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aCString -- Cstr to compare to this
|
|
|
|
* @param aLength -- length of given string.
|
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
PRBool nsString1::EqualsIgnoreCase(const char* aCString,PRInt32 aLength) const {
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(0!=aCString,kNullPointerError);
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
if((aLength>0) && (aLength!=mLength))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRInt32 cmp=nsCRT::strcasecmp(mStr,aCString);
|
|
|
|
return PRBool(0==cmp);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::DebugDump(ostream& aStream) const {
|
1998-04-14 00:24:54 +04:00
|
|
|
for(int i=0;i<mLength;i++) {
|
|
|
|
aStream <<char(mStr[i]);
|
|
|
|
}
|
|
|
|
aStream << endl;
|
|
|
|
}
|
|
|
|
|
1998-08-22 21:50:13 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess8/8/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
ostream& operator<<(ostream& os,nsString1& aString){
|
1998-08-22 21:50:13 +04:00
|
|
|
const PRUnichar* uc=aString.GetUnicode();
|
|
|
|
int len=aString.Length();
|
|
|
|
for(int i=0;i<len;i++)
|
|
|
|
os<<(char)uc[i];
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-09-06 03:21:42 +04:00
|
|
|
#define INIT_AUTO_STRING() \
|
|
|
|
mLength = 0; \
|
|
|
|
mCapacity = (sizeof(mBuf) / sizeof(chartype))-sizeof(chartype); \
|
1999-05-06 09:13:08 +04:00
|
|
|
mStr = mBuf; \
|
|
|
|
mBuf[0]=0
|
1998-09-06 03:21:42 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::nsAutoString1()
|
|
|
|
: nsString1()
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
1998-09-06 03:21:42 +04:00
|
|
|
INIT_AUTO_STRING();
|
1998-08-04 00:46:38 +04:00
|
|
|
mStr[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1998-08-04 00:46:38 +04:00
|
|
|
* @update gess 7/27/98
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-04 00:46:38 +04:00
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::nsAutoString1(const char* aCString)
|
|
|
|
: nsString1()
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
1998-09-06 03:21:42 +04:00
|
|
|
INIT_AUTO_STRING();
|
1998-11-21 01:11:09 +03:00
|
|
|
SetString(aCString);
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::nsAutoString1(const nsString1& other)
|
|
|
|
: nsString1()
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
1998-09-06 03:21:42 +04:00
|
|
|
INIT_AUTO_STRING();
|
1998-08-04 00:46:38 +04:00
|
|
|
SetString(other.GetUnicode(),other.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::nsAutoString1(PRUnichar aChar)
|
|
|
|
: nsString1()
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
1998-09-06 03:21:42 +04:00
|
|
|
INIT_AUTO_STRING();
|
1998-08-04 00:46:38 +04:00
|
|
|
Append(aChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::nsAutoString1(const nsAutoString1& other)
|
|
|
|
: nsString1()
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
1998-09-06 03:21:42 +04:00
|
|
|
INIT_AUTO_STRING();
|
1998-08-04 00:46:38 +04:00
|
|
|
SetString(other.GetUnicode(),other.mLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::nsAutoString1(const PRUnichar* unicode, PRInt32 uslen)
|
|
|
|
: nsString1()
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
1998-09-06 03:21:42 +04:00
|
|
|
INIT_AUTO_STRING();
|
|
|
|
Append(unicode, uslen ? uslen : nsCRT::strlen(unicode));
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::~nsAutoString1()
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
|
|
|
if (mStr == mBuf) {
|
|
|
|
// Force to null so that baseclass dtor doesn't do damage
|
|
|
|
mStr = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-06 03:21:42 +04:00
|
|
|
/**
|
1999-05-06 09:13:08 +04:00
|
|
|
* nsAutoString1's buffer growing routine uses a different algorithm
|
|
|
|
* than nsString1 because the lifetime of the auto string is assumed
|
1998-09-06 03:21:42 +04:00
|
|
|
* to be shorter. Therefore, we double the size of the buffer each
|
|
|
|
* time we grow so that (hopefully) we quickly get to the right
|
|
|
|
* size.
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsAutoString1::EnsureCapacityFor(PRInt32 aNewLength) {
|
1998-09-06 03:21:42 +04:00
|
|
|
if (aNewLength > mCapacity) {
|
|
|
|
PRInt32 size = mCapacity * 2;
|
|
|
|
if (size < aNewLength) {
|
|
|
|
size = mCapacity + aNewLength;
|
|
|
|
}
|
|
|
|
mCapacity=size;
|
|
|
|
chartype* temp = new chartype[mCapacity+1];
|
|
|
|
if (mLength > 0) {
|
|
|
|
nsCRT::memcpy(temp, mStr, mLength * sizeof(chartype) + sizeof(chartype));
|
|
|
|
}
|
|
|
|
if ((mStr != mBuf) && (0 != mStr)) {
|
|
|
|
delete [] mStr;
|
|
|
|
}
|
|
|
|
mStr = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
void
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1::SizeOf(nsISizeOfHandler* aHandler) const
|
1998-08-04 00:46:38 +04:00
|
|
|
{
|
|
|
|
aHandler->Add(sizeof(*this));
|
|
|
|
if (mStr != mBuf) {
|
|
|
|
aHandler->Add(mCapacity * sizeof(chartype));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsAutoString1::SelfTest(){
|
|
|
|
nsAutoString1 xas("Hello there");
|
1998-08-04 00:46:38 +04:00
|
|
|
xas.Append("this string exceeds the max size");
|
|
|
|
xas.DebugDump(cout);
|
|
|
|
}
|
|
|
|
|
1998-08-22 21:50:13 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess8/8/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
ostream& operator<<(ostream& os,nsAutoString1& aString){
|
1998-08-22 21:50:13 +04:00
|
|
|
const PRUnichar* uc=aString.GetUnicode();
|
|
|
|
int len=aString.Length();
|
|
|
|
for(int i=0;i<len;i++)
|
|
|
|
os<<(char)uc[i];
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
NS_BASE int fputs(const nsString1& aString, FILE* out){
|
|
|
|
char buf[200];
|
1998-08-04 00:46:38 +04:00
|
|
|
char* cp = buf;
|
1999-05-06 09:13:08 +04:00
|
|
|
PRInt32 aLength=aString.Length();
|
|
|
|
if (aLength >= PRInt32(sizeof(buf))) {
|
1998-08-04 00:46:38 +04:00
|
|
|
cp = aString.ToNewCString();
|
|
|
|
} else {
|
1999-05-06 09:13:08 +04:00
|
|
|
aString.ToCString(cp, aLength + 1);
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
if(aLength >0)
|
|
|
|
::fwrite(cp, 1, aLength, out);
|
1998-08-04 00:46:38 +04:00
|
|
|
if (cp != buf) {
|
1999-02-27 23:39:07 +03:00
|
|
|
delete [] cp;
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
return (int) aLength;
|
1998-08-04 00:46:38 +04:00
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-05-06 09:13:08 +04:00
|
|
|
void nsString1::SelfTest(void) {
|
1999-01-10 11:17:40 +03:00
|
|
|
|
1999-04-25 05:27:51 +04:00
|
|
|
#ifdef RICKG_DEBUG
|
1999-04-25 05:24:10 +04:00
|
|
|
mSelfTested=PR_TRUE;
|
1999-05-06 09:13:08 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
nsAutoString1 a("foobar");
|
|
|
|
nsAutoString1 b("foo");
|
|
|
|
nsAutoString1 c(".5111");
|
|
|
|
nsAutoString1 d(" 5");
|
|
|
|
PRInt32 result=a.Compare(b);
|
|
|
|
PRInt32 result2=result;
|
|
|
|
result=c.ToInteger(&result2);
|
|
|
|
result=d.ToInteger(&result2);
|
|
|
|
result2=result;
|
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
|
|
|
|
static const char* kConstructorError = kConstructorError;
|
|
|
|
static const char* kComparisonError = "Comparision error!";
|
|
|
|
static const char* kEqualsError = "Equals error!";
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1 as("Hello there");
|
1998-04-14 00:24:54 +04:00
|
|
|
as.SelfTest();
|
|
|
|
|
|
|
|
static const char* temp="hello";
|
|
|
|
|
|
|
|
//first, let's test the constructors...
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 empty;
|
1998-08-04 01:03:49 +04:00
|
|
|
empty="";
|
|
|
|
empty="xxx";
|
|
|
|
empty="";
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 a(temp);
|
|
|
|
nsString1* a_=new nsString1(a); //test copy constructor
|
|
|
|
nsString1 b("world!");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//verify destructor...
|
|
|
|
delete a_;
|
|
|
|
a_=0;
|
|
|
|
|
|
|
|
//Let's verify the Length() method...
|
|
|
|
NS_ASSERTION(5==a.Length(),"Error: constructor probably bad!");
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Let's check out the ACCESSORS...
|
|
|
|
//**********************************************
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
const chartype* p1=a.GetUnicode();
|
1998-04-14 00:24:54 +04:00
|
|
|
for(int i=0;i<a.Length();i++) {
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(a[i]==temp[i],kConstructorError); //test [] operator
|
|
|
|
NS_ASSERTION(a.CharAt(i)==temp[i],kConstructorError); //test charAt method
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(a.First()==temp[0],kConstructorError);
|
|
|
|
NS_ASSERTION(a.Last()==temp[a.Length()-1],kConstructorError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Now let's test the CREATION operators...
|
|
|
|
//**********************************************
|
|
|
|
|
|
|
|
static const char* temp1="helloworld!";
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp2=a+b;
|
|
|
|
nsString1 temp3=a+"world!";
|
|
|
|
nsString1 temp4=temp2+'!';
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//let's quick check the PRUnichar operator+ method...
|
1998-08-04 00:46:38 +04:00
|
|
|
const PRUnichar* uc=temp4.GetUnicode();
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp4a("Begin");
|
1998-04-14 00:24:54 +04:00
|
|
|
temp4a.DebugDump(cout);
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp4b=temp4a+uc;
|
1998-04-14 00:24:54 +04:00
|
|
|
temp4b.DebugDump(cout);
|
|
|
|
|
|
|
|
temp2.DebugDump(cout);
|
|
|
|
temp3.DebugDump(cout);
|
|
|
|
temp4.DebugDump(cout);
|
|
|
|
for(i=0;i<temp2.Length();i++) {
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp1[i]==temp2[i],kConstructorError);
|
|
|
|
NS_ASSERTION(temp1[i]==temp3[i],kConstructorError);
|
|
|
|
NS_ASSERTION(temp1[i]==temp4[i],kConstructorError);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp4.Last()=='!',kConstructorError);
|
|
|
|
NS_ASSERTION(temp4.Length()>temp3.Length(),kConstructorError); //should be char longer
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1* es1=temp2.ToNewString(); //this should make us a new string
|
1998-04-14 00:24:54 +04:00
|
|
|
char* es2=temp2.ToNewCString();
|
|
|
|
for(i=0;i<temp2.Length();i++) {
|
|
|
|
NS_ASSERTION(es2[i]==(*es1)[i],"Creation error!");
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp5("123.123");
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 error=0;
|
|
|
|
float f=temp5.ToFloat(&error);
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp6("1234");
|
1998-04-14 00:24:54 +04:00
|
|
|
error=0;
|
|
|
|
PRInt32 theInt=temp6.ToInteger(&error);
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Now let's test a few string COMPARISION ops...
|
|
|
|
//**********************************************
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 sourceString("Hello how are you");
|
|
|
|
nsString1 subString("you");
|
|
|
|
nsString1 replacementStr("xxx");
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
PRInt32 offset = sourceString.Find(subString);
|
|
|
|
sourceString.Cut(offset, subString.Length());
|
|
|
|
sourceString.Insert(replacementStr, offset, replacementStr.Length()); // Offset isn't checked in Insert either
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Now let's test a few string COMPARISION ops...
|
|
|
|
//**********************************************
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp8("aaaa");
|
|
|
|
nsString1 temp8a("AAAA");
|
|
|
|
nsString1 temp9("bbbb");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
const char* aaaa="aaaa";
|
|
|
|
const char* bbbb="bbbb";
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
//First test the string compare routines...
|
1998-08-04 01:03:49 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(0>temp8.Compare(temp9),kComparisonError);
|
|
|
|
NS_ASSERTION(0<temp9.Compare(temp8),kComparisonError);
|
|
|
|
NS_ASSERTION(0==temp8.Compare(temp8a,PR_TRUE),kComparisonError);
|
|
|
|
NS_ASSERTION(0==temp8.Compare(aaaa),kComparisonError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
//Now test the boolean operators...
|
|
|
|
NS_ASSERTION(temp8==temp8,kComparisonError);
|
|
|
|
NS_ASSERTION(temp8==aaaa,kComparisonError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp8!=temp9,kComparisonError);
|
|
|
|
NS_ASSERTION(temp8!=bbbb,kComparisonError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp8<temp9,kComparisonError);
|
|
|
|
NS_ASSERTION(temp8<bbbb,kComparisonError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp9>temp8,kComparisonError);
|
|
|
|
NS_ASSERTION(temp9>aaaa,kComparisonError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp8<=temp8,kComparisonError);
|
|
|
|
NS_ASSERTION(temp8<=temp9,kComparisonError);
|
|
|
|
NS_ASSERTION(temp8<=bbbb,kComparisonError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp9>=temp9,kComparisonError);
|
|
|
|
NS_ASSERTION(temp9>=temp8,kComparisonError);
|
|
|
|
NS_ASSERTION(temp9>=aaaa,kComparisonError);
|
|
|
|
|
|
|
|
NS_ASSERTION(temp8.Equals(temp8),kEqualsError);
|
|
|
|
NS_ASSERTION(temp8.Equals(aaaa),kEqualsError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp10(temp8);
|
1998-04-14 00:24:54 +04:00
|
|
|
temp10.ToUpperCase();
|
1998-08-04 00:46:38 +04:00
|
|
|
NS_ASSERTION(temp8.EqualsIgnoreCase(temp10),kEqualsError);
|
|
|
|
NS_ASSERTION(temp8.EqualsIgnoreCase("AAAA"),kEqualsError);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Now let's test a few string MANIPULATORS...
|
|
|
|
//**********************************************
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1 ab("ab");
|
|
|
|
nsString1 abcde("cde");
|
1998-04-14 00:24:54 +04:00
|
|
|
abcde.Insert(ab,0,2);
|
1999-05-06 09:13:08 +04:00
|
|
|
nsAutoString1 xxx("xxx");
|
1998-04-14 00:24:54 +04:00
|
|
|
abcde.Insert(xxx,2,3);
|
|
|
|
|
|
|
|
temp2.ToUpperCase();
|
|
|
|
for(i=0;i<temp2.Length();i++) {
|
|
|
|
NS_ASSERTION(nsCRT::ToUpper(temp1[i])==temp2[i],"ToUpper error!");
|
|
|
|
}
|
|
|
|
temp2.ToLowerCase();
|
|
|
|
for(i=0;i<temp2.Length();i++) {
|
|
|
|
NS_ASSERTION(temp1[i]==temp2[i],"ToLower error!");
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp7(temp2);
|
1998-04-14 00:24:54 +04:00
|
|
|
temp2.ToUpperCase(temp7);
|
|
|
|
for(i=0;i<temp2.Length();i++) {
|
|
|
|
NS_ASSERTION(nsCRT::ToUpper(temp1[i])==temp7[i],"ToLower error!");
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 cut("abcdef");
|
1998-04-14 00:24:54 +04:00
|
|
|
cut.Cut(7,10); //this is out of bounds, so ignore...
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
cut.Cut(5,2); //cut last chars
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
cut.Cut(1,1); //cut first char
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
cut.Cut(2,1); //cut one from the middle
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
cut="Hello there Rick";
|
|
|
|
cut.StripChars("Re"); //remove the R and e characters...
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
|
|
|
|
cut="'\"abcdef\"'";
|
|
|
|
cut.Trim("'");
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
cut.Trim("\"",PR_TRUE,PR_FALSE);
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
cut.Trim("\"",PR_FALSE,PR_TRUE);
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
|
|
|
|
cut="abc def\n\n ghi";
|
|
|
|
cut.StripWhitespace();
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
cut="abc def\n\n ghi";
|
|
|
|
cut.CompressWhitespace();
|
|
|
|
cut.DebugDump(cout);
|
|
|
|
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Now let's test the ASSIGNMENT operators...
|
|
|
|
//**********************************************
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp12;
|
|
|
|
nsString1 temp13;
|
|
|
|
nsString1 temp14;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
temp12 = a; //test assignment from another string ("hello")
|
|
|
|
temp13= "Hello world!"; //test assignment from char*
|
|
|
|
temp14 = '?'; //test assignment from char
|
|
|
|
|
1998-08-04 00:46:38 +04:00
|
|
|
const PRUnichar* uni=temp4.GetUnicode();
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp14a;
|
1998-04-14 00:24:54 +04:00
|
|
|
temp14a=uni; //test PRUnichar assignment operator...
|
|
|
|
temp14a.DebugDump(cout);
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Now let's test the APPENDING operators...
|
|
|
|
//**********************************************
|
|
|
|
|
|
|
|
temp14a+=uni; //test PRUnichar append operator (+=)
|
|
|
|
temp14a.DebugDump(cout);
|
|
|
|
|
|
|
|
temp12+=temp2; //append another string
|
|
|
|
temp12.DebugDump(cout);
|
|
|
|
temp13+="What!"; //append a char*
|
|
|
|
temp13.DebugDump(cout);
|
|
|
|
temp14+='?'; //append a char
|
|
|
|
temp14.DebugDump(cout);
|
|
|
|
|
|
|
|
temp14.Append(1000,10); //append an int
|
|
|
|
temp14.DebugDump(cout);
|
|
|
|
float f1=123.55f;
|
|
|
|
temp14.Append(f1); //append a float
|
|
|
|
temp14.DebugDump(cout);
|
|
|
|
|
|
|
|
//**********************************************
|
|
|
|
//Now let's test the SEARCHING operations...
|
|
|
|
//**********************************************
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsString1 temp15("abcdefghijklmnopqrstuvwxyzabc");
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 pos=temp15.Find("efg");
|
|
|
|
NS_ASSERTION(pos==4,"Error: Find routine");
|
|
|
|
|
|
|
|
pos=temp15.Find(PRUnichar('r'));
|
|
|
|
NS_ASSERTION(pos==17,"Error: Find char routine");
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
pos=temp15.FindCharInSet("12k");
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(pos==10,"Error: FindFirstInChar routine");
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
pos=temp15.RFindCharInSet("12k");
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_ASSERTION(pos==10,"Error: FindLastInChar routine");
|
|
|
|
|
|
|
|
pos=temp15.RFind("abc");
|
|
|
|
NS_ASSERTION(pos==26,"Error: RFind routine");
|
|
|
|
|
|
|
|
pos=temp15.RFind("xxx");
|
|
|
|
NS_ASSERTION(pos==-1,"Error: RFind routine"); //this should fail
|
|
|
|
|
|
|
|
pos=temp15.RFind("");
|
|
|
|
NS_ASSERTION(pos==-1,"Error: RFind routine"); //this too should fail.
|
|
|
|
|
|
|
|
pos=temp15.RFind(PRUnichar('a'));
|
|
|
|
NS_ASSERTION(pos==26,"Error: RFind routine");
|
|
|
|
#endif
|
|
|
|
}
|