1999-07-17 07:26:16 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-13 20:24:54 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-07-17 07:26:16 +00:00
|
|
|
*/
|
1998-09-04 17:26:37 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
#include <ctype.h>
|
1999-07-17 07:26:16 +00:00
|
|
|
#include <string.h>
|
1998-04-13 20:24:54 +00:00
|
|
|
#include <stdio.h>
|
1999-09-20 05:32:36 +00:00
|
|
|
#include <stdlib.h>
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsString.h"
|
1999-07-09 06:01:55 +00:00
|
|
|
#include "nsDebug.h"
|
1999-07-17 07:26:16 +00:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsDeque.h"
|
|
|
|
|
|
|
|
#ifndef RICKG_TESTBED
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "prdtoa.h"
|
1998-06-05 21:38:36 +00:00
|
|
|
#include "nsISizeOfHandler.h"
|
1999-07-17 07:26:16 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
static const char* kNullPointerError = "Error: unexpected null ptr";
|
|
|
|
static const char* kWhitespace="\b\t\r\n ";
|
1998-08-03 20:46:38 +00:00
|
|
|
|
|
|
|
|
1999-01-09 01:09:39 +00:00
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
static void CSubsume(nsStr& aDest,nsStr& aSource){
|
|
|
|
if(aSource.mStr && aSource.mLength) {
|
|
|
|
if(aSource.mOwnsBuffer){
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Destroy(aDest);
|
1999-07-17 07:26:16 +00:00
|
|
|
aDest.mStr=aSource.mStr;
|
|
|
|
aDest.mLength=aSource.mLength;
|
|
|
|
aDest.mCharSize=aSource.mCharSize;
|
|
|
|
aDest.mCapacity=aSource.mCapacity;
|
|
|
|
aDest.mOwnsBuffer=aSource.mOwnsBuffer;
|
|
|
|
aSource.mOwnsBuffer=PR_FALSE;
|
|
|
|
aSource.mStr=0;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
else{
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Assign(aDest,aSource,0,aSource.mLength);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
}
|
1999-10-05 04:47:19 +00:00
|
|
|
else nsStr::Truncate(aDest,0);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-02-08 18:57:21 +00:00
|
|
|
|
1999-05-06 05:13:08 +00:00
|
|
|
|
1998-05-20 16:21:48 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Default constructor.
|
1998-05-20 16:21:48 +00:00
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
nsCString::nsCString() {
|
1999-07-17 07:26:16 +00:00
|
|
|
nsStr::Initialize(*this,eOneByte);
|
1998-05-20 16:21:48 +00:00
|
|
|
}
|
|
|
|
|
1999-07-09 05:11:25 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* This constructor accepts an ascii string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 1/4/99
|
1999-07-09 05:11:25 +00:00
|
|
|
* @param aCString is a ptr to a 1-byte cstr
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aLength tells us how many chars to copy from given CString
|
1999-07-09 05:11:25 +00:00
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
nsCString::nsCString(const char* aCString,PRInt32 aLength) {
|
1999-07-17 07:26:16 +00:00
|
|
|
nsStr::Initialize(*this,eOneByte);
|
|
|
|
Assign(aCString,aLength);
|
1999-07-09 05:11:25 +00:00
|
|
|
}
|
1998-07-30 18:35:58 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* This constructor accepts a unicode string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 1/4/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aString is a ptr to a unichar string
|
|
|
|
* @param aLength tells us how many chars to copy from given aString
|
1999-07-17 07:26:16 +00:00
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
nsCString::nsCString(const PRUnichar* aString,PRInt32 aLength) {
|
1999-07-17 07:26:16 +00:00
|
|
|
nsStr::Initialize(*this,eOneByte);
|
1999-11-14 06:22:52 +00:00
|
|
|
Assign(aString,aLength);
|
1999-07-17 07:26:16 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* This constructor works for all other nsSTr derivatives
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 1/4/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param reference to another nsCString
|
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
nsCString::nsCString(const nsStr &aString) {
|
1999-07-17 07:26:16 +00:00
|
|
|
nsStr::Initialize(*this,eOneByte);
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Assign(*this,aString,0,aString.mLength);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-09 05:11:25 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* This is our copy constructor
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 1/4/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param reference to another nsCString
|
1999-07-09 05:11:25 +00:00
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
nsCString::nsCString(const nsCString& aString) {
|
1999-07-17 07:26:16 +00:00
|
|
|
nsStr::Initialize(*this,aString.mCharSize);
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Assign(*this,aString,0,aString.mLength);
|
1999-07-09 05:11:25 +00:00
|
|
|
}
|
1998-08-03 20:46:38 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* construct from subsumeable string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 1/4/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param reference to a subsumeString
|
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
nsCString::nsCString(nsSubsumeCStr& aSubsumeStr) {
|
1999-07-17 07:26:16 +00:00
|
|
|
CSubsume(*this,aSubsumeStr);
|
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString::~nsCString() {
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Destroy(*this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-08-31 03:04:37 +00:00
|
|
|
void nsCString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
}
|
1998-09-04 17:26:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method truncates this string to given length.
|
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-09-04 17:26:37 +00:00
|
|
|
* @param anIndex -- new length of string
|
|
|
|
* @return nada
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
void nsCString::Truncate(PRInt32 anIndex) {
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Truncate(*this,anIndex);
|
1998-06-05 21:38:36 +00:00
|
|
|
}
|
|
|
|
|
1998-08-29 05:06:50 +00: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 07:26:16 +00:00
|
|
|
PRBool nsCString::IsOrdered(void) const {
|
1998-08-29 05:06:50 +00:00
|
|
|
PRBool result=PR_TRUE;
|
|
|
|
if(mLength>1) {
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUint32 theIndex;
|
1998-08-29 05:06:50 +00:00
|
|
|
for(theIndex=1;theIndex<mLength;theIndex++) {
|
1998-10-26 22:33:39 +00:00
|
|
|
if(mStr[theIndex-1]>mStr[theIndex]) {
|
1998-08-29 05:06:50 +00:00
|
|
|
result=PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1998-08-03 20:46:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Call this method if you want to force the string to a certain capacity
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 1/4/99
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param aLength -- contains new length for mStr
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
void nsCString::SetCapacity(PRUint32 aLength) {
|
|
|
|
if(aLength>mCapacity) {
|
1999-10-05 04:47:19 +00:00
|
|
|
GrowCapacity(*this,aLength);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
AddNullTerminator(*this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Accessor methods...
|
|
|
|
*********************************************************************/
|
1999-07-09 05:11:25 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Retrieves internal (1-byte) buffer ptr;
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess1/4/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @return ptr to internal buffer
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
const char* nsCString::GetBuffer(void) const {
|
1999-07-09 06:01:55 +00:00
|
|
|
return mStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Get nth character.
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUnichar nsCString::operator[](PRUint32 anIndex) const {
|
|
|
|
return GetCharAt(*this,anIndex);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
/**
|
|
|
|
* Get nth character.
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUnichar nsCString::CharAt(PRUint32 anIndex) const {
|
|
|
|
return GetCharAt(*this,anIndex);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
/**
|
|
|
|
* Get 1st character.
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUnichar nsCString::First(void) const{
|
|
|
|
return GetCharAt(*this,0);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
/**
|
|
|
|
* Get last character.
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUnichar nsCString::Last(void) const{
|
1999-07-25 17:20:37 +00:00
|
|
|
return (char)GetCharAt(*this,mLength-1);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-08-30 06:55:13 +00: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 07:26:16 +00:00
|
|
|
PRBool nsCString::SetCharAt(PRUnichar aChar,PRUint32 anIndex){
|
1999-03-22 08:29:26 +00:00
|
|
|
PRBool result=PR_FALSE;
|
|
|
|
if(anIndex<mLength){
|
1999-07-25 17:20:37 +00:00
|
|
|
mStr[anIndex]=(char)aChar;
|
1999-03-22 08:29:26 +00:00
|
|
|
result=PR_TRUE;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-11-14 06:22:52 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/*********************************************************
|
|
|
|
append (operator+) METHODS....
|
|
|
|
*********************************************************/
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1998-04-13 20:24:54 +00:00
|
|
|
* Create a new string by appending given string to this
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param aString -- 2nd string to be appended
|
1999-08-30 06:55:13 +00:00
|
|
|
* @return new subsumeable string (this makes things faster by reducing copying)
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsSubsumeCStr nsCString::operator+(const nsCString& aString){
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString temp(*this); //make a temp string the same size as this...
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Append(temp,aString,0,aString.mLength);
|
1999-07-17 07:26:16 +00:00
|
|
|
return nsSubsumeCStr(temp);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1998-04-13 20:24:54 +00:00
|
|
|
* create a new string by adding this to the given buffer.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-11-20 22:11:09 +00:00
|
|
|
* @param aCString is a ptr to cstring to be added to this
|
1999-08-30 06:55:13 +00:00
|
|
|
* @return newly created subsumable string
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsSubsumeCStr nsCString::operator+(const char* aCString) {
|
|
|
|
nsCString temp(*this);
|
1998-11-20 22:11:09 +00:00
|
|
|
temp.Append(aCString);
|
1999-07-17 07:26:16 +00:00
|
|
|
return nsSubsumeCStr(temp);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1998-04-13 20:24:54 +00:00
|
|
|
* create a new string by adding this to the given char.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param aChar is a char to be added to this
|
1999-08-30 06:55:13 +00:00
|
|
|
* @return newly created subsumable string
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsSubsumeCStr nsCString::operator+(PRUnichar aChar) {
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString temp(*this);
|
1999-07-25 17:20:37 +00:00
|
|
|
temp.Append(aChar);
|
1999-07-17 07:26:16 +00:00
|
|
|
return nsSubsumeCStr(temp);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1998-04-13 20:24:54 +00:00
|
|
|
* create a new string by adding this to the given char.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-25 17:20:37 +00:00
|
|
|
* @param aChar is a char to be added to this
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return newly created string
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsSubsumeCStr nsCString::operator+(char aChar) {
|
|
|
|
nsCString temp(*this);
|
|
|
|
temp.Append(aChar);
|
1999-07-17 07:26:16 +00:00
|
|
|
return nsSubsumeCStr(temp);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Lexomorphic transforms...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts all chars in internal string to lower
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
*/
|
|
|
|
void nsCString::ToLowerCase() {
|
|
|
|
nsStr::ChangeCase(*this,PR_FALSE);
|
1999-07-09 05:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-09 06:01:55 +00:00
|
|
|
* Converts all chars in internal string to upper
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-09 05:11:25 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
void nsCString::ToUpperCase() {
|
|
|
|
nsStr::ChangeCase(*this,PR_TRUE);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-01-09 01:09:39 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Converts chars in this to lowercase, and
|
|
|
|
* stores them in aString
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aOut is a string to contain result
|
1999-01-09 01:09:39 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
void nsCString::ToLowerCase(nsCString& aString) const {
|
|
|
|
aString=*this;
|
|
|
|
nsStr::ChangeCase(aString,PR_FALSE);
|
1999-01-09 01:09:39 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Converts chars in this to uppercase, and
|
1999-07-17 07:26:16 +00:00
|
|
|
* stores them in a given output string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-09 06:01:55 +00:00
|
|
|
* @param aOut is a string to contain result
|
1999-07-09 05:11:25 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
void nsCString::ToUpperCase(nsCString& aString) const {
|
|
|
|
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 00:30:29 +00:00
|
|
|
* @update gess 11/02/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aChar -- char to be stripped
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return *this
|
|
|
|
*/
|
1999-12-03 00:30:29 +00:00
|
|
|
nsCString& nsCString::StripChar(PRUnichar aChar,PRInt32 anOffset){
|
|
|
|
|
|
|
|
anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset);
|
|
|
|
while(kNotFound<anOffset) {
|
|
|
|
nsStr::Delete(*this,anOffset,1);
|
|
|
|
anOffset=nsStr::FindChar(*this,aChar,PR_FALSE,anOffset);
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
nsCString& nsCString::StripChars(const char* aSet){
|
1999-09-30 04:03:49 +00:00
|
|
|
nsStr::StripChars(*this,aSet);
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* This method strips whitespace throughout the string
|
|
|
|
*
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::StripWhitespace() {
|
|
|
|
return StripChars(kWhitespace);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
nsCString& nsCString::ReplaceChar(PRUnichar aOldChar, PRUnichar aNewChar) {
|
|
|
|
PRUint32 theIndex=0;
|
|
|
|
for(theIndex=0;theIndex<mLength;theIndex++){
|
|
|
|
if(mStr[theIndex]==(char)aOldChar) {
|
|
|
|
mStr[theIndex]=(char)aNewChar;
|
|
|
|
}//if
|
1999-03-07 19:23:28 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
nsCString& nsCString::ReplaceChar(const char* aSet, PRUnichar aNewChar){
|
|
|
|
if(aSet){
|
|
|
|
PRInt32 theIndex=FindCharInSet(aSet,0);
|
|
|
|
while(kNotFound<theIndex) {
|
|
|
|
mStr[theIndex]=(char)aNewChar;
|
|
|
|
theIndex=FindCharInSet(aSet,theIndex+1);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-12-02 10:14:38 +00:00
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given target with the given replacement
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
|
|
|
nsCString& nsCString::ReplaceSubstring(const char* aTarget,const char* aNewValue){
|
|
|
|
if(aTarget && aNewValue) {
|
|
|
|
|
|
|
|
PRInt32 len=strlen(aTarget);
|
|
|
|
if(0<len) {
|
|
|
|
CBufDescriptor theDesc1(aTarget,PR_TRUE, len+1,len);
|
|
|
|
nsCAutoString theTarget(theDesc1);
|
|
|
|
|
|
|
|
len=strlen(aNewValue);
|
|
|
|
if(0<len) {
|
|
|
|
CBufDescriptor theDesc2(aNewValue,PR_TRUE, len+1,len);
|
|
|
|
nsCAutoString 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
|
|
|
|
*/
|
|
|
|
nsCString& nsCString::ReplaceSubstring(const nsCString& aTarget,const nsCString& 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;
|
|
|
|
while(kNotFound!=(theIndex=nsStr::FindSubstr(*this,aTarget,PR_FALSE,theIndex))) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::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;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* This method trims characters found in aTrimSet from
|
|
|
|
* either end of the underlying string.
|
|
|
|
*
|
|
|
|
* @update gess 3/31/98
|
|
|
|
* @param aTrimSet -- contains chars to be trimmed from
|
|
|
|
* both ends
|
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::Trim(const char* aTrimSet, PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
|
|
|
if(aTrimSet){
|
|
|
|
nsStr::Trim(*this,aTrimSet,aEliminateLeading,aEliminateTrailing);
|
|
|
|
}
|
|
|
|
return *this;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* This method strips chars in given set from string.
|
|
|
|
* You can control whether chars are yanked from
|
1999-07-17 07:26:16 +00: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
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
|
|
|
if(aSet){
|
|
|
|
ReplaceChar(aSet,aChar);
|
|
|
|
nsStr::CompressSet(*this,aSet,aEliminateLeading,aEliminateTrailing);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* 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
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::CompressWhitespace( PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
|
|
|
CompressSet(kWhitespace,' ',aEliminateLeading,aEliminateTrailing);
|
|
|
|
return *this;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**********************************************************************
|
|
|
|
string conversion methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Creates a duplicate clone (ptr) of this string.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return ptr to clone of this string
|
|
|
|
*/
|
|
|
|
nsCString* nsCString::ToNewString() const {
|
|
|
|
return new nsCString(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ascii clone of this string
|
1999-08-30 06:55:13 +00:00
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return ptr to new ascii string
|
|
|
|
*/
|
|
|
|
char* nsCString::ToNewCString() const {
|
|
|
|
nsCString temp(mStr);
|
|
|
|
temp.SetCapacity(8);
|
|
|
|
char* result=temp.mStr;
|
|
|
|
temp.mStr=0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Creates an unicode clone of this string
|
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return ptr to new ascii string
|
|
|
|
*/
|
|
|
|
PRUnichar* nsCString::ToNewUnicode() const {
|
|
|
|
nsString temp(mStr);
|
|
|
|
temp.SetCapacity(8);
|
|
|
|
PRUnichar* result=temp.mUStr;
|
|
|
|
temp.mStr=0;
|
|
|
|
temp.mOwnsBuffer=PR_FALSE;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies contents of this string into he given buffer
|
1999-08-30 06:55:13 +00: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-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aBuf
|
|
|
|
* @param aBufLength
|
|
|
|
* @param anOffset
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
char* nsCString::ToCString(char* aBuf, PRUint32 aBufLength,PRUint32 anOffset) const{
|
|
|
|
if(aBuf) {
|
1999-08-30 06:55:13 +00: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 07:26:16 +00:00
|
|
|
temp.mStr=0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
return aBuf;
|
|
|
|
}
|
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
|
|
|
* Perform string to float conversion.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return float rep of string value
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
float nsCString::ToFloat(PRInt32* aErrorCode) const {
|
|
|
|
char buf[100];
|
1998-07-25 02:11:02 +00:00
|
|
|
if (mLength > PRInt32(sizeof(buf)-1)) {
|
1998-04-26 03:13:20 +00:00
|
|
|
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
1998-04-13 20:24:54 +00:00
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
char* cp = ToCString(buf, sizeof(buf));
|
|
|
|
float f = (float) PR_strtod(cp, &cp);
|
|
|
|
if (*cp != 0) {
|
1998-04-26 03:13:20 +00:00
|
|
|
*aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-04-26 03:13:20 +00:00
|
|
|
*aErrorCode = (PRInt32) NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1998-10-04 04:52:10 +00:00
|
|
|
* Perform numeric string to int conversion with given radix.
|
2000-01-18 21:06:05 +00:00
|
|
|
* NOTE: 1. This method mandates that the string is well formed and uppercased.
|
1999-07-17 07:26:16 +00:00
|
|
|
* 2. This method will return an error if the string you give
|
|
|
|
contains chars outside the range for the specified radix.
|
|
|
|
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 10/01/98
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param aErrorCode will contain error if one occurs
|
1998-10-04 04:52:10 +00:00
|
|
|
* @param aRadix tells us what base to expect the string in.
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return int rep of string value
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 _ToInteger(nsCString& aString,PRInt32* anErrorCode,PRUint32 aRadix) {
|
1998-10-04 04:52:10 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
|
|
|
PRInt32 result=0;
|
1998-11-24 02:38:21 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
char* cp = aString.mStr + aString.mLength;
|
|
|
|
PRInt32 theMult=1;
|
1999-01-10 08:17:40 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
*anErrorCode = NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-10-04 04:52:10 +00:00
|
|
|
//now iterate the numeric chars and build our result
|
1999-07-17 07:26:16 +00:00
|
|
|
char theChar=0;
|
|
|
|
char theDigit=0;
|
|
|
|
while(--cp>=aString.mStr){
|
1999-08-25 03:11:05 +00:00
|
|
|
theChar=*cp;
|
1998-10-04 04:52:10 +00:00
|
|
|
if((theChar>='0') && (theChar<='9')){
|
1999-07-17 07:26:16 +00:00
|
|
|
theDigit=theChar-'0';
|
1998-10-04 04:52:10 +00:00
|
|
|
}
|
|
|
|
else if((theChar>='A') && (theChar<='F')) {
|
1999-07-17 07:26:16 +00:00
|
|
|
if(10==aRadix){
|
|
|
|
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
result=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
theDigit=(theChar-'A')+10;
|
1998-10-04 04:52:10 +00:00
|
|
|
}
|
1999-10-05 04:47:19 +00:00
|
|
|
else if((theChar>='a') && (theChar<='f')) {
|
|
|
|
if(10==aRadix){
|
|
|
|
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
result=0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
theDigit=(theChar-'a')+10;
|
|
|
|
}
|
1998-10-04 04:52:10 +00:00
|
|
|
else if('-'==theChar) {
|
|
|
|
result=-result;
|
|
|
|
break;
|
|
|
|
}
|
1999-10-05 04:47:19 +00:00
|
|
|
else if(('+'==theChar) || (' '==theChar) || ('X'==theChar) || ('x'==theChar)) { //stop in a good state if you see this...
|
1999-07-09 06:01:55 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
else {
|
|
|
|
//we've encountered a char that's not a legal number or sign
|
|
|
|
*anErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
1998-11-24 02:38:21 +00:00
|
|
|
result=0;
|
1998-10-04 04:52:10 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
|
|
|
|
result+=theDigit*theMult;
|
1998-10-04 04:52:10 +00:00
|
|
|
theMult*=aRadix;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-10-04 04:52:10 +00:00
|
|
|
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Call this method to extract the rightmost numeric value from the given
|
|
|
|
* 1-byte input string, and simultaneously determine the radix.
|
|
|
|
* NOTE: This method mandates that the string is well formed.
|
2000-01-18 21:06:05 +00:00
|
|
|
* Leading and trailing gunk should be removed, and upper-cased.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 10/01/98
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param anInputString contains orig string
|
|
|
|
* @param anOutString contains numeric portion copy of input string
|
|
|
|
* @param aRadix (an out parm) tells the caller what base we think the string is in.
|
|
|
|
* @return non-zero error code if this string is non-numeric
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
static PRInt32 GetNumericSubstring(nsCString& aString,PRUint32& aRadix) {
|
1998-07-30 20:36:51 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
const char* cp=aString.GetBuffer();
|
|
|
|
PRInt32 result=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
if(cp) {
|
1998-04-13 20:24:54 +00:00
|
|
|
|
2000-01-18 21:06:05 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
//begin by skipping over leading chars that shouldn't be part of the number...
|
|
|
|
|
|
|
|
char* to=(char*)cp;
|
|
|
|
const char* endcp=cp+aString.mLength;
|
2000-01-18 21:06:05 +00:00
|
|
|
PRBool done=PR_FALSE;
|
|
|
|
|
|
|
|
while(!done){
|
|
|
|
switch(*cp) {
|
|
|
|
case '0': case '1': case '2': case '3': case '4':
|
|
|
|
case '5': case '6': case '7': case '8': case '9':
|
|
|
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
|
|
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
|
|
|
case '-': case '+': case '#':
|
|
|
|
done=PR_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cp++;
|
|
|
|
done=cp<endcp;
|
|
|
|
break;
|
|
|
|
} //switch
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
|
2000-01-18 21:06:05 +00:00
|
|
|
while(cp<endcp) {
|
|
|
|
char theChar=*cp;
|
|
|
|
|
|
|
|
if('A'<=theChar) {
|
|
|
|
if('F'>=theChar) {
|
|
|
|
aRadix=16;
|
|
|
|
*to++=theChar;
|
|
|
|
}
|
|
|
|
else if('X'==theChar) {
|
|
|
|
if('-'==aString.mStr[0])
|
|
|
|
to=&aString.mStr[1];
|
|
|
|
else to=aString.mStr;
|
|
|
|
aRadix=16;
|
|
|
|
}
|
|
|
|
else if('a'<=theChar) {
|
|
|
|
if('f'>=theChar) {
|
|
|
|
aRadix=16;
|
|
|
|
*to++='A'+(theChar-'a');
|
|
|
|
}
|
|
|
|
else if('x'==theChar) {
|
|
|
|
if('-'==aString.mStr[0])
|
|
|
|
to=&aString.mStr[1];
|
|
|
|
else to=aString.mStr;
|
|
|
|
aRadix=16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else break; //bad char
|
1999-10-05 04:47:19 +00:00
|
|
|
}
|
2000-01-18 21:06:05 +00:00
|
|
|
else if((theChar>='0') && (theChar<='9')) {
|
1999-10-05 04:47:19 +00:00
|
|
|
*to++=theChar;
|
|
|
|
}
|
|
|
|
else if('-'==theChar) {
|
|
|
|
*to++=theChar;
|
|
|
|
}
|
2000-01-18 21:06:05 +00:00
|
|
|
else if(('#'!=theChar) && ('+'!=theChar)){
|
|
|
|
break; //terminate on invalid char!
|
1999-10-05 04:47:19 +00:00
|
|
|
}
|
|
|
|
cp++;
|
1999-07-17 07:26:16 +00:00
|
|
|
}
|
2000-01-18 21:06:05 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
aString.Truncate(to-aString.mStr);
|
|
|
|
result=(0==aString.mLength) ? NS_ERROR_ILLEGAL_VALUE : NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-09 05:11:25 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1999-05-06 05:13:08 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* This method tries to autodetect that radix given a string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 10/01/98
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return 10,16,or 0 (meaning I don't know)
|
1999-05-06 05:13:08 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUint32 nsCString::DetermineRadix(void) {
|
|
|
|
PRUint32 result=kRadixUnknown;
|
|
|
|
if(0<mLength) {
|
|
|
|
nsCAutoString theString(*this);
|
|
|
|
if(NS_OK!=GetNumericSubstring(theString,result))
|
|
|
|
result=kRadixUnknown;
|
1999-05-06 05:13:08 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Perform decimal numeric string to int conversion.
|
|
|
|
* NOTE: In this version, we use the radix you give, even if it's wrong.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 10/01/98
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @param aRadix tells us what base to expect the given string in.
|
|
|
|
* @return int rep of string value
|
1999-07-09 06:01:55 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::ToInteger(PRInt32* anErrorCode,PRUint32 aRadix) const {
|
|
|
|
|
|
|
|
//copy chars to local buffer -- step down from 2 bytes to 1 if necessary...
|
1999-10-05 04:47:19 +00:00
|
|
|
PRInt32 result=0;
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCAutoString theString(*this);
|
|
|
|
PRUint32 theRadix=aRadix;
|
1999-10-05 04:47:19 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
*anErrorCode=GetNumericSubstring(theString,theRadix); //we actually don't use this radix; use given radix instead
|
1999-10-05 04:47:19 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
if(NS_OK==*anErrorCode){
|
|
|
|
if(kAutoDetect==aRadix)
|
|
|
|
aRadix=theRadix;
|
|
|
|
if((kRadix10==aRadix) || (kRadix16==aRadix))
|
|
|
|
result=_ToInteger(theString,anErrorCode,aRadix); //note we use the given radix, not the computed one.
|
|
|
|
else *anErrorCode=NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**********************************************************************
|
|
|
|
String manipulation methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
|
1998-09-04 17:26:37 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* assign given nsStr (or derivative) to this one
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aString: string to be appended
|
1998-09-04 17:26:37 +00:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-08-30 06:55:13 +00:00
|
|
|
nsCString& nsCString::Assign(const nsStr& aString,PRInt32 aCount) {
|
1999-07-17 07:26:16 +00:00
|
|
|
if(this!=&aString){
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-07-18 21:26:03 +00:00
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount=aString.mLength;
|
|
|
|
else aCount=MinInt(aCount,aString.mLength);
|
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Assign(*this,aString,0,aCount);
|
1999-07-17 07:26:16 +00:00
|
|
|
}
|
|
|
|
return *this;
|
1998-09-04 17:26:37 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1998-09-04 17:26:37 +00:00
|
|
|
/**
|
|
|
|
* assign given char* to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-11-20 22:11:09 +00:00
|
|
|
* @param aCString: buffer to be assigned to this
|
1999-11-19 08:05:30 +00: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.
|
|
|
|
*
|
1998-09-04 17:26:37 +00:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::Assign(const char* aCString,PRInt32 aCount) {
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-07-17 07:26:16 +00:00
|
|
|
if(aCString){
|
|
|
|
Append(aCString,aCount);
|
|
|
|
}
|
|
|
|
return *this;
|
1998-09-04 17:26:37 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* assign given unichar* to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aCString: buffer to be assigned to this
|
1999-11-19 08:05:30 +00: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 06:55:13 +00:00
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
nsCString& nsCString::Assign(const PRUnichar* aString,PRInt32 aCount) {
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-08-30 06:55:13 +00:00
|
|
|
|
1999-11-14 06:22:52 +00:00
|
|
|
if(aString && aCount){
|
1999-08-30 06:55:13 +00:00
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eTwoByte);
|
|
|
|
temp.mUStr=(PRUnichar*)aString;
|
|
|
|
|
|
|
|
if(0<aCount) {
|
|
|
|
temp.mLength=aCount;
|
1999-11-14 06:22:52 +00: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
|
1999-11-15 17:10:06 +00:00
|
|
|
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0);
|
|
|
|
NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Assign(PRUnichar*)");
|
1999-11-14 06:22:52 +00:00
|
|
|
#endif
|
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
}
|
|
|
|
else aCount=temp.mLength=nsCRT::strlen(aString);
|
|
|
|
|
|
|
|
if(0<aCount)
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Append(*this,temp,0,aCount);
|
1999-08-30 06:55:13 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-11-14 06:22:52 +00:00
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
/**
|
|
|
|
* assign given unichar to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param aChar: char to be assignd to this
|
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsCString& nsCString::Assign(PRUnichar aChar) {
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-07-17 07:26:16 +00:00
|
|
|
return Append(aChar);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* assign given char to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aChar: char to be assignd to this
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsCString& nsCString::Assign(char aChar) {
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Truncate(*this,0);
|
1999-07-17 07:26:16 +00:00
|
|
|
return Append(aChar);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00: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-06 22:59:11 +00:00
|
|
|
* @update gess10/30/98
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param
|
|
|
|
* @return
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
#ifdef AIX
|
|
|
|
nsCString& nsCString::operator=(const nsSubsumeCStr& aSubsumeString) {
|
|
|
|
nsSubsumeCStr temp(aSubsumeString); // a temp is needed for the AIX compiler
|
|
|
|
CSubsume(*this,temp);
|
|
|
|
#else
|
|
|
|
nsCString& nsCString::operator=(nsSubsumeCStr& aSubsumeString) {
|
|
|
|
CSubsume(*this,aSubsumeString);
|
|
|
|
#endif // AIX
|
1998-04-13 20:24:54 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1998-04-13 20:24:54 +00:00
|
|
|
* append given string to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsCString& nsCString::Append(const nsCString& aString,PRInt32 aCount) {
|
1999-07-18 21:26:03 +00:00
|
|
|
if(aCount<0)
|
|
|
|
aCount=aString.mLength;
|
|
|
|
else aCount=MinInt(aCount,aString.mLength);
|
1999-07-17 07:26:16 +00:00
|
|
|
if(0<aCount)
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Append(*this,aString,0,aCount);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* append given string to this string;
|
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
nsCString& nsCString::Append(const nsStr& aString,PRInt32 aCount) {
|
|
|
|
|
|
|
|
if(aCount<0)
|
|
|
|
aCount=aString.mLength;
|
|
|
|
else aCount=MinInt(aCount,aString.mLength);
|
|
|
|
|
|
|
|
if(0<aCount)
|
|
|
|
nsStr::Append(*this,aString,0,aCount);
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* append given c-string to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param aString : string to be appended to this
|
1999-07-25 17:20:37 +00:00
|
|
|
* @param aCount: #of chars to be copied; -1 means to copy the whole thing
|
1999-11-19 08:05:30 +00:00
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::Append(const char* aCString,PRInt32 aCount) {
|
|
|
|
if(aCString){
|
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eOneByte);
|
|
|
|
temp.mStr=(char*)aCString;
|
1999-07-20 06:58:41 +00:00
|
|
|
|
1999-07-25 17:20:37 +00:00
|
|
|
if(0<aCount) {
|
|
|
|
temp.mLength=aCount;
|
|
|
|
}
|
|
|
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
1999-07-20 06:58:41 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
if(0<aCount)
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Append(*this,temp,0,aCount);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1999-07-25 17:20:37 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* append given char to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aChar: char to be appended to this
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsCString& nsCString::Append(PRUnichar aChar) {
|
|
|
|
PRUnichar buf[2]={0,0};
|
|
|
|
buf[0]=aChar;
|
1999-07-20 06:58:41 +00:00
|
|
|
|
1999-07-25 17:20:37 +00:00
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eTwoByte);
|
|
|
|
temp.mUStr=buf;
|
|
|
|
temp.mLength=1;
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Append(*this,temp,0,1);
|
1998-04-13 20:24:54 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* append given unichar to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aChar: char to be appended to this
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::Append(char aChar) {
|
|
|
|
char buf[2]={0,0};
|
|
|
|
buf[0]=aChar;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
nsStr temp;
|
|
|
|
Initialize(temp,eOneByte);
|
|
|
|
temp.mStr=buf;
|
|
|
|
temp.mLength=1;
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Append(*this,temp,0,1);
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Append the given integer to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aInteger:
|
|
|
|
* @param aRadix:
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-09-30 04:03:49 +00:00
|
|
|
nsCString& nsCString::Append(PRInt32 anInteger,PRInt32 aRadix) {
|
1999-09-20 05:50:43 +00:00
|
|
|
|
1999-09-30 04:03:49 +00:00
|
|
|
PRUint32 theInt=(PRUint32)anInteger;
|
1999-09-20 05:10:32 +00:00
|
|
|
|
1999-09-30 04:03:49 +00: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 05:10:32 +00:00
|
|
|
|
1999-09-30 04:03:49 +00:00
|
|
|
PRInt32 radices[] = {1000000000,268435456};
|
|
|
|
PRInt32 mask1=radices[16==aRadix];
|
1999-09-20 05:10:32 +00:00
|
|
|
|
1999-09-30 04:03:49 +00:00
|
|
|
PRInt32 charpos=0;
|
|
|
|
if(anInteger<0) {
|
|
|
|
theInt*=-1;
|
|
|
|
if(10==aRadix) {
|
|
|
|
buf[charpos++]='-';
|
|
|
|
}
|
|
|
|
else theInt=(int)~(theInt-1);
|
1999-09-20 05:50:43 +00:00
|
|
|
}
|
|
|
|
|
1999-09-30 05:15:37 +00:00
|
|
|
PRBool isfirst=PR_TRUE;
|
1999-09-30 04:03:49 +00:00
|
|
|
while(mask1>=1) {
|
1999-10-05 04:47:19 +00:00
|
|
|
PRInt32 theDiv=theInt/mask1;
|
|
|
|
if((theDiv) || (!isfirst)) {
|
|
|
|
buf[charpos++]="0123456789abcdef"[theDiv];
|
1999-09-30 05:15:37 +00:00
|
|
|
isfirst=PR_FALSE;
|
1999-09-30 04:03:49 +00:00
|
|
|
}
|
1999-10-05 04:47:19 +00:00
|
|
|
theInt-=theDiv*mask1;
|
1999-09-30 04:03:49 +00:00
|
|
|
mask1/=aRadix;
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return Append(buf);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Append the given float to this string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aFloat:
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::Append(float aFloat){
|
1998-04-13 20:24:54 +00:00
|
|
|
char buf[40];
|
1999-07-17 07:26:16 +00:00
|
|
|
// *** XX UNCOMMENT THIS LINE
|
|
|
|
//PR_snprintf(buf, sizeof(buf), "%g", aFloat);
|
|
|
|
sprintf(buf,"%g",aFloat);
|
|
|
|
return Append(buf);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/*
|
1999-08-30 06:55:13 +00:00
|
|
|
* Copies n characters from this left of this string to given string,
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aDest -- Receiving string
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUint32 nsCString::Left(nsCString& aDest,PRInt32 aCount) const{
|
1999-07-18 21:26:03 +00:00
|
|
|
if(aCount<0)
|
|
|
|
aCount=mLength;
|
|
|
|
else aCount=MinInt(aCount,mLength);
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Assign(aDest,*this,0,aCount);
|
1999-07-17 07:26:16 +00:00
|
|
|
return aDest.mLength;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/*
|
1999-08-30 06:55:13 +00:00
|
|
|
* Copies n characters from this string to from given offset
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aDest -- Receiving string
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param anOffset -- where copying should begin
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRUint32 nsCString::Mid(nsCString& aDest,PRUint32 anOffset,PRInt32 aCount) const{
|
1999-07-18 21:26:03 +00:00
|
|
|
if(aCount<0)
|
|
|
|
aCount=mLength;
|
|
|
|
else aCount=MinInt(aCount,mLength);
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Assign(aDest,*this,anOffset,aCount);
|
1999-07-17 07:26:16 +00:00
|
|
|
return aDest.mLength;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/*
|
1999-08-30 06:55:13 +00:00
|
|
|
* Copies last n characters from this string to given string,
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aDest -- Receiving string
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-08-30 06:55:13 +00:00
|
|
|
PRUint32 nsCString::Right(nsCString& aDest,PRInt32 aCount) const{
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 offset=MaxInt(mLength-aCount,0);
|
1999-08-30 06:55:13 +00:00
|
|
|
return Mid(aDest,offset,aCount);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
|
|
|
|
/*
|
1998-04-13 20:24:54 +00:00
|
|
|
* This method inserts n chars from given string into this
|
|
|
|
* string at str[anOffset].
|
|
|
|
*
|
|
|
|
* @update gess 4/1/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aString -- source String to be inserted into this
|
1998-04-13 20:24:54 +00:00
|
|
|
* @param anOffset -- insertion position within this str
|
|
|
|
* @param aCount -- number of chars to be copied from aCopy
|
1999-08-30 06:55:13 +00:00
|
|
|
* @return this
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-08-30 06:55:13 +00:00
|
|
|
nsCString& nsCString::Insert(const nsCString& aString,PRUint32 anOffset,PRInt32 aCount) {
|
1999-07-18 21:26:03 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Insert(*this,anOffset,aString,0,aCount);
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Insert a char* into this string at a specified offset.
|
1999-07-17 07:26:16 +00:00
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess4/22/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param char* aCString to be inserted into this string
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param anOffset is insert pos in str
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aCounttells us how many chars to insert
|
|
|
|
* @return this
|
1999-07-17 07:26:16 +00:00
|
|
|
*/
|
|
|
|
nsCString& nsCString::Insert(const char* aCString,PRUint32 anOffset,PRInt32 aCount){
|
|
|
|
if(aCString){
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mStr=(char*)aCString;
|
1999-07-20 06:58:41 +00:00
|
|
|
|
1999-07-25 17:20:37 +00:00
|
|
|
if(0<aCount) {
|
|
|
|
temp.mLength=aCount;
|
1999-11-14 06:22:52 +00: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
|
1999-11-15 17:10:06 +00:00
|
|
|
PRInt32 len=nsStr::FindChar(temp,0,PR_FALSE,0);
|
|
|
|
NS_WARN_IF_FALSE(kNotFound==len,"possible embedded null in Insert(char*)");
|
1999-11-14 06:22:52 +00:00
|
|
|
#endif
|
|
|
|
|
1999-07-25 17:20:37 +00:00
|
|
|
}
|
|
|
|
else aCount=temp.mLength=nsCRT::strlen(aCString);
|
1999-07-20 06:58:41 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
if(temp.mLength && (0<aCount)){
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Insert(*this,anOffset,temp,0,aCount);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1998-04-25 19:44:35 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Insert a single unichar into this string at a specified offset.
|
1998-04-25 19:44:35 +00:00
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess4/22/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aChar unichar to be inserted into this string
|
1998-04-25 19:44:35 +00:00
|
|
|
* @param anOffset is insert pos in str
|
1999-08-30 06:55:13 +00:00
|
|
|
* @return this
|
1998-04-25 19:44:35 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsCString& nsCString::Insert(PRUnichar aChar,PRUint32 anOffset){
|
|
|
|
PRUnichar theBuffer[2]={0,0};
|
|
|
|
theBuffer[0]=aChar;
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mUStr=theBuffer;
|
|
|
|
temp.mLength=1;
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
1999-07-25 17:20:37 +00:00
|
|
|
return *this;
|
1999-07-17 07:26:16 +00:00
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
|
|
|
* Insert a single uni-char into this string at
|
|
|
|
* a specified offset.
|
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess4/22/98
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aChar char to be inserted into this string
|
|
|
|
* @param anOffset is insert pos in str
|
1999-08-30 06:55:13 +00:00
|
|
|
* @return this
|
1999-07-17 07:26:16 +00:00
|
|
|
*/
|
1999-07-25 17:20:37 +00:00
|
|
|
nsCString& nsCString::Insert(char aChar,PRUint32 anOffset){
|
|
|
|
char theBuffer[2]={0,0};
|
1999-07-17 07:26:16 +00:00
|
|
|
theBuffer[0]=aChar;
|
|
|
|
nsStr temp;
|
1999-07-25 17:20:37 +00:00
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mStr=theBuffer;
|
1999-07-17 07:26:16 +00:00
|
|
|
temp.mLength=1;
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Insert(*this,anOffset,temp,0,1);
|
1999-07-17 07:26:16 +00:00
|
|
|
return *this;
|
1998-04-25 19:44:35 +00:00
|
|
|
}
|
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/*
|
|
|
|
* This method is used to cut characters in this string
|
|
|
|
* starting at anOffset, continuing for aCount chars.
|
|
|
|
*
|
1999-07-17 07:26:16 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-09 06:01:55 +00:00
|
|
|
* @param anOffset -- start pos for cut operation
|
|
|
|
* @param aCount -- number of chars to be cut
|
|
|
|
* @return *this
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString& nsCString::Cut(PRUint32 anOffset, PRInt32 aCount) {
|
1999-07-18 21:26:03 +00:00
|
|
|
if(0<aCount) {
|
1999-10-05 04:47:19 +00:00
|
|
|
nsStr::Delete(*this,anOffset,aCount);
|
1999-07-18 21:26:03 +00:00
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
return *this;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Searching methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Search for given character within this string.
|
|
|
|
* This method does so by using a binary search,
|
|
|
|
* so your string HAD BETTER BE ORDERED!
|
1999-07-09 06:01:55 +00:00
|
|
|
*
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aChar is the unicode char to be found
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::BinarySearch(PRUnichar aChar) const{
|
|
|
|
PRInt32 low=0;
|
|
|
|
PRInt32 high=mLength-1;
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
while (low <= high) {
|
|
|
|
int middle = (low + high) >> 1;
|
|
|
|
PRUnichar theChar=GetCharAt(*this,middle);
|
|
|
|
if (theChar==aChar)
|
|
|
|
return middle;
|
|
|
|
if (theChar>aChar)
|
|
|
|
high = middle - 1;
|
|
|
|
else
|
|
|
|
low = middle + 1;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return kNotFound;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Search for given cstr within this string
|
1999-07-09 06:01:55 +00:00
|
|
|
*
|
1999-07-17 07:26:16 +00:00
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aCString - substr to be found
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1999-07-09 06:01:55 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::Find(const char* aCString,PRBool aIgnoreCase,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aCString) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aCString);
|
|
|
|
temp.mStr=(char*)aCString;
|
|
|
|
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1998-05-11 23:27:35 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
|
|
|
* Search for given buffer within this string
|
1999-07-09 06:01:55 +00:00
|
|
|
*
|
1999-07-17 07:26:16 +00:00
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aString unichar* to be found
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1999-07-09 06:01:55 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::Find(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{
|
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
|
|
|
|
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aString) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aString);
|
|
|
|
temp.mUStr=(PRUnichar*)aString;
|
|
|
|
result=nsStr::FindSubstr(*this,temp,aIgnoreCase,anOffset);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1998-08-03 20:46:38 +00:00
|
|
|
|
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Search for given string within this string
|
1999-07-09 06:01:55 +00:00
|
|
|
*
|
1999-07-17 07:26:16 +00:00
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aSTring -- buffer to be found
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
PRInt32 nsCString::Find(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::FindSubstr(*this,aString,aIgnoreCase,anOffset);
|
|
|
|
return result;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
|
|
|
* Search for a given char, starting at given offset
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aChar the unichar to be sought
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
PRInt32 nsCString::FindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::FindChar(*this,aChar,aIgnoreCase,anOffset);
|
|
|
|
return result;
|
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00: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-07-17 07:26:16 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset -- where in this string to start searching
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
PRInt32 nsCString::FindCharInSet(const char* aCStringSet,PRInt32 anOffset) const{
|
|
|
|
NS_ASSERTION(0!=aCStringSet,kNullPointerError);
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aCStringSet) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aCStringSet);
|
|
|
|
temp.mStr=(char*)aCStringSet;
|
|
|
|
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00: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
|
1998-08-29 05:06:50 +00:00
|
|
|
*
|
1999-07-09 06:01:55 +00:00
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aStringSet
|
|
|
|
* @param anOffset -- where in this string to start searching
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return
|
1998-08-29 05:06:50 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::FindCharInSet(const PRUnichar* aStringSet,PRInt32 anOffset) const{
|
|
|
|
NS_ASSERTION(0!=aStringSet,kNullPointerError);
|
1998-08-29 05:06:50 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aStringSet) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aStringSet);
|
|
|
|
temp.mStr=(char*)aStringSet;
|
|
|
|
result=nsStr::FindCharInSet(*this,temp,PR_FALSE,anOffset);
|
1998-08-29 05:06:50 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1998-08-29 05:06:50 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00: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
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset -- where in this string to start searching
|
1999-07-17 07:26:16 +00:00
|
|
|
* @return
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::FindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::FindCharInSet(*this,aSet,PR_FALSE,anOffset);
|
1998-04-13 20:24:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Reverse search for substring
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aString
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset - tells us where to begin the search
|
|
|
|
* @return offset of substring or -1
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::RFind(const nsStr& aString,PRBool aIgnoreCase,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::RFindSubstr(*this,aString,aIgnoreCase,anOffset);
|
1998-04-13 20:24:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Reverse search for substring
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aString
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset - tells us where to begin the search
|
|
|
|
* @return offset of substring or -1
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::RFind(const char* aString,PRBool aIgnoreCase,PRInt32 anOffset) const{
|
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 result=kNotFound;
|
|
|
|
if(aString) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aString);
|
|
|
|
temp.mStr=(char*)aString;
|
|
|
|
result=nsStr::RFindSubstr(*this,temp,aIgnoreCase,anOffset);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Reverse search for char
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aChar
|
|
|
|
* @param aIgnoreCase
|
|
|
|
* @param anOffset - tells us where to begin the search
|
|
|
|
* @return offset of substring or -1
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::RFindChar(PRUnichar aChar,PRBool aIgnoreCase,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::RFindChar(*this,aChar,aIgnoreCase,anOffset);
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Reverse search for char in this string that is also a member of given charset
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset
|
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::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);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Reverse search for char in this string that is also a member of given charset
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aStringSet
|
|
|
|
* @param anOffset
|
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::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);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Reverse search for char in this string that is also a member of given charset
|
1998-04-13 20:24:54 +00:00
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1999-08-30 06:55:13 +00:00
|
|
|
* @param aCStringSet
|
|
|
|
* @param anOffset
|
|
|
|
* @return offset of found char, or -1 (kNotFound)
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::RFindCharInSet(const nsStr& aSet,PRInt32 anOffset) const{
|
|
|
|
PRInt32 result=nsStr::RFindCharInSet(*this,aSet,PR_FALSE,anOffset);
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
COMPARISON METHODS...
|
|
|
|
**************************************************************/
|
|
|
|
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Compares given cstring to this string.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aCString points to a cstring
|
|
|
|
* @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
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::Compare(const char *aCString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
NS_ASSERTION(0!=aCString,kNullPointerError);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
if(aCString) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eOneByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aCString);
|
|
|
|
temp.mStr=(char*)aCString;
|
|
|
|
return nsStr::Compare(*this,temp,aCount,aIgnoreCase);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return 0;
|
1999-07-09 05:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Compares given unistring to this string.
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param aString pts to a uni-string
|
|
|
|
* @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-07-09 05:11:25 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::Compare(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
NS_ASSERTION(0!=aString,kNullPointerError);
|
|
|
|
|
|
|
|
if(aString) {
|
|
|
|
nsStr temp;
|
|
|
|
nsStr::Initialize(temp,eTwoByte);
|
|
|
|
temp.mLength=nsCRT::strlen(aString);
|
|
|
|
temp.mUStr=(PRUnichar*)aString;
|
|
|
|
return nsStr::Compare(*this,temp,aCount,aIgnoreCase);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
return 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Compare given nsStr with this cstring.
|
|
|
|
*
|
|
|
|
* @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
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRInt32 nsCString::Compare(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
return nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
/**
|
|
|
|
* Here come a whole bunch of operator functions that are self-explanatory...
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::operator==(const nsStr& S) const {return Equals(S);}
|
|
|
|
PRBool nsCString::operator==(const char* s) const {return Equals(s);}
|
|
|
|
PRBool nsCString::operator==(const PRUnichar* s) const {return Equals(s);}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::operator!=(const nsStr& S) const {return PRBool(Compare(S)!=0);}
|
|
|
|
PRBool nsCString::operator!=(const char* s) const {return PRBool(Compare(s)!=0);}
|
|
|
|
PRBool nsCString::operator!=(const PRUnichar* s) const {return PRBool(Compare(s)!=0);}
|
1999-07-09 05:11:25 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::operator<(const nsStr& S) const {return PRBool(Compare(S)<0);}
|
|
|
|
PRBool nsCString::operator<(const char* s) const {return PRBool(Compare(s)<0);}
|
|
|
|
PRBool nsCString::operator<(const PRUnichar* s) const {return PRBool(Compare(s)<0);}
|
1998-08-03 20:46:38 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::operator>(const nsStr& S) const {return PRBool(Compare(S)>0);}
|
|
|
|
PRBool nsCString::operator>(const char* s) const {return PRBool(Compare(s)>0);}
|
|
|
|
PRBool nsCString::operator>(const PRUnichar* s) const {return PRBool(Compare(s)>0);}
|
1998-08-03 20:46:38 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::operator<=(const nsStr& S) const {return PRBool(Compare(S)<=0);}
|
|
|
|
PRBool nsCString::operator<=(const char* s) const {return PRBool(Compare(s)<=0);}
|
|
|
|
PRBool nsCString::operator<=(const PRUnichar* s) const {return PRBool(Compare(s)<=0);}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::operator>=(const nsStr& S) const {return PRBool(Compare(S)>=0);}
|
|
|
|
PRBool nsCString::operator>=(const char* s) const {return PRBool(Compare(s)>=0);}
|
|
|
|
PRBool nsCString::operator>=(const PRUnichar* s) const {return PRBool(Compare(s)>=0);}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::EqualsIgnoreCase(const nsStr& aString) const {
|
|
|
|
return Equals(aString,PR_TRUE);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::EqualsIgnoreCase(const char* aString,PRInt32 aLength) const {
|
|
|
|
return Equals(aString,PR_TRUE,aLength);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aLength) const {
|
|
|
|
return Equals(aString,PR_TRUE,aLength);
|
|
|
|
}
|
1999-07-09 05:11:25 +00:00
|
|
|
|
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/**
|
|
|
|
* Compare this to given string; note that we compare full strings here.
|
|
|
|
*
|
1999-07-17 07:26:16 +00:00
|
|
|
* @update gess 01/04/99
|
|
|
|
* @param aString is the other nsCString to be compared to
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1999-07-09 06:01:55 +00:00
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::Equals(const nsStr& aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
PRInt32 theAnswer=nsStr::Compare(*this,aString,aCount,aIgnoreCase);
|
|
|
|
PRBool result=PRBool(0==theAnswer);
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
|
|
|
* Compare this to given string; note that we compare full strings here.
|
1999-07-17 07:26:16 +00:00
|
|
|
*
|
|
|
|
* @param aString is the CString to be compared
|
|
|
|
* @param aCount tells us how many chars you want to compare starting with start of string
|
|
|
|
* @param aIgnorecase tells us whether to be case sensitive
|
|
|
|
* @param aCount tells us how many chars to test; -1 implies full length
|
1998-04-13 20:24:54 +00:00
|
|
|
* @return TRUE if equal
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::Equals(const char* aCString,PRBool aIgnoreCase,PRInt32 aCount) const{
|
|
|
|
PRInt32 theAnswer=Compare(aCString,aIgnoreCase,aCount);
|
|
|
|
PRBool result=PRBool(0==theAnswer);
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
PRBool nsCString::Equals(const PRUnichar* aString,PRBool aIgnoreCase,PRInt32 aCount) const {
|
|
|
|
PRInt32 theAnswer=Compare(aString,aIgnoreCase,aCount);
|
|
|
|
PRBool result=PRBool(0==theAnswer);
|
|
|
|
return result;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**************************************************************
|
|
|
|
Define the string deallocator class...
|
|
|
|
**************************************************************/
|
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
class nsCStringDeallocator: public nsDequeFunctor{
|
|
|
|
public:
|
|
|
|
virtual void* operator()(void* anObject) {
|
|
|
|
nsCString* aString= (nsCString*)anObject;
|
|
|
|
if(aString){
|
|
|
|
delete aString;
|
|
|
|
}
|
|
|
|
return 0;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
};
|
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* This class, appropriately enough, creates and recycles nsCString objects..
|
|
|
|
****************************************************************************/
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
class nsCStringRecycler {
|
|
|
|
public:
|
|
|
|
nsCStringRecycler() : mDeque(0) {
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
~nsCStringRecycler() {
|
|
|
|
nsCStringDeallocator theDeallocator;
|
|
|
|
mDeque.ForEach(theDeallocator); //now delete the strings
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
void Recycle(nsCString* aString) {
|
|
|
|
mDeque.Push(aString);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
|
|
|
|
nsCString* CreateString(void){
|
|
|
|
nsCString* result=(nsCString*)mDeque.Pop();
|
|
|
|
if(!result)
|
|
|
|
result=new nsCString();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
nsDeque mDeque;
|
|
|
|
};
|
|
|
|
static nsCStringRecycler& GetRecycler(void);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/**
|
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1999-07-09 06:01:55 +00:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCStringRecycler& GetRecycler(void){
|
|
|
|
static nsCStringRecycler gCRecycler;
|
|
|
|
return gCRecycler;
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1998-08-22 17:50:13 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
#endif
|
1998-09-05 23:21:42 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Call this mehod when you're done
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCString* nsCString::CreateString(void){
|
|
|
|
nsCString* result=0;
|
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
result=GetRecycler().CreateString();
|
|
|
|
#endif
|
|
|
|
return result;
|
1998-08-03 20:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Call this mehod when you're done
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
void nsCString::Recycle(nsCString* aString){
|
|
|
|
#ifndef RICKG_TESTBED
|
|
|
|
GetRecycler().Recycle(aString);
|
|
|
|
#endif
|
1998-08-03 20:46:38 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 10:08:10 +00:00
|
|
|
#if 0
|
1998-08-03 20:46:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess8/8/98
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
ostream& operator<<(ostream& aStream,const nsCString& aString){
|
|
|
|
if(eOneByte==aString.mCharSize) {
|
|
|
|
aStream<<aString.mStr;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
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-09-06 22:59:11 +00:00
|
|
|
return aStream;
|
1998-08-03 20:46:38 +00:00
|
|
|
}
|
1999-07-17 10:08:10 +00:00
|
|
|
#endif
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
|
|
|
*
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 01/04/99
|
1998-08-03 20:46:38 +00:00
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
NS_COM int fputs(const nsCString& aString, FILE* out)
|
1999-07-09 06:01:55 +00:00
|
|
|
{
|
1999-07-17 07:26:16 +00: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) {
|
|
|
|
delete[] cp;
|
|
|
|
}
|
|
|
|
return (int) len;
|
1998-08-03 20:46:38 +00:00
|
|
|
}
|
1999-11-19 08:05:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dumps the contents of the string to stdout
|
|
|
|
* @update gess 11/15/99
|
|
|
|
*/
|
|
|
|
void nsCString::DebugDump(void) const {
|
|
|
|
|
|
|
|
if(mStr && (eOneByte==mCharSize)) {
|
|
|
|
printf("\n%s",mStr);
|
|
|
|
}
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
IMPLEMENTATION NOTES: AUTOSTRING...
|
|
|
|
***********************************************************************/
|
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Default constructor
|
|
|
|
*
|
1999-07-09 06:01:55 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCAutoString::nsCAutoString() : nsCString(){
|
|
|
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
|
|
|
AddNullTerminator(*this);
|
1999-08-30 06:55:13 +00:00
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-07-09 05:11:25 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Default constructor
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCAutoString::nsCAutoString(const nsCAutoString& aString) : nsCString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
|
|
|
AddNullTerminator(*this);
|
|
|
|
Append(aString);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1999-07-09 06:01:55 +00:00
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Copy construct from ascii c-string
|
|
|
|
* @param aCString is a ptr to a 1-byte cstr
|
1999-07-09 06:01:55 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCAutoString::nsCAutoString(const char* aCString,PRInt32 aLength) : nsCString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
|
|
|
AddNullTerminator(*this);
|
|
|
|
Append(aCString,aLength);
|
1998-09-05 23:21:42 +00:00
|
|
|
}
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* Copy construct using an external buffer descriptor
|
|
|
|
* @param aBuffer -- descibes external buffer
|
1999-07-17 07:26:16 +00:00
|
|
|
*/
|
1999-08-24 00:52:32 +00:00
|
|
|
nsCAutoString::nsCAutoString(const CBufDescriptor& aBuffer) : nsCString() {
|
1999-07-17 07:26:16 +00:00
|
|
|
if(!aBuffer.mBuffer) {
|
|
|
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsStr::Initialize(*this,aBuffer.mBuffer,aBuffer.mCapacity,aBuffer.mLength,aBuffer.mCharSize,!aBuffer.mStackBased);
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1999-09-19 16:43:09 +00:00
|
|
|
if(!aBuffer.mIsConst)
|
|
|
|
AddNullTerminator(*this); //this isn't really needed, but it guarantees that folks don't pass string constants.
|
1999-07-09 06:01:55 +00:00
|
|
|
}
|
1998-08-03 20:46:38 +00:00
|
|
|
|
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* Copy construct from uni-string
|
|
|
|
* @param aString is a ptr to a unistr
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCAutoString::nsCAutoString(const PRUnichar* aString,PRInt32 aLength) : nsCString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
|
|
|
AddNullTerminator(*this);
|
|
|
|
Append(aString,aLength);
|
1998-08-03 20:46:38 +00:00
|
|
|
}
|
|
|
|
|
1998-08-22 17:50:13 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* construct from an nsStr
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param
|
1998-08-22 17:50:13 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCAutoString::nsCAutoString(const nsStr& aString) : nsCString() {
|
|
|
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
|
|
|
AddNullTerminator(*this);
|
|
|
|
Append(aString);
|
1998-08-22 17:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
|
1998-08-03 20:46:38 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* construct from a char
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
nsCAutoString::nsCAutoString(PRUnichar aChar) : nsCString(){
|
|
|
|
nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
|
|
|
|
AddNullTerminator(*this);
|
|
|
|
Append(aChar);
|
1998-08-03 20:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1999-07-17 07:26:16 +00:00
|
|
|
* construct from a subsumeable string
|
1999-09-06 22:59:11 +00:00
|
|
|
* @update gess 1/4/99
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param reference to a subsumeString
|
1998-08-03 20:46:38 +00:00
|
|
|
*/
|
1999-07-17 07:26:16 +00:00
|
|
|
#ifdef AIX
|
|
|
|
nsCAutoString::nsCAutoString(const nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
|
|
|
nsSubsumeCStr temp(aSubsumeStr); // a temp is needed for the AIX compiler
|
|
|
|
CSubsume(*this,temp);
|
|
|
|
#else
|
|
|
|
nsCAutoString::nsCAutoString( nsSubsumeCStr& aSubsumeStr) :nsCString() {
|
|
|
|
CSubsume(*this,aSubsumeStr);
|
|
|
|
#endif // AIX
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
/**
|
1999-08-30 06:55:13 +00:00
|
|
|
* deconstructor
|
1999-07-17 07:26:16 +00:00
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
nsCAutoString::~nsCAutoString(){
|
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-08-31 03:04:37 +00:00
|
|
|
void nsCAutoString::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const {
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = sizeof(*this) + mCapacity * mCharSize;
|
|
|
|
}
|
1999-07-17 07:26:16 +00:00
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
nsSubsumeCStr::nsSubsumeCStr(nsStr& aString) : nsCString() {
|
|
|
|
CSubsume(*this,aString);
|
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
nsSubsumeCStr::nsSubsumeCStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength) : nsCString() {
|
|
|
|
mUStr=aString;
|
1999-09-02 07:04:59 +00:00
|
|
|
mCapacity=mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
|
1999-07-17 07:26:16 +00:00
|
|
|
mOwnsBuffer=assumeOwnership;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSubsumeCStr::nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength) : nsCString() {
|
|
|
|
mStr=aString;
|
1999-09-02 07:04:59 +00:00
|
|
|
mCapacity=mLength=(-1==aLength) ? strlen(aString) : aLength;
|
1999-07-17 07:26:16 +00:00
|
|
|
mOwnsBuffer=assumeOwnership;
|
|
|
|
}
|
1999-07-09 06:01:55 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
|