1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-03-22 12:54:46 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1999-05-06 09:13:08 +04:00
|
|
|
#include <string.h>
|
1999-09-20 09:32:36 +04:00
|
|
|
#include <stdlib.h>
|
1999-07-17 11:26:16 +04:00
|
|
|
#include "nsString.h"
|
1999-03-22 12:54:46 +03:00
|
|
|
#include "nsDebug.h"
|
1999-03-23 10:26:27 +03:00
|
|
|
#include "nsDeque.h"
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
#include "prdtoa.h"
|
|
|
|
#include "nsISizeOfHandler.h"
|
1999-07-19 07:10:41 +04:00
|
|
|
#endif
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|
2000-02-19 12:17:49 +03:00
|
|
|
static const char* kPossibleNull = "Error: possible unintended null in string";
|
1999-03-22 12:54:46 +03:00
|
|
|
static const char* kNullPointerError = "Error: unexpected null ptr";
|
|
|
|
static const char* kWhitespace="\b\t\r\n ";
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
static void Subsume(nsStr& aDest,nsStr& aSource){
|
1999-05-07 04:47:24 +04:00
|
|
|
if(aSource.mStr && aSource.mLength) {
|
|
|
|
if(aSource.mOwnsBuffer){
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Destroy(aDest);
|
1999-05-07 04:47:24 +04:00
|
|
|
aDest.mStr=aSource.mStr;
|
|
|
|
aDest.mLength=aSource.mLength;
|
|
|
|
aDest.mCharSize=aSource.mCharSize;
|
|
|
|
aDest.mCapacity=aSource.mCapacity;
|
|
|
|
aDest.mOwnsBuffer=aSource.mOwnsBuffer;
|
1999-05-07 06:21:43 +04:00
|
|
|
aSource.mOwnsBuffer=PR_FALSE;
|
1999-05-07 04:47:24 +04:00
|
|
|
aSource.mStr=0;
|
|
|
|
}
|
|
|
|
else{
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Assign(aDest,aSource,0,aSource.mLength);
|
1999-05-07 04:47:24 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-05 08:47:19 +04:00
|
|
|
else nsStr::Truncate(aDest,0);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-05-07 04:47:24 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Default constructor.
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-10-05 08:47:19 +04:00
|
|
|
nsString::nsString() {
|
1999-09-02 11:04:59 +04:00
|
|
|
nsStr::Initialize(*this,eTwoByte);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor accepts an ascii string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 1/4/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aCString is a ptr to a 1-byte cstr
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aLength tells us how many chars to copy from given CString
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-11-14 09:22:52 +03:00
|
|
|
nsString::nsString(const char* aCString,PRInt32 aCount){
|
1999-09-02 11:04:59 +04:00
|
|
|
nsStr::Initialize(*this,eTwoByte);
|
1999-11-14 09:22:52 +03:00
|
|
|
Assign(aCString,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* This constructor accepts a unicode string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 1/4/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aString is a ptr to a unichar string
|
|
|
|
* @param aLength tells us how many chars to copy from given aString
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-11-14 09:22:52 +03:00
|
|
|
nsString::nsString(const PRUnichar* aString,PRInt32 aCount) {
|
1999-08-30 10:55:13 +04:00
|
|
|
nsStr::Initialize(*this,eTwoByte);
|
1999-11-14 09:22:52 +03:00
|
|
|
Assign(aString,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* This constructor works for all other nsSTr derivatives
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 1/4/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param reference to another nsCString
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-10-05 08:47:19 +04:00
|
|
|
nsString::nsString(const nsStr &aString) {
|
1999-09-02 11:04:59 +04:00
|
|
|
nsStr::Initialize(*this,eTwoByte);
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Assign(*this,aString,0,aString.mLength);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is our copy constructor
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 1/4/99
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param reference to another nsString
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-10-05 08:47:19 +04:00
|
|
|
nsString::nsString(const nsString& aString) {
|
1999-08-30 10:55:13 +04:00
|
|
|
nsStr::Initialize(*this,eTwoByte);
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Assign(*this,aString,0,aString.mLength);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* construct from subsumeable string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 1/4/99
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param reference to a subsumeString
|
|
|
|
*/
|
1999-11-12 06:58:15 +03:00
|
|
|
#ifdef AIX
|
|
|
|
nsString::nsString(const nsSubsumeStr& aSubsumeStr) {
|
|
|
|
nsStr::Initialize(*this,eTwoByte);
|
|
|
|
|
|
|
|
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
|
|
|
Subsume(*this,temp);
|
|
|
|
#else
|
1999-10-05 08:47:19 +04:00
|
|
|
nsString::nsString(nsSubsumeStr& aSubsumeStr) {
|
1999-09-19 20:43:09 +04:00
|
|
|
nsStr::Initialize(*this,eTwoByte);
|
1999-11-12 06:58:15 +03:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
Subsume(*this,aSubsumeStr);
|
1999-11-12 06:58:15 +03:00
|
|
|
#endif /* AIX */
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
* Make sure we call nsStr::Destroy.
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString::~nsString() {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Destroy(*this);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-08-31 07:04:37 +04:00
|
|
|
void nsString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method truncates this string to given length.
|
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param anIndex -- new length of string
|
|
|
|
* @return nada
|
|
|
|
*/
|
2000-02-24 11:20:03 +03:00
|
|
|
void nsString::Truncate(PRUint32 anIndex) {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Truncate(*this,anIndex);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not the characters in this
|
|
|
|
* string are in sorted order.
|
|
|
|
*
|
|
|
|
* @update gess 8/25/98
|
|
|
|
* @return TRUE if ordered.
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::IsOrdered(void) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
PRBool result=PR_TRUE;
|
|
|
|
if(mLength>1) {
|
|
|
|
PRUint32 theIndex;
|
|
|
|
PRUnichar c1=0;
|
1999-04-06 01:38:50 +04:00
|
|
|
PRUnichar c2=GetCharAt(*this,0);
|
1999-03-22 12:54:46 +03:00
|
|
|
for(theIndex=1;theIndex<mLength;theIndex++) {
|
|
|
|
c1=c2;
|
1999-04-06 01:38:50 +04:00
|
|
|
c2=GetCharAt(*this,theIndex);
|
1999-03-22 12:54:46 +03:00
|
|
|
if(c1>c2) {
|
|
|
|
result=PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method if you want to force the string to a certain capacity
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 1/4/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aLength -- contains new length for mStr
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
void nsString::SetCapacity(PRUint32 aLength) {
|
|
|
|
if(aLength>mCapacity) {
|
1999-10-05 08:47:19 +04:00
|
|
|
GrowCapacity(*this,aLength);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
AddNullTerminator(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Accessor methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
|
1999-03-23 03:28:36 +03:00
|
|
|
//static char gChar=0;
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
/**
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess1/4/99
|
1999-05-06 09:13:08 +04:00
|
|
|
* @return ptr to internal buffer (if 1-byte), otherwise NULL
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
const char* nsString::GetBuffer(void) const {
|
1999-06-03 14:49:14 +04:00
|
|
|
const char* result=(eOneByte==mCharSize) ? mStr : 0;
|
|
|
|
return result;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
1999-07-17 11:26:16 +04:00
|
|
|
* This method returns the internal unicode buffer.
|
|
|
|
* Now that we've factored the string class, this should never
|
|
|
|
* be able to return a 1 byte string.
|
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess1/4/99
|
1999-07-17 11:26:16 +04:00
|
|
|
* @return ptr to internal (2-byte) buffer;
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
const PRUnichar* nsString::GetUnicode(void) const {
|
|
|
|
const PRUnichar* result=(eOneByte==mCharSize) ? 0 : mUStr;
|
1999-06-03 14:49:14 +04:00
|
|
|
return result;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get nth character.
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRUnichar nsString::operator[](PRUint32 anIndex) const {
|
1999-04-06 01:38:50 +04:00
|
|
|
return GetCharAt(*this,anIndex);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
/**
|
|
|
|
* Get nth character.
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRUnichar nsString::CharAt(PRUint32 anIndex) const {
|
1999-04-06 01:38:50 +04:00
|
|
|
return GetCharAt(*this,anIndex);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
/**
|
|
|
|
* Get 1st character.
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRUnichar nsString::First(void) const{
|
1999-04-06 01:38:50 +04:00
|
|
|
return GetCharAt(*this,0);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
/**
|
|
|
|
* Get last character.
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRUnichar nsString::Last(void) const{
|
1999-04-06 01:38:50 +04:00
|
|
|
return GetCharAt(*this,mLength-1);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
/**
|
|
|
|
* set a char inside this string at given index
|
|
|
|
* @param aChar is the char you want to write into this string
|
|
|
|
* @param anIndex is the ofs where you want to write the given char
|
|
|
|
* @return TRUE if successful
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
1999-03-22 12:54:46 +03:00
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if(anIndex<mLength){
|
1999-06-03 14:49:14 +04:00
|
|
|
if(eOneByte==mCharSize)
|
1999-07-17 11:26:16 +04:00
|
|
|
mStr[anIndex]=char(aChar);
|
1999-03-23 10:33:10 +03:00
|
|
|
else mUStr[anIndex]=aChar;
|
1999-07-25 21:21:14 +04:00
|
|
|
|
|
|
|
// SOON! if(0==aChar) mLength=anIndex;
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
result=PR_TRUE;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-11-14 09:22:52 +03:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/*********************************************************
|
|
|
|
append (operator+) METHODS....
|
|
|
|
*********************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new string by appending given string to this
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString -- 2nd string to be appended
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return new subsumeable string (this makes things faster by reducing copying)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsSubsumeStr nsString::operator+(const nsStr& aString){
|
|
|
|
nsString temp(*this); //make a temp string the same size as this...
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(temp,aString,0,aString.mLength);
|
1999-05-06 09:13:08 +04:00
|
|
|
return nsSubsumeStr(temp);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new string by appending given string to this
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString -- 2nd string to be appended
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return new subsumeable string (this makes things faster by reducing copying)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsSubsumeStr nsString::operator+(const nsString& aString){
|
|
|
|
nsString temp(*this); //make a temp string the same size as this...
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(temp,aString,0,aString.mLength);
|
1999-05-06 09:13:08 +04:00
|
|
|
return nsSubsumeStr(temp);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given buffer.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aCString is a ptr to cstring to be added to this
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return new subsumeable string (this makes things faster by reducing copying)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsSubsumeStr nsString::operator+(const char* aCString) {
|
|
|
|
nsString temp(*this);
|
|
|
|
temp.Append(aCString);
|
1999-05-06 09:13:08 +04:00
|
|
|
return nsSubsumeStr(temp);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given char.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aChar is a char to be added to this
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return new subsumeable string (this makes things faster by reducing copying)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsSubsumeStr nsString::operator+(char aChar) {
|
|
|
|
nsString temp(*this);
|
1999-03-22 12:54:46 +03:00
|
|
|
temp.Append(char(aChar));
|
1999-05-06 09:13:08 +04:00
|
|
|
return nsSubsumeStr(temp);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given buffer.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString is a ptr to unistring to be added to this
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return new subsumeable string (this makes things faster by reducing copying)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsSubsumeStr nsString::operator+(const PRUnichar* aString) {
|
|
|
|
nsString temp(*this);
|
1999-03-22 12:54:46 +03:00
|
|
|
temp.Append(aString);
|
1999-05-06 09:13:08 +04:00
|
|
|
return nsSubsumeStr(temp);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given char.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aChar is a unichar to be added to this
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return new subsumeable string (this makes things faster by reducing copying)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsSubsumeStr nsString::operator+(PRUnichar aChar) {
|
|
|
|
nsString temp(*this);
|
1999-03-22 12:54:46 +03:00
|
|
|
temp.Append(char(aChar));
|
1999-05-06 09:13:08 +04:00
|
|
|
return nsSubsumeStr(temp);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Lexomorphic transforms...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts all chars in internal string to lower
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
void nsString::ToLowerCase() {
|
1999-03-22 12:54:46 +03:00
|
|
|
nsStr::ChangeCase(*this,PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts all chars in internal string to upper
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
void nsString::ToUpperCase() {
|
1999-03-22 12:54:46 +03:00
|
|
|
nsStr::ChangeCase(*this,PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Converts chars in this to uppercase, and
|
1999-03-22 12:54:46 +03:00
|
|
|
* stores them in aString
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aOut is a string to contain result
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
void nsString::ToLowerCase(nsString& aString) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
aString=*this;
|
|
|
|
nsStr::ChangeCase(aString,PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Converts chars in this to uppercase, and
|
1999-03-22 12:54:46 +03:00
|
|
|
* stores them in a given output string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aOut is a string to contain result
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
void nsString::ToUpperCase(nsString& aString) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
aString=*this;
|
|
|
|
nsStr::ChangeCase(aString,PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to remove all occurances of the
|
|
|
|
* characters found in aSet from this string.
|
|
|
|
*
|
1999-12-03 03:30:29 +03:00
|
|
|
* @update gess 11/02/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aChar -- char to be stripped
|
1999-12-03 03:30:29 +03:00
|
|
|
* @param anOffset -- where in this string to start stripping chars
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return *this
|
|
|
|
*/
|
1999-12-03 03:30:29 +03:00
|
|
|
nsString& nsString::StripChar(PRUnichar aChar,PRInt32 anOffset){
|
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength);
|
1999-12-03 03:30:29 +03:00
|
|
|
while(kNotFound<anOffset) {
|
|
|
|
nsStr::Delete(*this,anOffset,1);
|
2000-02-11 15:11:03 +03:00
|
|
|
anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset,mLength);
|
1999-12-03 03:30:29 +03:00
|
|
|
}
|
1999-07-17 11:26:16 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to remove all occurances of the
|
|
|
|
* characters found in aSet from this string.
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aSet -- characters to be cut from this
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
nsString& nsString::StripChars(const char* aSet){
|
1999-09-30 08:03:49 +04:00
|
|
|
nsStr::StripChars(*this,aSet);
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method strips whitespace throughout the string
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::StripWhitespace() {
|
1999-09-30 08:03:49 +04:00
|
|
|
return StripChars(kWhitespace);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar) {
|
1999-03-22 12:54:46 +03:00
|
|
|
PRUint32 theIndex=0;
|
1999-06-03 14:49:14 +04:00
|
|
|
if(eTwoByte==mCharSize){
|
|
|
|
for(theIndex=0;theIndex<mLength;theIndex++){
|
|
|
|
if(mUStr[theIndex]==aSourceChar) {
|
1999-03-23 10:33:10 +03:00
|
|
|
mUStr[theIndex]=aDestChar;
|
1999-06-03 14:49:14 +04:00
|
|
|
}//if
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
1999-06-03 14:49:14 +04:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
for(theIndex=0;theIndex<mLength;theIndex++){
|
|
|
|
if(mStr[theIndex]==(char)aSourceChar) {
|
1999-03-23 10:33:10 +03:00
|
|
|
mStr[theIndex]=(char)aDestChar;
|
1999-06-03 14:49:14 +04:00
|
|
|
}//if
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
nsString& nsString::ReplaceChar(const char* aSet, PRUnichar aNewChar){
|
|
|
|
if(aSet){
|
|
|
|
PRInt32 theIndex=FindCharInSet(aSet,0);
|
|
|
|
while(kNotFound<theIndex) {
|
|
|
|
if(eTwoByte==mCharSize)
|
|
|
|
mUStr[theIndex]=aNewChar;
|
|
|
|
else mStr[theIndex]=(char)aNewChar;
|
|
|
|
theIndex=FindCharInSet(aSet,theIndex+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-12-02 13:14:38 +03:00
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given target with the given replacement
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
nsString& nsString::ReplaceSubstring(const PRUnichar* aTarget,const PRUnichar* aNewValue){
|
|
|
|
if(aTarget && aNewValue) {
|
|
|
|
|
|
|
|
PRInt32 len=nsCRT::strlen(aTarget);
|
|
|
|
if(0<len) {
|
|
|
|
CBufDescriptor theDesc1(aTarget,PR_TRUE, len+1,len);
|
|
|
|
nsAutoString theTarget(theDesc1);
|
|
|
|
|
|
|
|
len=nsCRT::strlen(aNewValue);
|
|
|
|
if(0<len) {
|
|
|
|
CBufDescriptor theDesc2(aNewValue,PR_TRUE, len+1,len);
|
|
|
|
nsAutoString theNewValue(theDesc2);
|
|
|
|
|
|
|
|
ReplaceSubstring(theTarget,theNewValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given target substring with the given replacement substring
|
|
|
|
*
|
|
|
|
* @param aTarget
|
|
|
|
* @param aNewValue
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
nsString& nsString::ReplaceSubstring(const nsString& aTarget,const nsString& aNewValue){
|
|
|
|
|
|
|
|
|
|
|
|
//WARNING: This is not working yet!!!!!
|
|
|
|
|
|
|
|
if(aTarget.mLength && aNewValue.mLength) {
|
|
|
|
PRBool isSameLen=(aTarget.mLength==aNewValue.mLength);
|
|
|
|
|
|
|
|
if((isSameLen) && (1==aNewValue.mLength)) {
|
|
|
|
ReplaceChar(aTarget.CharAt(0),aNewValue.CharAt(0));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRInt32 theIndex=0;
|
2000-02-11 15:11:03 +03:00
|
|
|
while(kNotFound!=(theIndex=nsStr::FindSubstr(*this,aTarget,PR_FALSE,theIndex,mLength))) {
|
1999-12-02 13:14:38 +03:00
|
|
|
if(aNewValue.mLength<aTarget.mLength) {
|
|
|
|
//Since target is longer than newValue, we should delete a few chars first, then overwrite.
|
|
|
|
PRInt32 theDelLen=aTarget.mLength-aNewValue.mLength;
|
|
|
|
nsStr::Delete(*this,theIndex,theDelLen);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//this is the worst case: the newvalue is larger than the substr it's replacing
|
|
|
|
//so we have to insert some characters...
|
|
|
|
PRInt32 theInsLen=aNewValue.mLength-aTarget.mLength;
|
|
|
|
nsStr::Insert(*this,theIndex,aNewValue,0,theInsLen);
|
|
|
|
}
|
|
|
|
nsStr::Overwrite(*this,aNewValue,theIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
PRInt32 nsString::CountChar(PRUnichar aChar) {
|
|
|
|
PRInt32 theIndex=0;
|
|
|
|
PRInt32 theCount=0;
|
|
|
|
PRInt32 theLen=(PRInt32)mLength;
|
|
|
|
for(theIndex=0;theIndex<theLen;theIndex++){
|
|
|
|
PRUnichar theChar=GetCharAt(*this,theIndex);
|
|
|
|
if(theChar==aChar)
|
|
|
|
theCount++;
|
|
|
|
}
|
|
|
|
return theCount;
|
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03: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
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
nsString& nsString::Trim(const char* aTrimSet, PRBool aEliminateLeading,PRBool aEliminateTrailing,PRBool aIgnoreQuotes){
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
if(aTrimSet){
|
2000-02-11 15:11:03 +03:00
|
|
|
|
|
|
|
PRUnichar theFirstChar=0;
|
|
|
|
PRUnichar theLastChar=0;
|
|
|
|
PRBool theQuotesAreNeeded=PR_FALSE;
|
|
|
|
|
|
|
|
if(aIgnoreQuotes && (mLength>2)) {
|
|
|
|
theFirstChar=First();
|
|
|
|
theLastChar=Last();
|
|
|
|
if(theFirstChar==theLastChar) {
|
|
|
|
if(('\''==theFirstChar) || ('"'==theFirstChar)) {
|
|
|
|
Cut(0,1);
|
|
|
|
Truncate(mLength-1);
|
|
|
|
theQuotesAreNeeded=PR_TRUE;
|
|
|
|
}
|
|
|
|
else theFirstChar=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing);
|
1999-07-17 11:26:16 +04:00
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
if(aIgnoreQuotes && theQuotesAreNeeded) {
|
|
|
|
Insert(theFirstChar,0);
|
|
|
|
Append(theLastChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* This method strips chars in given set from string.
|
|
|
|
* You can control whether chars are yanked from
|
1999-03-22 12:54:46 +03:00
|
|
|
* start and end of string as well.
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param aEliminateLeading controls stripping of leading ws
|
|
|
|
* @param aEliminateTrailing controls stripping of trailing ws
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
1999-03-22 12:54:46 +03:00
|
|
|
if(aSet){
|
1999-07-17 11:26:16 +04:00
|
|
|
ReplaceChar(aSet,aChar);
|
|
|
|
nsStr::CompressSet(*this,aSet,aEliminateLeading,aEliminateTrailing);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method strips whitespace from string.
|
|
|
|
* You can control whether whitespace is yanked from
|
|
|
|
* start and end of string as well.
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param aEliminateLeading controls stripping of leading ws
|
|
|
|
* @param aEliminateTrailing controls stripping of trailing ws
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::CompressWhitespace( PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
|
|
|
CompressSet(kWhitespace,' ',aEliminateLeading,aEliminateTrailing);
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
string conversion methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a duplicate clone (ptr) of this string.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return ptr to clone of this string
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString* nsString::ToNewString() const {
|
|
|
|
return new nsString(*this);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ascii clone of this string
|
1999-08-30 10:55:13 +04:00
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
2000-02-24 11:20:03 +03:00
|
|
|
* @update gess 02/24/00
|
|
|
|
* @WARNING! Potential i18n issue here, since we're stepping down from 2byte chars to 1byte chars!
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return ptr to new ascii string
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
char* nsString::ToNewCString() const {
|
|
|
|
|
2000-02-24 11:20:03 +03:00
|
|
|
nsCString temp(*this); //construct nsCString with alloc on heap (which we'll steal in a moment)
|
|
|
|
temp.SetCapacity(8); //force it to have an allocated buffer, even if this is empty.
|
|
|
|
char* result=temp.mStr; //steal temp's buffer
|
|
|
|
temp.mStr=0; //clear temp's buffer to prevent deallocation
|
|
|
|
return result; //and return the char*
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
2000-02-24 11:20:03 +03:00
|
|
|
|
1999-09-14 02:51:29 +04:00
|
|
|
/**
|
|
|
|
* Creates an UTF8 clone of this string
|
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
|
|
|
* @update ftang 09/10/99
|
|
|
|
* @return ptr to new UTF8 string
|
|
|
|
* http://www.cis.ohio-state.edu/htbin/rfc/rfc2279.html
|
|
|
|
*/
|
|
|
|
char* nsString::ToNewUTF8String() const {
|
|
|
|
nsCString temp(*this);
|
|
|
|
temp.SetCapacity(8); //ensure that we get an allocated buffer instead of the common empty one.
|
|
|
|
|
|
|
|
// Caculate how many bytes we need
|
|
|
|
PRUnichar* p;
|
|
|
|
PRInt32 utf8len;
|
|
|
|
for(p = this->mUStr, utf8len=0; 0 != (*p);p++)
|
|
|
|
{
|
|
|
|
if(0x0000 == ((*p) & 0x007F))
|
|
|
|
utf8len += 1; // 0000 0000 - 0000 007F
|
|
|
|
else if(0x0000 == ((*p) & 0x07FF))
|
|
|
|
utf8len += 2; // 0000 0080 - 0000 07FF
|
|
|
|
else
|
|
|
|
utf8len += 3; // 0000 0800 - 0000 FFFF
|
|
|
|
// Note: Surrogate pair need 4 bytes, but in this caculation
|
|
|
|
// we count as 6 bytes. It will wast 2 bytes per surrogate pair
|
|
|
|
}
|
|
|
|
|
|
|
|
if((utf8len+1) > 8)
|
|
|
|
temp.SetCapacity(utf8len+1);
|
|
|
|
|
|
|
|
char* result=temp.mStr;
|
|
|
|
char* out = result;
|
|
|
|
PRUint32 ucs4=0;
|
|
|
|
|
|
|
|
for(p = this->mUStr, utf8len=0; 0 != (*p);p++)
|
|
|
|
{
|
|
|
|
if(0 == ucs4) {
|
|
|
|
if(0x0000 == ((*p) & 0xFF80)) {
|
|
|
|
*out++ = (char)*p;
|
|
|
|
} else if(0x0000 == ((*p) & 0xF800)) {
|
|
|
|
*out++ = 0xC0 | (char)((*p) >> 6);
|
|
|
|
*out++ = 0x80 | (char)(0x003F & (*p));
|
|
|
|
} else {
|
|
|
|
if( 0xD800 == ( 0xFC00 & (*p)))
|
|
|
|
{ // D800- DBFF - High Surrogate
|
|
|
|
// N = (H- D800) *400 + 10000 + ...
|
|
|
|
ucs4 = 0x10000 | ((0x03FF & (*p)) << 10);
|
|
|
|
} else if( 0xDC00 == ( 0xFC00 & (*p))) {
|
|
|
|
// DC00- DFFF - Low Surrogate
|
|
|
|
// error here. We should hit High Surrogate first
|
|
|
|
// Do not output any thing in this case
|
|
|
|
} else {
|
|
|
|
*out++ = 0xE0 | (char)((*p) >> 12);
|
|
|
|
*out++ = 0x80 | (char)(0x003F & (*p >> 6));
|
|
|
|
*out++ = 0x80 | (char)(0x003F & (*p) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if( 0xDC00 == (0xFC00 & (*p))) {
|
|
|
|
// DC00- DFFF - Low Surrogate
|
|
|
|
// N += ( L - DC00 )
|
|
|
|
ucs4 |= (0x03FF & (*p));
|
|
|
|
// 0001 0000-001F FFFF
|
|
|
|
*out++ = 0xF0 | (char)(ucs4 >> 18);
|
|
|
|
*out++ = 0x80 | (char)(0x003F & (ucs4 >> 12));
|
|
|
|
*out++ = 0x80 | (char)(0x003F & (ucs4 >> 6));
|
|
|
|
*out++ = 0x80 | (char)(0x003F & ucs4) ;
|
|
|
|
} else {
|
|
|
|
// Got a High Surrogate but no low surrogate
|
|
|
|
// output nothing.
|
|
|
|
}
|
|
|
|
ucs4 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out = '\0'; // null terminate
|
|
|
|
temp.mStr=0;
|
|
|
|
temp.mOwnsBuffer=PR_FALSE;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ascii clone of this string
|
1999-08-30 10:55:13 +04:00
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
2000-02-24 11:20:03 +03:00
|
|
|
* @update gess 02/24/00
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return ptr to new ascii string
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRUnichar* nsString::ToNewUnicode() const {
|
2000-02-24 11:20:03 +03:00
|
|
|
|
|
|
|
nsString temp(*this); //construct nsString with alloc on heap (which we'll steal in a moment)
|
|
|
|
temp.SetCapacity(8); //force it to have an allocated buffer, even if this is empty.
|
|
|
|
PRUnichar* result=temp.mUStr; //steal temp's buffer
|
|
|
|
temp.mStr=0; //clear temp's buffer to prevent deallocation
|
|
|
|
temp.mOwnsBuffer=PR_FALSE;
|
|
|
|
return result; //and return the PRUnichar* to the caller
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies contents of this string into he given buffer
|
1999-08-30 10:55:13 +04:00
|
|
|
* Note that if you provide me a buffer that is smaller than the length of
|
|
|
|
* this string, only the number of bytes that will fit are copied.
|
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aBuf
|
|
|
|
* @param aBufLength -- size of your external buffer (including null)
|
|
|
|
* @param anOffset -- THIS IS NOT USED AT THIS TIME!
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
char* nsString::ToCString(char* aBuf, PRUint32 aBufLength,PRUint32 anOffset) const{
|
|
|
|
if(aBuf) {
|
1999-08-30 10:55:13 +04:00
|
|
|
|
|
|
|
// NS_ASSERTION(mLength<=aBufLength,"buffer smaller than string");
|
|
|
|
|
|
|
|
CBufDescriptor theDescr(aBuf,PR_TRUE,aBufLength,0);
|
|
|
|
nsCAutoString temp(theDescr);
|
|
|
|
temp.Assign(*this,aBufLength-1);
|
1999-07-17 11:26:16 +04:00
|
|
|
temp.mStr=0;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return aBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform string to float conversion.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return float rep of string value
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
float nsString::ToFloat(PRInt32* aErrorCode) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
char buf[100];
|
|
|
|
if (mLength > PRInt32(sizeof(buf)-1)) {
|
|
|
|
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
char* cp = ToCString(buf, sizeof(buf));
|
|
|
|
float f = (float) PR_strtod(cp, &cp);
|
|
|
|
if (*cp != 0) {
|
|
|
|
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
*aErrorCode = (PRInt32) NS_OK;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
1999-06-17 11:24:13 +04:00
|
|
|
|
1999-06-14 01:23:04 +04:00
|
|
|
/**
|
|
|
|
* Perform decimal numeric string to int conversion.
|
|
|
|
* NOTE: In this version, we use the radix you give, even if it's wrong.
|
2000-02-13 20:46:15 +03:00
|
|
|
* @update gess 02/14/00
|
1999-06-14 01:23:04 +04:00
|
|
|
* @param aErrorCode will contain error if one occurs
|
2000-02-13 20:46:15 +03:00
|
|
|
* @param aRadix tells us what base to expect the given string in. kAutoDetect tells us to determine the radix.
|
1999-06-14 01:23:04 +04:00
|
|
|
* @return int rep of string value
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
2000-02-13 20:46:15 +03:00
|
|
|
PRUnichar* cp=mUStr;
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 theRadix = (kAutoDetect==aRadix) ? 10 : aRadix;
|
|
|
|
PRInt32 result=0;
|
|
|
|
PRBool negate=PR_FALSE;
|
|
|
|
PRUnichar theChar=0;
|
|
|
|
|
|
|
|
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if(cp) {
|
|
|
|
|
|
|
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
|
|
|
|
2000-02-13 20:46:15 +03:00
|
|
|
PRUnichar* endcp=cp+mLength;
|
2000-02-11 15:11:03 +03:00
|
|
|
PRBool done=PR_FALSE;
|
|
|
|
|
|
|
|
while((cp<endcp) && (!done)){
|
|
|
|
theChar=*cp;
|
|
|
|
switch(*cp++) {
|
|
|
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
|
|
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
|
|
|
theRadix=16;
|
|
|
|
done=PR_TRUE;
|
|
|
|
break;
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
done=PR_TRUE;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
negate=PR_TRUE; //fall through...
|
|
|
|
break;
|
|
|
|
case 'X': case 'x':
|
|
|
|
theRadix=16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
} //switch
|
|
|
|
}
|
|
|
|
|
|
|
|
//if you don't have any valid chars, return 0, but set the error;
|
|
|
|
if(cp<=endcp) {
|
|
|
|
|
|
|
|
*anErrorCode = NS_OK;
|
|
|
|
|
|
|
|
//now iterate the numeric chars and build our result
|
|
|
|
PRUnichar* first=--cp; //in case we have to back up.
|
|
|
|
|
|
|
|
while(cp<=endcp){
|
|
|
|
theChar=*cp++;
|
|
|
|
if(('0'<=theChar) && (theChar<='9')){
|
|
|
|
result = (theRadix * result) + (theChar-'0');
|
|
|
|
}
|
|
|
|
else if((theChar>='A') && (theChar<='F')) {
|
|
|
|
if(10==theRadix) {
|
|
|
|
if(kAutoDetect==aRadix){
|
|
|
|
theRadix=16;
|
|
|
|
cp=first; //backup
|
|
|
|
result=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
result=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = (theRadix * result) + ((theChar-'A')+10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((theChar>='a') && (theChar<='f')) {
|
|
|
|
if(10==theRadix) {
|
|
|
|
if(kAutoDetect==aRadix){
|
|
|
|
theRadix=16;
|
|
|
|
cp=first; //backup
|
|
|
|
result=0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
result=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = (theRadix * result) + ((theChar-'a')+10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(('X'==theChar) || ('x'==theChar) || ('#'==theChar) || ('+'==theChar)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//we've encountered a char that's not a legal number or sign
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} //while
|
|
|
|
if(negate)
|
|
|
|
result=-result;
|
|
|
|
} //if
|
|
|
|
}
|
|
|
|
return result;
|
1999-06-14 01:23:04 +04:00
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**********************************************************************
|
|
|
|
String manipulation methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* assign given nsStr (or derivative) to this one
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aString: nsStr to be appended
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Assign(const nsStr& aString,PRInt32 aCount) {
|
1999-06-03 14:49:14 +04:00
|
|
|
if(this!=&aString){
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-07-19 01:26:03 +04:00
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount=aString.mLength;
|
|
|
|
else aCount=MinInt(aCount,aString.mLength);
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Assign(*this,aString,0,aCount);
|
1999-06-03 14:49:14 +04:00
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char* to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aCString: buffer to be assigned to this
|
1999-11-19 11:05:30 +03:00
|
|
|
* @param aCount -- length of given buffer or -1 if you want me to compute length.
|
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Assign(const char* aCString,PRInt32 aCount) {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-03-22 12:54:46 +03:00
|
|
|
if(aCString){
|
|
|
|
Append(aCString,aCount);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given unichar* to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString: buffer to be assigned to this
|
1999-11-19 11:05:30 +03:00
|
|
|
* @param aCount -- length of given buffer or -1 if you want me to compute length.
|
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-03-22 12:54:46 +03:00
|
|
|
if(aString){
|
|
|
|
Append(aString,aCount);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aChar: char to be assignd to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Assign(char aChar) {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-03-22 12:54:46 +03:00
|
|
|
return Append(aChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* assign given unichar to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aChar: char to be assignd to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Assign(PRUnichar aChar) {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-03-22 12:54:46 +03:00
|
|
|
return Append(aChar);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-05-06 09:13:08 +04:00
|
|
|
* WARNING! THIS IS A VERY SPECIAL METHOD.
|
|
|
|
* This method "steals" the contents of aSource and hands it to aDest.
|
|
|
|
* Ordinarily a copy is made, but not in this version.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess10/30/98
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param
|
|
|
|
* @return
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-06-05 02:08:19 +04:00
|
|
|
#ifdef AIX
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::operator=(const nsSubsumeStr& aSubsumeString) {
|
1999-06-05 02:08:19 +04:00
|
|
|
nsSubsumeStr temp(aSubsumeString); // a temp is needed for the AIX compiler
|
|
|
|
Subsume(*this,temp);
|
|
|
|
#else
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::operator=(nsSubsumeStr& aSubsumeString) {
|
1999-05-06 09:13:08 +04:00
|
|
|
Subsume(*this,aSubsumeString);
|
1999-06-05 02:08:19 +04:00
|
|
|
#endif // AIX
|
1999-05-06 09:13:08 +04:00
|
|
|
return *this;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* append given string to this string;
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Append(const nsStr& aString,PRInt32 aCount) {
|
1999-07-19 01:26:03 +04:00
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount=aString.mLength;
|
|
|
|
else aCount=MinInt(aCount,aString.mLength);
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
if(0<aCount)
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(*this,aString,0,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* append given string to this string
|
1999-08-30 10:55:13 +04:00
|
|
|
* I don't think we need this method now that we have the previous one.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Append(const nsString& aString,PRInt32 aCount) {
|
1999-07-19 01:26:03 +04:00
|
|
|
if(aCount<0)
|
|
|
|
aCount=aString.mLength;
|
|
|
|
else aCount=MinInt(aCount,aString.mLength);
|
1999-07-17 11:26:16 +04:00
|
|
|
if(0<aCount)
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(*this,aString,0,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* append given c-string to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString : string to be appended to this
|
1999-11-19 11:05:30 +03:00
|
|
|
* @param aCount -- length of given buffer or -1 if you want me to compute length.
|
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Append(const char* aCString,PRInt32 aCount) {
|
1999-07-25 21:21:14 +04:00
|
|
|
if(aCString && aCount){ //if astring is null or count==0 there's nothing to do
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eOneByte);
|
|
|
|
temp.mStr=(char*)aCString;
|
1999-07-20 10:58:41 +04:00
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
if(0<aCount) {
|
|
|
|
temp.mLength=aCount;
|
1999-11-14 09:22:52 +03:00
|
|
|
|
|
|
|
// If this assertion fires, the caller is probably lying about the length of
|
|
|
|
// the passed-in string. File a bug on the caller.
|
1999-11-14 13:05:40 +03:00
|
|
|
|
1999-11-14 09:22:52 +03:00
|
|
|
#ifdef NS_DEBUG
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
|
2000-02-19 12:17:49 +03:00
|
|
|
if(kNotFound<len) {
|
|
|
|
NS_WARNING(kPossibleNull);
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
}
|
|
|
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
if(0<aCount)
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(*this,temp,0,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* append given unicode string to this
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString : string to be appended to this
|
1999-11-19 11:05:30 +03:00
|
|
|
* @param aCount -- length of given buffer or -1 if you want me to compute length.
|
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Append(const PRUnichar* aString,PRInt32 aCount) {
|
1999-07-25 21:21:14 +04:00
|
|
|
if(aString && aCount){ //if astring is null or count==0 there's nothing to do
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eTwoByte);
|
|
|
|
temp.mUStr=(PRUnichar*)aString;
|
1999-07-20 10:58:41 +04:00
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
if(0<aCount) {
|
|
|
|
temp.mLength=aCount;
|
1999-11-14 09:22:52 +03:00
|
|
|
|
|
|
|
// If this assertion fires, the caller is probably lying about the length of
|
|
|
|
// the passed-in string. File a bug on the caller.
|
|
|
|
#ifdef NS_DEBUG
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
|
2000-02-19 12:17:49 +03:00
|
|
|
if(kNotFound<len) {
|
|
|
|
NS_WARNING(kPossibleNull);
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
}
|
|
|
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
if(0<aCount)
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(*this,temp,0,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* append given char to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aChar: char to be appended
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Append(char aChar) {
|
1999-03-22 12:54:46 +03:00
|
|
|
char buf[2]={0,0};
|
|
|
|
buf[0]=aChar;
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eOneByte);
|
|
|
|
temp.mStr=buf;
|
|
|
|
temp.mLength=1;
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(*this,temp,0,1);
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* append given unichar to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aChar: char to be appended to this
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Append(PRUnichar aChar) {
|
1999-03-22 12:54:46 +03:00
|
|
|
PRUnichar buf[2]={0,0};
|
|
|
|
buf[0]=aChar;
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eTwoByte);
|
|
|
|
temp.mUStr=buf;
|
|
|
|
temp.mLength=1;
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Append(*this,temp,0,1);
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Append the given integer to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aInteger:
|
|
|
|
* @param aRadix:
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return
|
|
|
|
*/
|
1999-09-30 08:03:49 +04:00
|
|
|
nsString& nsString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
1999-09-20 09:50:43 +04:00
|
|
|
|
1999-09-30 08:03:49 +04:00
|
|
|
PRUint32 theInt=(PRUint32)anInteger;
|
1999-09-20 09:10:32 +04:00
|
|
|
|
1999-09-30 08:03:49 +04:00
|
|
|
char buf[]={'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
1999-09-20 09:10:32 +04:00
|
|
|
|
1999-09-30 08:03:49 +04:00
|
|
|
PRInt32 radices[] = {1000000000,268435456};
|
|
|
|
PRInt32 mask1=radices[16==aRadix];
|
1999-09-20 09:10:32 +04:00
|
|
|
|
1999-09-30 08:03:49 +04:00
|
|
|
PRInt32 charpos=0;
|
|
|
|
if(anInteger<0) {
|
|
|
|
theInt*=-1;
|
|
|
|
if(10==aRadix) {
|
|
|
|
buf[charpos++]='-';
|
|
|
|
}
|
|
|
|
else theInt=(int)~(theInt-1);
|
1999-09-20 09:50:43 +04:00
|
|
|
}
|
|
|
|
|
1999-09-30 09:15:37 +04:00
|
|
|
PRBool isfirst=PR_TRUE;
|
1999-09-30 08:03:49 +04:00
|
|
|
while(mask1>=1) {
|
1999-10-05 08:47:19 +04:00
|
|
|
PRInt32 theDiv=theInt/mask1;
|
|
|
|
if((theDiv) || (!isfirst)) {
|
|
|
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
1999-09-30 09:15:37 +04:00
|
|
|
isfirst=PR_FALSE;
|
1999-09-30 08:03:49 +04:00
|
|
|
}
|
1999-10-05 08:47:19 +04:00
|
|
|
theInt-=theDiv*mask1;
|
1999-09-30 08:03:49 +04:00
|
|
|
mask1/=aRadix;
|
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
return Append(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Append the given float to this string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aFloat:
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Append(float aFloat){
|
1999-03-22 12:54:46 +03:00
|
|
|
char buf[40];
|
|
|
|
// *** XX UNCOMMENT THIS LINE
|
|
|
|
//PR_snprintf(buf, sizeof(buf), "%g", aFloat);
|
|
|
|
sprintf(buf,"%g",aFloat);
|
1999-07-17 11:26:16 +04:00
|
|
|
Append(buf);
|
|
|
|
return *this;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-08-30 10:55:13 +04:00
|
|
|
* Copies n characters from this left of this string to given string,
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aDest -- Receiving string
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRUint32 nsString::Left(nsString& aDest,PRInt32 aCount) const{
|
1999-07-19 01:26:03 +04:00
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount=mLength;
|
|
|
|
else aCount=MinInt(aCount,mLength);
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Assign(aDest,*this,0,aCount);
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return aDest.mLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-08-30 10:55:13 +04:00
|
|
|
* Copies n characters from this string to from given offset
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
|
|
|
* @param aDest -- Receiving string
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param anOffset -- where copying should begin
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRUint32 nsString::Mid(nsString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
|
1999-07-19 01:26:03 +04:00
|
|
|
if(aCount<0)
|
|
|
|
aCount=mLength;
|
|
|
|
else aCount=MinInt(aCount,mLength);
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return aDest.mLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-08-30 10:55:13 +04:00
|
|
|
* Copies last n characters from this string to given string,
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aDest -- Receiving string
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
PRUint32 nsString::Right(nsString& aDest,PRInt32 aCount) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
PRInt32 offset=MaxInt(mLength-aCount,0);
|
1999-08-30 10:55:13 +04:00
|
|
|
return Mid(aDest,offset,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method inserts n chars from given string into this
|
|
|
|
* string at str[anOffset].
|
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aString -- source String to be inserted into this
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param anOffset -- insertion position within this str
|
1999-07-25 21:21:14 +04:00
|
|
|
* @param aCount -- number of chars to be copied from aCopy
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return this
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Insert(*this,anOffset,aCopy,0,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Insert a char* into this string at a specified offset.
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess4/22/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param char* aCString to be inserted into this string
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param anOffset is insert pos in str
|
1999-11-19 11:05:30 +03:00
|
|
|
* @param aCount -- length of given buffer or -1 if you want me to compute length.
|
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return this
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
1999-07-25 21:21:14 +04:00
|
|
|
if(aCString && aCount){
|
1999-06-14 01:23:04 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mStr=(char*)aCString;
|
1999-07-20 10:58:41 +04:00
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
if(0<aCount) {
|
|
|
|
temp.mLength=aCount;
|
1999-11-14 09:22:52 +03:00
|
|
|
|
|
|
|
// If this assertion fires, the caller is probably lying about the length of
|
|
|
|
// the passed-in string. File a bug on the caller.
|
|
|
|
#ifdef NS_DEBUG
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
|
2000-02-19 12:17:49 +03:00
|
|
|
if(kNotFound<len) {
|
|
|
|
NS_WARNING(kPossibleNull);
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
}
|
|
|
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
1999-07-20 10:58:41 +04:00
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
if(0<aCount){
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Insert a unicode* into this string at a specified offset.
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess4/22/98
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aChar char to be inserted into this string
|
|
|
|
* @param anOffset is insert pos in str
|
1999-11-19 11:05:30 +03:00
|
|
|
* @param aCount -- length of given buffer or -1 if you want me to compute length.
|
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return this
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Insert(const PRUnichar* aString,PRUint32 anOffset,PRInt32 aCount){
|
1999-07-25 21:21:14 +04:00
|
|
|
if(aString && aCount){
|
1999-07-17 11:26:16 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mUStr=(PRUnichar*)aString;
|
1999-07-20 10:58:41 +04:00
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
if(0<aCount) {
|
|
|
|
temp.mLength=aCount;
|
1999-11-14 09:22:52 +03:00
|
|
|
|
|
|
|
// If this assertion fires, the caller is probably lying about the length of
|
|
|
|
// the passed-in string. File a bug on the caller.
|
|
|
|
#ifdef NS_DEBUG
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0,temp.mLength);
|
2000-02-19 12:17:49 +03:00
|
|
|
if(kNotFound<len) {
|
|
|
|
NS_WARNING(kPossibleNull);
|
|
|
|
}
|
1999-11-14 09:22:52 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
}
|
|
|
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
1999-07-20 10:58:41 +04:00
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
if(0<aCount){
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a single uni-char into this string at
|
|
|
|
* a specified offset.
|
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess4/22/98
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aChar char to be inserted into this string
|
|
|
|
* @param anOffset is insert pos in str
|
1999-08-30 10:55:13 +04:00
|
|
|
* @return this
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
1999-03-22 12:54:46 +03:00
|
|
|
PRUnichar theBuffer[2]={0,0};
|
|
|
|
theBuffer[0]=aChar;
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mUStr=theBuffer;
|
|
|
|
temp.mLength=1;
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method is used to cut characters in this string
|
|
|
|
* starting at anOffset, continuing for aCount chars.
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param anOffset -- start pos for cut operation
|
|
|
|
* @param aCount -- number of chars to be cut
|
|
|
|
* @return *this
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString& nsString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
1999-07-19 01:26:03 +04:00
|
|
|
if(0<aCount) {
|
1999-10-05 08:47:19 +04:00
|
|
|
nsStr::Delete(*this,anOffset,aCount);
|
1999-07-19 01:26:03 +04:00
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Searching methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for given character within this string.
|
|
|
|
* This method does so by using a binary search,
|
|
|
|
* so your string HAD BETTER BE ORDERED!
|
|
|
|
*
|
|
|
|
* @param aChar is the unicode char to be found
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::BinarySearch(PRUnichar aChar) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
PRInt32 low=0;
|
|
|
|
PRInt32 high=mLength-1;
|
|
|
|
|
|
|
|
while (low <= high) {
|
|
|
|
int middle = (low + high) >> 1;
|
1999-04-06 01:38:50 +04:00
|
|
|
PRUnichar theChar=GetCharAt(*this,middle);
|
1999-03-22 12:54:46 +03:00
|
|
|
if (theChar==aChar)
|
|
|
|
return middle;
|
|
|
|
if (theChar>aChar)
|
|
|
|
high = middle - 1;
|
|
|
|
else
|
|
|
|
low = middle + 1;
|
|
|
|
}
|
|
|
|
return kNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2000-02-11 15:11:03 +03:00
|
|
|
* search for given string within this string
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aString - substr to be found
|
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=aCString,kNullPointerError);
|
|
|
|
|
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aCString) {
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aCString);
|
|
|
|
temp.mStr=(char*)aCString;
|
2000-02-11 15:11:03 +03:00
|
|
|
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
/**
|
2000-02-11 15:11:03 +03:00
|
|
|
* search for given string within this string
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aString - substr to be found
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
|
|
|
|
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aString) {
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aString);
|
|
|
|
temp.mUStr=(PRUnichar*)aString;
|
2000-02-11 15:11:03 +03:00
|
|
|
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2000-02-11 15:11:03 +03:00
|
|
|
* Search for given string within this string
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aString - substr to be found
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
|
|
|
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
/**
|
2000-02-11 15:11:03 +03:00
|
|
|
* search for given string within this string
|
1999-05-06 09:13:08 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aString - substr to be found
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-05-06 09:13:08 +04:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::Find(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
|
|
|
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
|
1999-05-06 09:13:08 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
* Search for a given char, starting at given offset
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aChar
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
#if 0
|
1999-07-19 07:10:41 +04:00
|
|
|
PRInt32 nsString::Find(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) const{
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset);
|
|
|
|
return result;
|
|
|
|
}
|
1999-08-30 10:55:13 +04:00
|
|
|
#endif
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for a given char, starting at given offset
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aChar is the unichar to be sought
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1999-07-17 11:26:16 +04:00
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
|
|
|
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* This method finds the offset of the first char in this string that is
|
|
|
|
* a member of the given charset, starting the search at anOffset
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset -- where in this string to start searching
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=aCStringSet,kNullPointerError);
|
|
|
|
|
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aCStringSet) {
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aCStringSet);
|
|
|
|
temp.mStr=(char*)aCStringSet;
|
|
|
|
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* This method finds the offset of the first char in this string that is
|
|
|
|
* a member of the given charset, starting the search at anOffset
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset -- where in this string to start searching
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) const{
|
|
|
|
NS_ASSERTION(0!=aStringSet,kNullPointerError);
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
PRInt32 result=kNotFound;
|
1999-07-17 11:26:16 +04:00
|
|
|
if(aStringSet) {
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
1999-07-17 11:26:16 +04:00
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aStringSet);
|
|
|
|
temp.mStr=(char*)aStringSet;
|
|
|
|
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* This method finds the offset of the first char in this string that is
|
|
|
|
* a member of the given charset, starting the search at anOffset
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset -- where in this string to start searching
|
1999-07-17 11:26:16 +04:00
|
|
|
* @return
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::FindCharInSet(*this,aSet,PR_FALSE,anOffset);
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
2000-02-11 15:11:03 +03:00
|
|
|
* Reverse search for given string within this string
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aString - substr to be found
|
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
|
|
|
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
/**
|
2000-02-11 15:11:03 +03:00
|
|
|
* Reverse search for given string within this string
|
1999-05-06 09:13:08 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aString - substr to be found
|
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1999-05-06 09:13:08 +04:00
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::RFind(const nsString& aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
|
|
|
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset,aCount);
|
1999-05-06 09:13:08 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
2000-02-11 15:11:03 +03:00
|
|
|
* Reverse search for given string within this string
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aString - substr to be found
|
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @param anOffset tells us where in this string to start searching
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
2000-02-11 15:11:03 +03:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aString) {
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aString);
|
|
|
|
temp.mStr=(char*)aString;
|
2000-02-11 15:11:03 +03:00
|
|
|
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset,aCount);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Reverse search for char
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param achar
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset - tells us where to begin the search
|
|
|
|
* @return offset of substring or -1
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
#if 0
|
1999-07-19 07:10:41 +04:00
|
|
|
PRInt32 nsString::RFind(PRUnichar aChar,PRInt32 anOffset,PRBool aIgnoreCase) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset);
|
|
|
|
return result;
|
|
|
|
}
|
1999-08-30 10:55:13 +04:00
|
|
|
#endif
|
1999-07-19 07:10:41 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Reverse search for a given char, starting at given offset
|
1999-07-17 11:26:16 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aChar
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset
|
1999-07-17 11:26:16 +04:00
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 nsString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset,PRInt32 aCount) const{
|
|
|
|
PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset,aCount);
|
1999-07-17 11:26:16 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Reverse search for char in this string that is also a member of given charset
|
1999-07-17 11:26:16 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset
|
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
1999-07-17 11:26:16 +04:00
|
|
|
*/
|
|
|
|
PRInt32 nsString::RFindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
|
|
|
|
NS_ASSERTION(0!=aCStringSet,kNullPointerError);
|
|
|
|
|
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aCStringSet) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aCStringSet);
|
|
|
|
temp.mStr=(char*)aCStringSet;
|
|
|
|
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Reverse search for a first char in this string that is a
|
|
|
|
* member of the given char set
|
1999-07-17 11:26:16 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aSet
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset
|
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
1999-07-17 11:26:16 +04:00
|
|
|
*/
|
|
|
|
PRInt32 nsString::RFindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::RFindCharInSet(*this,aSet,PR_FALSE,anOffset);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Reverse search for a first char in this string that is a
|
|
|
|
* member of the given char set
|
1999-07-17 11:26:16 +04:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aSet
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset
|
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
1999-07-17 11:26:16 +04:00
|
|
|
*/
|
|
|
|
PRInt32 nsString::RFindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) const{
|
|
|
|
NS_ASSERTION(0!=aStringSet,kNullPointerError);
|
|
|
|
|
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aStringSet) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aStringSet);
|
|
|
|
temp.mUStr=(PRUnichar*)aStringSet;
|
|
|
|
result=nsStr::RFindCharInSet(*this,temp,PR_FALSE,anOffset);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
COMPARISON METHODS...
|
|
|
|
**************************************************************/
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
/**
|
|
|
|
* Compares given cstring to this string.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param aCString pts to a cstring
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-05-06 09:13:08 +04:00
|
|
|
* @return -1,0,1
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::Compare(const nsString& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
PRInt32 result=nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
|
|
|
return result;
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
* Compares given cstring to this string.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aCString pts to a cstring
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return -1,0,1
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=aCString,kNullPointerError);
|
|
|
|
|
|
|
|
if(aCString) {
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
1999-11-14 09:22:52 +03:00
|
|
|
|
|
|
|
temp.mLength= (0<aCount) ? aCount : nsCRT::strlen(aCString);
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
temp.mStr=(char*)aCString;
|
1999-07-17 11:26:16 +04:00
|
|
|
return nsStr::Compare(*this,temp,aCount,aIgnoreCase);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares given unistring to this string.
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param aString pts to a uni-string
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return -1,0,1
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
|
|
|
|
|
|
|
if(aString) {
|
1999-05-06 09:13:08 +04:00
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aString);
|
|
|
|
temp.mUStr=(PRUnichar*)aString;
|
1999-07-17 11:26:16 +04:00
|
|
|
return nsStr::Compare(*this,temp,aCount,aIgnoreCase);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
return 0;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 11:26:16 +04:00
|
|
|
* Compare given nsStr with this cstring.
|
1999-03-22 12:54:46 +03:00
|
|
|
*
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param aString is an nsStr instance to be compared
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
|
|
|
* @return -1,0,1
|
1999-03-22 12:54:46 +03:00
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 nsString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
/**
|
|
|
|
* Here come a whole bunch of operator functions that are self-explanatory...
|
|
|
|
*/
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::operator==(const nsString& S) const {return Equals(S);}
|
|
|
|
PRBool nsString::operator==(const nsStr& S) const {return Equals(S);}
|
|
|
|
PRBool nsString::operator==(const char* s) const {return Equals(s);}
|
|
|
|
PRBool nsString::operator==(const PRUnichar* s) const {return Equals(s);}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::operator!=(const nsString& S) const {return PRBool(Compare(S)!=0);}
|
|
|
|
PRBool nsString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
|
|
|
|
PRBool nsString::operator!=(const char* s) const {return PRBool(Compare(s)!=0);}
|
|
|
|
PRBool nsString::operator!=(const PRUnichar* s) const {return PRBool(Compare(s)!=0);}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::operator<(const nsString& S) const {return PRBool(Compare(S)<0);}
|
|
|
|
PRBool nsString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
|
|
|
|
PRBool nsString::operator<(const char* s) const {return PRBool(Compare(s)<0);}
|
|
|
|
PRBool nsString::operator<(const PRUnichar* s) const {return PRBool(Compare(s)<0);}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::operator>(const nsString& S) const {return PRBool(Compare(S)>0);}
|
|
|
|
PRBool nsString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
|
|
|
|
PRBool nsString::operator>(const char* s) const {return PRBool(Compare(s)>0);}
|
|
|
|
PRBool nsString::operator>(const PRUnichar* s) const {return PRBool(Compare(s)>0);}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::operator<=(const nsString& S) const {return PRBool(Compare(S)<=0);}
|
|
|
|
PRBool nsString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
|
|
|
|
PRBool nsString::operator<=(const char* s) const {return PRBool(Compare(s)<=0);}
|
|
|
|
PRBool nsString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)<=0);}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::operator>=(const nsString& S) const {return PRBool(Compare(S)>=0);}
|
|
|
|
PRBool nsString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
|
|
|
|
PRBool nsString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
|
|
|
|
PRBool nsString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::EqualsIgnoreCase(const nsString& aString) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
return Equals(aString,PR_TRUE);
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
|
|
|
|
return Equals(aString,PR_TRUE,aLength);
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
1999-08-24 05:14:44 +04:00
|
|
|
PRBool nsString::EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
return Equals(aAtom,PR_TRUE);
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
return Equals(s1,s2,PR_TRUE);
|
|
|
|
}
|
|
|
|
|
1999-11-14 09:22:52 +03:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
/**
|
|
|
|
* Compare this to given string; note that we compare full strings here.
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param aString is the other nsString to be compared to
|
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-05-06 09:13:08 +04:00
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::Equals(const nsString& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
PRInt32 theAnswer=nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
|
|
|
PRBool result=PRBool(0==theAnswer);
|
|
|
|
return result;
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
* Compare this to given string; note that we compare full strings here.
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param aString is the other nsString to be compared to
|
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
PRInt32 theAnswer=nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
|
|
|
PRBool result=PRBool(0==theAnswer);
|
|
|
|
return result;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 11:26:16 +04:00
|
|
|
* Compare this to given c-string; note that we compare full strings here.
|
|
|
|
*
|
|
|
|
* @param aString is the CString to be compared
|
|
|
|
* @param aIgnorecase tells us whether to be case sensitive
|
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::Equals(const char* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
PRInt32 theAnswer=Compare(aString,aIgnoreCase,aCount);
|
|
|
|
PRBool result=PRBool(0==theAnswer);
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 11:26:16 +04:00
|
|
|
* Compare this to given unicode string; note that we compare full strings here.
|
|
|
|
*
|
|
|
|
* @param aString is the U-String to be compared
|
|
|
|
* @param aIgnorecase tells us whether to be case sensitive
|
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
PRInt32 theAnswer=Compare(aString,aIgnoreCase,aCount);
|
|
|
|
PRBool result=PRBool(0==theAnswer);
|
1999-03-22 12:54:46 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 11:26:16 +04:00
|
|
|
* Compare this to given atom; note that we compare full strings here.
|
1999-03-22 12:54:46 +03:00
|
|
|
* 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 01/04/99
|
|
|
|
* @param aString -- unistring to compare to this
|
|
|
|
* @param aLength -- length of given string.
|
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-08-24 05:14:44 +04:00
|
|
|
PRBool nsString::Equals(/*FIX: const */nsIAtom* aAtom,PRBool aIgnoreCase) const{
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=aAtom,kNullPointerError);
|
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if(aAtom){
|
1999-07-17 11:26:16 +04:00
|
|
|
PRInt32 cmp=0;
|
1999-09-04 02:21:29 +04:00
|
|
|
const PRUnichar* unicode;
|
1999-08-21 11:07:00 +04:00
|
|
|
if (aAtom->GetUnicode(&unicode) != NS_OK || unicode == nsnull)
|
|
|
|
return PR_FALSE;
|
1999-07-17 11:26:16 +04:00
|
|
|
if (aIgnoreCase)
|
1999-08-21 11:07:00 +04:00
|
|
|
cmp=nsCRT::strcasecmp(mUStr,unicode);
|
1999-07-17 11:26:16 +04:00
|
|
|
else
|
1999-08-21 11:07:00 +04:00
|
|
|
cmp=nsCRT::strcmp(mUStr,unicode);
|
1999-03-22 12:54:46 +03:00
|
|
|
result=PRBool(0==cmp);
|
|
|
|
}
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
return result;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare given strings
|
|
|
|
* @update gess 7/27/98
|
1999-07-17 11:26:16 +04:00
|
|
|
* @param s1 -- first unichar string to be compared
|
|
|
|
* @param s2 -- second unichar string to be compared
|
1999-03-22 12:54:46 +03:00
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase) const {
|
1999-03-22 12:54:46 +03:00
|
|
|
NS_ASSERTION(0!=s1,kNullPointerError);
|
|
|
|
NS_ASSERTION(0!=s2,kNullPointerError);
|
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if((s1) && (s2)){
|
|
|
|
PRInt32 cmp=(aIgnoreCase) ? nsCRT::strcasecmp(s1,s2) : nsCRT::strcmp(s1,s2);
|
|
|
|
result=PRBool(0==cmp);
|
|
|
|
}
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
return result;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if given char in valid alpha range
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if in alpha range
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::IsAlpha(PRUnichar aChar) {
|
1999-03-22 12:54:46 +03:00
|
|
|
// XXX i18n
|
|
|
|
if (((aChar >= 'A') && (aChar <= 'Z')) || ((aChar >= 'a') && (aChar <= 'z'))) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if given char is a valid space character
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if is valid space char
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::IsSpace(PRUnichar aChar) {
|
1999-03-22 12:54:46 +03:00
|
|
|
// XXX i18n
|
|
|
|
if ((aChar == ' ') || (aChar == '\r') || (aChar == '\n') || (aChar == '\t')) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-07-25 21:21:14 +04:00
|
|
|
/**
|
|
|
|
* Determine if given buffer contains plain ascii
|
|
|
|
*
|
|
|
|
* @param aBuffer -- if null, then we test *this, otherwise we test given buffer
|
|
|
|
* @return TRUE if is all ascii chars, or if strlen==0
|
|
|
|
*/
|
|
|
|
PRBool nsString::IsASCII(const PRUnichar* aBuffer) {
|
|
|
|
|
|
|
|
if(!aBuffer) {
|
|
|
|
aBuffer=mUStr;
|
|
|
|
if(eOneByte==mCharSize)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if(aBuffer) {
|
|
|
|
while(*aBuffer) {
|
|
|
|
if(*aBuffer>255){
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
aBuffer++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
* Determine if given char is valid digit
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if char is a valid digit
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
PRBool nsString::IsDigit(PRUnichar aChar) {
|
1999-03-22 12:54:46 +03:00
|
|
|
// XXX i18n
|
|
|
|
return PRBool((aChar >= '0') && (aChar <= '9'));
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
#ifndef RICKG_TESTBED
|
1999-05-06 09:13:08 +04:00
|
|
|
/**************************************************************
|
|
|
|
Define the string deallocator class...
|
|
|
|
**************************************************************/
|
|
|
|
class nsStringDeallocator: public nsDequeFunctor{
|
|
|
|
public:
|
|
|
|
virtual void* operator()(void* anObject) {
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString* aString= (nsString*)anObject;
|
1999-05-06 09:13:08 +04:00
|
|
|
if(aString){
|
|
|
|
delete aString;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1999-03-23 10:26:27 +03:00
|
|
|
/****************************************************************************
|
1999-07-17 11:26:16 +04:00
|
|
|
* This class, appropriately enough, creates and recycles nsString objects..
|
1999-03-23 10:26:27 +03:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
class nsStringRecycler {
|
|
|
|
public:
|
|
|
|
nsStringRecycler() : mDeque(0) {
|
|
|
|
}
|
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
~nsStringRecycler() {
|
|
|
|
nsStringDeallocator theDeallocator;
|
|
|
|
mDeque.ForEach(theDeallocator); //now delete the strings
|
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
void Recycle(nsString* aString) {
|
1999-03-23 10:26:27 +03:00
|
|
|
mDeque.Push(aString);
|
|
|
|
}
|
|
|
|
|
1999-09-02 11:04:59 +04:00
|
|
|
nsString* CreateString(void){
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString* result=(nsString*)mDeque.Pop();
|
1999-03-23 10:26:27 +03:00
|
|
|
if(!result)
|
1999-09-02 11:04:59 +04:00
|
|
|
result=new nsString();
|
1999-03-23 10:26:27 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
nsDeque mDeque;
|
|
|
|
};
|
1999-07-17 11:26:16 +04:00
|
|
|
static nsStringRecycler& GetRecycler(void);
|
1999-04-25 06:05:03 +04:00
|
|
|
|
1999-03-23 10:26:27 +03:00
|
|
|
/**
|
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-23 10:26:27 +03:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
nsStringRecycler& GetRecycler(void){
|
|
|
|
static nsStringRecycler gRecycler;
|
|
|
|
return gRecycler;
|
|
|
|
}
|
1999-07-17 11:26:16 +04:00
|
|
|
#endif
|
|
|
|
|
1999-03-23 10:26:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this mehod when you're done
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-23 10:26:27 +03:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-09-02 11:04:59 +04:00
|
|
|
nsString* nsString::CreateString(void){
|
1999-07-17 11:26:16 +04:00
|
|
|
nsString* result=0;
|
|
|
|
#ifndef RICKG_TESTBED
|
1999-09-02 11:04:59 +04:00
|
|
|
GetRecycler().CreateString();
|
1999-07-17 11:26:16 +04:00
|
|
|
#endif
|
1999-03-23 10:26:27 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this mehod when you're done
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-23 10:26:27 +03:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
void nsString::Recycle(nsString* aString){
|
|
|
|
#ifndef RICKG_TESTBED
|
1999-03-23 10:26:27 +03:00
|
|
|
GetRecycler().Recycle(aString);
|
1999-07-17 11:26:16 +04:00
|
|
|
#else
|
|
|
|
delete aString;
|
|
|
|
#endif
|
1999-03-23 10:26:27 +03:00
|
|
|
}
|
|
|
|
|
1999-07-17 14:08:10 +04:00
|
|
|
#if 0
|
1999-03-22 12:54:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess8/8/98
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
ostream& operator<<(ostream& aStream,const nsString& aString){
|
1999-06-03 14:49:14 +04:00
|
|
|
if(eOneByte==aString.mCharSize) {
|
|
|
|
aStream<<aString.mStr;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
else{
|
1999-06-03 14:49:14 +04:00
|
|
|
PRUint32 theOffset=0;
|
|
|
|
const PRUint32 theBufSize=300;
|
|
|
|
char theBuf[theBufSize+1];
|
|
|
|
PRUint32 theCount=0;
|
|
|
|
PRUint32 theRemains=0;
|
|
|
|
|
|
|
|
while(theOffset<aString.mLength){
|
|
|
|
theRemains=aString.mLength-theOffset;
|
|
|
|
theCount=(theRemains<theBufSize) ? theRemains : theBufSize;
|
|
|
|
aString.ToCString(theBuf,theCount+1,theOffset);
|
|
|
|
theBuf[theCount]=0;
|
|
|
|
aStream<<theBuf;
|
|
|
|
theOffset+=theCount;
|
|
|
|
}
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
1999-09-07 02:59:11 +04:00
|
|
|
return aStream;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
1999-07-17 14:08:10 +04:00
|
|
|
#endif
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-11-19 11:05:30 +03:00
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
|
|
|
*
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 01/04/99
|
1999-03-22 12:54:46 +03:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
NS_COM int fputs(const nsString& aString, FILE* out)
|
1999-03-22 12:54:46 +03:00
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
char* cp = buf;
|
|
|
|
PRInt32 len = aString.mLength;
|
|
|
|
if (len >= PRInt32(sizeof(buf))) {
|
|
|
|
cp = aString.ToNewCString();
|
|
|
|
} else {
|
|
|
|
aString.ToCString(cp, len + 1);
|
|
|
|
}
|
|
|
|
if(len>0)
|
|
|
|
::fwrite(cp, 1, len, out);
|
|
|
|
if (cp != buf) {
|
1999-03-30 05:23:24 +04:00
|
|
|
delete[] cp;
|
1999-03-22 12:54:46 +03:00
|
|
|
}
|
|
|
|
return (int) len;
|
|
|
|
}
|
|
|
|
|
1999-11-19 11:05:30 +03:00
|
|
|
/**
|
|
|
|
* Dumps the contents of the string to stdout
|
|
|
|
* @update gess 11/15/99
|
|
|
|
*/
|
|
|
|
void nsString::DebugDump(void) const {
|
|
|
|
|
|
|
|
const char* theBuffer=mStr;
|
|
|
|
nsCAutoString temp;
|
|
|
|
|
|
|
|
if(eTwoByte==mCharSize) {
|
|
|
|
temp.Assign(*this);
|
|
|
|
theBuffer=temp.GetBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(theBuffer) {
|
|
|
|
printf("\n%s",theBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
/***********************************************************************
|
|
|
|
IMPLEMENTATION NOTES: AUTOSTRING...
|
|
|
|
***********************************************************************/
|
1999-04-25 06:05:03 +04:00
|
|
|
|
|
|
|
|
1999-03-22 12:54:46 +03:00
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Default constructor
|
|
|
|
*
|
1999-05-06 09:13:08 +04:00
|
|
|
*/
|
1999-09-02 11:04:59 +04:00
|
|
|
nsAutoString::nsAutoString() : nsString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
1999-05-06 09:13:08 +04:00
|
|
|
AddNullTerminator(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy construct from ascii c-string
|
|
|
|
* @param aCString is a ptr to a 1-byte cstr
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aLength tells us how many chars to copy from aCString
|
1999-05-06 09:13:08 +04:00
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
nsAutoString::nsAutoString(const char* aCString,PRInt32 aLength) : nsString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
1999-05-06 09:13:08 +04:00
|
|
|
AddNullTerminator(*this);
|
1999-07-17 11:26:16 +04:00
|
|
|
Append(aCString,aLength);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy construct from uni-string
|
|
|
|
* @param aString is a ptr to a unistr
|
1999-08-30 10:55:13 +04:00
|
|
|
* @param aLength tells us how many chars to copy from aString
|
1999-05-06 09:13:08 +04:00
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
nsAutoString::nsAutoString(const PRUnichar* aString,PRInt32 aLength) : nsString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
1999-05-06 09:13:08 +04:00
|
|
|
AddNullTerminator(*this);
|
1999-07-17 11:26:16 +04:00
|
|
|
Append(aString,aLength);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* constructor that uses external buffer
|
|
|
|
* @param aBuffer describes the external buffer
|
1999-05-06 09:13:08 +04:00
|
|
|
*/
|
1999-09-02 12:02:57 +04:00
|
|
|
nsAutoString::nsAutoString(const CBufDescriptor& aBuffer) : nsString() {
|
1999-07-17 11:26:16 +04:00
|
|
|
if(!aBuffer.mBuffer) {
|
|
|
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-07-17 11:26:16 +04:00
|
|
|
nsStr::Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
1999-09-19 20:43:09 +04:00
|
|
|
if(!aBuffer.mIsConst)
|
|
|
|
AddNullTerminator(*this);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-05-06 09:13:08 +04:00
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Copy construct from an nsStr
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param
|
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
nsAutoString::nsAutoString(const nsStr& aString) : nsString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
1999-05-06 09:13:08 +04:00
|
|
|
AddNullTerminator(*this);
|
1999-07-17 11:26:16 +04:00
|
|
|
Append(aString);
|
1999-07-09 10:01:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Default copy constructor
|
1999-07-09 10:01:55 +04:00
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
nsAutoString::nsAutoString(const nsAutoString& aString) : nsString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
1999-07-09 10:01:55 +04:00
|
|
|
AddNullTerminator(*this);
|
1999-07-17 11:26:16 +04:00
|
|
|
Append(aString);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
1999-08-30 10:55:13 +04:00
|
|
|
* Copy construct from a unichar
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param
|
|
|
|
*/
|
1999-08-30 10:55:13 +04:00
|
|
|
nsAutoString::nsAutoString(PRUnichar aChar) : nsString(){
|
|
|
|
nsStr::Initialize(*this,mBuffer,(sizeof(mBuffer)>>eTwoByte)-1,0,eTwoByte,PR_FALSE);
|
1999-05-06 09:13:08 +04:00
|
|
|
AddNullTerminator(*this);
|
1999-07-17 11:26:16 +04:00
|
|
|
Append(aChar);
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* construct from a subsumeable string
|
1999-09-07 02:59:11 +04:00
|
|
|
* @update gess 1/4/99
|
1999-05-06 09:13:08 +04:00
|
|
|
* @param reference to a subsumeString
|
|
|
|
*/
|
1999-06-05 02:08:19 +04:00
|
|
|
#ifdef AIX
|
1999-09-02 11:04:59 +04:00
|
|
|
nsAutoString::nsAutoString(const nsSubsumeStr& aSubsumeStr) :nsString() {
|
1999-06-05 02:08:19 +04:00
|
|
|
nsSubsumeStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
|
|
|
Subsume(*this,temp);
|
|
|
|
#else
|
1999-09-02 11:04:59 +04:00
|
|
|
nsAutoString::nsAutoString( nsSubsumeStr& aSubsumeStr) :nsString() {
|
1999-05-06 09:13:08 +04:00
|
|
|
Subsume(*this,aSubsumeStr);
|
1999-06-05 02:08:19 +04:00
|
|
|
#endif // AIX
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* deconstruct the autstring
|
|
|
|
* @param
|
|
|
|
*/
|
1999-07-17 11:26:16 +04:00
|
|
|
nsAutoString::~nsAutoString(){
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
1999-08-31 07:04:37 +04:00
|
|
|
void nsAutoString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
|
|
|
}
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
2000-02-11 15:11:03 +03:00
|
|
|
nsSubsumeStr::nsSubsumeStr() : nsString() {
|
|
|
|
}
|
|
|
|
|
1999-09-02 11:04:59 +04:00
|
|
|
nsSubsumeStr::nsSubsumeStr(nsStr& aString) : nsString() {
|
2000-02-11 15:11:03 +03:00
|
|
|
::Subsume(*this,aString);
|
1999-07-09 10:01:55 +04:00
|
|
|
}
|
|
|
|
|
1999-09-02 11:04:59 +04:00
|
|
|
nsSubsumeStr::nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) : nsString() {
|
1999-05-29 11:29:46 +04:00
|
|
|
mUStr=aString;
|
2000-02-11 15:11:03 +03:00
|
|
|
mCharSize=eTwoByte;
|
1999-09-02 11:04:59 +04:00
|
|
|
mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
|
1999-05-29 11:29:46 +04:00
|
|
|
mOwnsBuffer=assumeOwnership;
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
1999-06-03 14:49:14 +04:00
|
|
|
|
1999-09-02 11:04:59 +04:00
|
|
|
nsSubsumeStr::nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) : nsString() {
|
1999-05-29 11:29:46 +04:00
|
|
|
mStr=aString;
|
1999-09-02 11:04:59 +04:00
|
|
|
mCharSize=eOneByte;
|
|
|
|
mCapacity=mLength=(-1==aLength) ? strlen(aString) : aLength;
|
1999-05-29 11:29:46 +04:00
|
|
|
mOwnsBuffer=assumeOwnership;
|
1999-05-06 09:13:08 +04:00
|
|
|
}
|
|
|
|
|
2000-02-11 18:19:17 +03:00
|
|
|
int nsSubsumeStr::Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) {
|
2000-02-11 15:11:03 +03:00
|
|
|
mUStr=aString;
|
|
|
|
mCharSize=eTwoByte;
|
|
|
|
mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
|
|
|
|
mOwnsBuffer=assumeOwnership;
|
2000-02-11 18:19:17 +03:00
|
|
|
return 0;
|
2000-02-11 15:11:03 +03:00
|
|
|
}
|