1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-14 00:24:54 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2000-05-12 09:25:26 +04:00
|
|
|
* Original Author:
|
|
|
|
* Rick Gessner <rickg@netscape.com>
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Contributor(s):
|
2000-05-12 09:25:26 +04:00
|
|
|
* Scott Collins <scc@mozilla.org>
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
MODULE NOTES:
|
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
See nsStr.h for a more general description of string classes.
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
This version of the nsString class offers many improvements over the
|
|
|
|
original version:
|
|
|
|
1. Wide and narrow chars
|
|
|
|
2. Allocators
|
|
|
|
3. Much smarter autostrings
|
|
|
|
4. Subsumable strings
|
1998-09-04 21:26:37 +04:00
|
|
|
***********************************************************************/
|
|
|
|
|
2000-04-26 04:55:37 +04:00
|
|
|
#ifndef NEW_STRING_APIS
|
2000-05-16 11:18:04 +04:00
|
|
|
#define NEW_STRING_APIS 1
|
2000-04-26 04:55:37 +04:00
|
|
|
#endif //NEW_STRING_APIS
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
#ifndef _nsCString_
|
|
|
|
#define _nsCString_
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
#include "nsString2.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include <stdio.h>
|
1999-04-25 07:50:10 +04:00
|
|
|
#include "nsStr.h"
|
1999-07-17 11:26:16 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
|
2000-03-23 05:12:23 +03:00
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
#include "nsAWritableString.h"
|
2000-03-29 04:06:31 +04:00
|
|
|
#else
|
|
|
|
#define NS_LITERAL_STRING(s) (s)
|
|
|
|
#define NS_LITERAL_CSTRING(s) (s)
|
2000-03-31 02:51:51 +04:00
|
|
|
|
2000-05-15 11:28:00 +04:00
|
|
|
#define NS_DEF_DERIVED_STRING_OPERATOR_PLUS(_StringT, _CharT)
|
|
|
|
#define NS_DEF_2_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT)
|
|
|
|
|
2000-03-31 02:51:51 +04:00
|
|
|
inline
|
|
|
|
char
|
|
|
|
nsLiteralChar( char c )
|
|
|
|
{
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
PRUnichar
|
|
|
|
nsLiteralPRUnichar( PRUnichar c )
|
|
|
|
{
|
|
|
|
return c;
|
|
|
|
}
|
2000-03-23 05:12:23 +03:00
|
|
|
#endif
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
class NS_COM nsSubsumeCStr;
|
1999-05-06 09:13:08 +04:00
|
|
|
|
2000-03-23 05:12:23 +03:00
|
|
|
class NS_COM nsCString :
|
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
public nsAWritableCString,
|
|
|
|
#endif
|
|
|
|
public nsStr {
|
|
|
|
|
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
protected:
|
2000-04-15 04:05:17 +04:00
|
|
|
virtual const void* Implementation() const { return "nsCString"; }
|
2000-03-25 01:06:57 +03:00
|
|
|
virtual const char* GetReadableFragment( nsReadableFragment<char>&, nsFragmentRequest, PRUint32 ) const;
|
|
|
|
virtual char* GetWritableFragment( nsWritableFragment<char>&, nsFragmentRequest, PRUint32 );
|
2000-03-23 05:12:23 +03:00
|
|
|
#endif
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
nsCString();
|
1998-09-04 21:26:37 +04:00
|
|
|
|
2000-03-31 02:51:51 +04:00
|
|
|
/**
|
|
|
|
* This is our copy constructor
|
|
|
|
* @param reference to another nsCString
|
|
|
|
*/
|
|
|
|
nsCString(const nsCString& aString);
|
|
|
|
|
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
nsCString( const nsAReadableCString& );
|
|
|
|
|
|
|
|
nsCString(const char*);
|
|
|
|
nsCString(const char*, PRInt32);
|
|
|
|
#else
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This constructor accepts an isolatin string
|
|
|
|
* @param aCString is a ptr to a 1-byte cstr
|
|
|
|
*/
|
|
|
|
nsCString(const char* aCString,PRInt32 aLength=-1);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This constructor accepts a unichar string
|
|
|
|
* @param aCString is a ptr to a 2-byte cstr
|
|
|
|
*/
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This is a copy constructor that accepts an nsStr
|
|
|
|
* @param reference to another nsCString
|
|
|
|
*/
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString(const nsStr&);
|
2000-03-31 02:51:51 +04:00
|
|
|
#endif
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This constructor takes a subsumestr
|
|
|
|
* @param reference to subsumestr
|
|
|
|
*/
|
2000-03-29 04:06:31 +04:00
|
|
|
nsCString(nsSubsumeCStr& aSubsumeStr);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
virtual ~nsCString();
|
1999-07-09 09:11:25 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the length of this string
|
|
|
|
* @return string length
|
|
|
|
*/
|
2000-03-23 05:12:23 +03:00
|
|
|
virtual PRUint32 Length() const { return mLength; }
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the size of this string
|
|
|
|
* @return string length
|
|
|
|
*/
|
|
|
|
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Call this method if you want to force a different string capacity
|
|
|
|
* @update gess7/30/98
|
|
|
|
* @param aLength -- contains new length for mStr
|
|
|
|
* @return
|
|
|
|
*/
|
2000-03-23 05:12:23 +03:00
|
|
|
void SetLength(PRUint32 aLength);
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the new length of the string.
|
|
|
|
* @param aLength is new string length.
|
|
|
|
* @return nada
|
|
|
|
*/
|
|
|
|
void SetCapacity(PRUint32 aLength);
|
2000-03-23 05:12:23 +03:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This method truncates this string to given length.
|
|
|
|
*
|
|
|
|
* @param anIndex -- new length of string
|
|
|
|
* @return nada
|
|
|
|
*/
|
2000-03-23 05:12:23 +03:00
|
|
|
void Truncate(PRUint32 anIndex=0) {
|
|
|
|
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
|
|
|
if ( anIndex < mLength )
|
|
|
|
SetLength(anIndex);
|
|
|
|
}
|
1998-09-04 21:26:37 +04:00
|
|
|
|
2000-03-23 05:12:23 +03:00
|
|
|
#ifndef NEW_STRING_APIS
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Determine whether or not this string has a length of 0
|
|
|
|
*
|
|
|
|
* @return TRUE if empty.
|
|
|
|
*/
|
|
|
|
PRBool IsEmpty(void) const {
|
|
|
|
return PRBool(0==mLength);
|
|
|
|
}
|
2000-03-25 01:06:57 +03:00
|
|
|
#endif
|
1999-05-29 11:29:46 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**********************************************************************
|
|
|
|
Accessor methods...
|
|
|
|
*********************************************************************/
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
|
|
|
*/
|
|
|
|
const char* GetBuffer(void) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
#ifndef NEW_STRING_APIS
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Get nth character.
|
|
|
|
*/
|
|
|
|
PRUnichar operator[](PRUint32 anIndex) const;
|
|
|
|
PRUnichar CharAt(PRUint32 anIndex) const;
|
|
|
|
PRUnichar First(void) const;
|
|
|
|
PRUnichar Last(void) const;
|
2000-03-23 05:12:23 +03:00
|
|
|
#endif
|
1999-03-22 11:29:26 +03:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
1999-03-22 11:29:26 +03:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**********************************************************************
|
|
|
|
String creation methods...
|
|
|
|
*********************************************************************/
|
1998-09-04 21:26:37 +04:00
|
|
|
|
2000-03-23 05:12:23 +03:00
|
|
|
#ifndef NEW_STRING_APIS
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Create a new string by appending given string to this
|
|
|
|
* @param aString -- 2nd string to be appended
|
|
|
|
* @return new string
|
|
|
|
*/
|
|
|
|
nsSubsumeCStr operator+(const nsCString& aString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given char*.
|
|
|
|
* @param aCString is a ptr to cstring to be added to this
|
|
|
|
* @return newly created string
|
|
|
|
*/
|
|
|
|
nsSubsumeCStr operator+(const char* aCString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given char.
|
|
|
|
* @param aChar is a char to be added to this
|
|
|
|
* @return newly created string
|
|
|
|
*/
|
|
|
|
nsSubsumeCStr operator+(PRUnichar aChar);
|
|
|
|
nsSubsumeCStr operator+(char aChar);
|
2000-03-23 05:12:23 +03:00
|
|
|
#endif
|
1998-09-04 21:26:37 +04:00
|
|
|
|
2000-05-02 02:25:44 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**********************************************************************
|
|
|
|
Lexomorphic transforms...
|
|
|
|
*********************************************************************/
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Converts chars in this to lowercase
|
|
|
|
* @update gess 7/27/98
|
|
|
|
*/
|
|
|
|
void ToLowerCase();
|
1999-01-09 04:09:39 +03:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Converts chars in this to lowercase, and
|
|
|
|
* stores them in aOut
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aOut is a string to contain result
|
|
|
|
*/
|
|
|
|
void ToLowerCase(nsCString& aString) const;
|
1999-07-09 09:11:25 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Converts chars in this to uppercase
|
|
|
|
* @update gess 7/27/98
|
|
|
|
*/
|
|
|
|
void ToUpperCase();
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Converts chars in this to lowercase, and
|
|
|
|
* stores them in a given output string
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param aOut is a string to contain result
|
|
|
|
*/
|
|
|
|
void ToUpperCase(nsCString& aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This method is used to remove all occurances of the
|
|
|
|
* characters found in aSet from this string.
|
|
|
|
*
|
|
|
|
* @param aSet -- characters to be cut from this
|
|
|
|
* @return *this
|
|
|
|
*/
|
2000-04-21 10:59:14 +04:00
|
|
|
void StripChars(const char* aSet);
|
|
|
|
void StripChar(PRUnichar aChar,PRInt32 anOffset=0);
|
2000-04-21 11:34:06 +04:00
|
|
|
void StripChar(char aChar,PRInt32 anOffset=0) { StripChar((PRUnichar) (unsigned char)aChar,anOffset); }
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This method strips whitespace throughout the string
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 10:59:14 +04:00
|
|
|
void StripWhitespace();
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* swaps occurence of 1 string for another
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 10:59:14 +04:00
|
|
|
void ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
|
|
|
|
void ReplaceChar(const char* aSet,PRUnichar aNewChar);
|
1999-10-05 08:47:19 +04:00
|
|
|
|
2000-04-21 10:59:14 +04:00
|
|
|
void ReplaceSubstring(const nsCString& aTarget,const nsCString& aNewValue);
|
|
|
|
void ReplaceSubstring(const char* aTarget,const char* aNewValue);
|
1999-12-02 13:14:38 +03:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
PRInt32 CountChar(PRUnichar aChar);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method trims characters found in aTrimSet from
|
|
|
|
* either end of the underlying string.
|
|
|
|
*
|
|
|
|
* @param aTrimSet -- contains chars to be trimmed from
|
|
|
|
* both ends
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aEliminateLeading
|
|
|
|
* @param aEliminateTrailing
|
|
|
|
* @param aIgnoreQuotes
|
1999-10-05 08:47:19 +04:00
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 10:59:14 +04:00
|
|
|
void Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE);
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method strips whitespace from string.
|
|
|
|
* You can control whether whitespace is yanked from
|
|
|
|
* start and end of string as well.
|
|
|
|
*
|
|
|
|
* @param aEliminateLeading controls stripping of leading ws
|
|
|
|
* @param aEliminateTrailing controls stripping of trailing ws
|
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 10:59:14 +04:00
|
|
|
void CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method strips whitespace from string.
|
|
|
|
* You can control whether whitespace is yanked from
|
|
|
|
* start and end of string as well.
|
|
|
|
*
|
|
|
|
* @param aEliminateLeading controls stripping of leading ws
|
|
|
|
* @param aEliminateTrailing controls stripping of trailing ws
|
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 10:59:14 +04:00
|
|
|
void CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**********************************************************************
|
|
|
|
string conversion methods...
|
|
|
|
*********************************************************************/
|
2000-03-31 02:51:51 +04:00
|
|
|
//#ifndef STANDALONE_STRING_TESTS
|
2000-03-25 05:07:34 +03:00
|
|
|
operator char*() {return mStr;}
|
|
|
|
operator const char*() const {return (const char*)mStr;}
|
2000-03-31 02:51:51 +04:00
|
|
|
//#endif
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This method constructs a new nsCString that is a clone
|
|
|
|
* of this string.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsCString* ToNewString() const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Creates an ISOLatin1 clone of this string
|
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
|
|
|
* @return ptr to new isolatin1 string
|
|
|
|
*/
|
|
|
|
char* ToNewCString() const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Creates a unicode clone of this string
|
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
|
|
|
* @return ptr to new unicode string
|
|
|
|
*/
|
|
|
|
PRUnichar* ToNewUnicode() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies data from internal buffer onto given char* buffer
|
|
|
|
* NOTE: This only copies as many chars as will fit in given buffer (clips)
|
|
|
|
* @param aBuf is the buffer where data is stored
|
|
|
|
* @param aBuflength is the max # of chars to move to buffer
|
|
|
|
* @return ptr to given buffer
|
|
|
|
*/
|
|
|
|
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Perform string to float conversion.
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return float rep of string value
|
|
|
|
*/
|
|
|
|
float ToFloat(PRInt32* aErrorCode) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Perform string to int conversion.
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
2000-02-13 20:46:15 +03:00
|
|
|
* @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you.
|
|
|
|
* @return int rep of string value, and possible (out) error code
|
1999-10-05 08:47:19 +04:00
|
|
|
*/
|
|
|
|
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**********************************************************************
|
|
|
|
String manipulation methods...
|
|
|
|
*********************************************************************/
|
1999-07-09 10:01:55 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* assign given string to this string
|
|
|
|
* @param aStr: buffer to be assigned to this
|
1999-11-19 11:05:30 +03:00
|
|
|
* @param aCount is the length of the given str (or -1) if you want me to determine its length
|
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-10-05 08:47:19 +04:00
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
|
2000-05-12 09:25:26 +04:00
|
|
|
nsCString& operator=( const nsCString& aString ) { Assign(aString); return *this; }
|
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
nsCString& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsCString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsCString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
|
|
|
|
nsCString& operator=( char aChar ) { Assign(aChar); return *this; }
|
|
|
|
#endif
|
|
|
|
|
2000-03-29 04:06:31 +04:00
|
|
|
void AssignWithConversion(const PRUnichar*,PRInt32=-1);
|
2000-04-22 13:17:20 +04:00
|
|
|
void AssignWithConversion( const nsString& aString );
|
2000-03-29 04:06:31 +04:00
|
|
|
void AssignWithConversion(PRUnichar);
|
|
|
|
|
|
|
|
#ifndef NEW_STRING_APIS
|
2000-03-31 02:51:51 +04:00
|
|
|
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
|
|
|
|
nsCString& Assign(char aChar);
|
|
|
|
|
2000-03-29 04:06:31 +04:00
|
|
|
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1) { AssignWithConversion(aString, aCount); return *this; }
|
|
|
|
//nsCString& Assign(PRUnichar aChar) { AssignWithConversion(aChar); return *this; }
|
2000-03-29 04:06:31 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* here come a bunch of assignment operators...
|
|
|
|
* @param aString: string to be added to this
|
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& operator=(PRUnichar aChar) {AssignWithConversion(aChar); return *this;}
|
2000-04-17 16:22:37 +04:00
|
|
|
nsCString& operator=(char aChar) {return Assign(aChar);}
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& operator=(const PRUnichar* aString) {AssignWithConversion(aString); return *this;}
|
2000-03-24 01:42:34 +03:00
|
|
|
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& operator=(const nsStr& aString) {return Assign(aString);}
|
2000-03-29 04:06:31 +04:00
|
|
|
nsCString& operator=(const char* aCString) {return Assign(aCString);}
|
2000-03-31 02:51:51 +04:00
|
|
|
|
|
|
|
// Yes, I know this makes assignment from a |nsSubsumeString| not do the special thing
|
|
|
|
// |nsSubsumeString| needs to go away
|
2000-05-02 02:25:44 +04:00
|
|
|
#if defined(AIX) || defined(XP_OS2_VACPP)
|
|
|
|
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX and VAC++ requires a const here
|
1999-10-05 08:47:19 +04:00
|
|
|
#else
|
|
|
|
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
|
|
|
|
#endif
|
2000-03-24 01:42:34 +03:00
|
|
|
#endif
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-07-09 10:01:55 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/*
|
|
|
|
* Appends n characters from given string to this,
|
|
|
|
*
|
|
|
|
* @param aString is the source to be appended to this
|
|
|
|
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
|
1999-11-19 11:05:30 +03:00
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-10-05 08:47:19 +04:00
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
2000-03-31 02:51:51 +04:00
|
|
|
|
2000-04-01 04:24:32 +04:00
|
|
|
void AppendWithConversion(const nsString&, PRInt32=-1);
|
2000-03-31 02:51:51 +04:00
|
|
|
void AppendWithConversion(PRUnichar aChar);
|
|
|
|
// Why no |AppendWithConversion(const PRUnichar*)|?
|
2000-04-15 04:05:17 +04:00
|
|
|
void AppendInt(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
|
|
|
|
void AppendFloat( double aFloat );
|
|
|
|
|
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
virtual void do_AppendFromReadable( const nsAReadableCString& );
|
|
|
|
#endif
|
2000-03-31 02:51:51 +04:00
|
|
|
|
|
|
|
#ifndef NEW_STRING_APIS
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
|
2000-03-31 02:51:51 +04:00
|
|
|
nsCString& Append(const nsCString& aString,PRInt32 aCount);
|
|
|
|
nsCString& Append(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
|
1999-10-05 08:47:19 +04:00
|
|
|
nsCString& Append(const char* aString,PRInt32 aCount=-1);
|
|
|
|
nsCString& Append(char aChar);
|
2000-03-31 02:51:51 +04:00
|
|
|
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& Append(PRUnichar aChar) {AppendWithConversion(aChar); return *this;}
|
|
|
|
//nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10) {AppendInt(aInteger,aRadix); return *this;}
|
|
|
|
//nsCString& Append(float aFloat) {AppendFloat(aFloat); return *this;}
|
2000-04-15 04:05:17 +04:00
|
|
|
|
2000-03-31 02:51:51 +04:00
|
|
|
/**
|
|
|
|
* Here's a bunch of methods that append varying types...
|
|
|
|
* @param various...
|
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
nsCString& operator+=(const nsCString& aString) {return Append(aString,(PRInt32)aString.mLength);}
|
|
|
|
nsCString& operator+=(const char* aCString) {return Append(aCString);}
|
|
|
|
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& operator+=(const PRUnichar aChar) {return Append(aChar);}
|
2000-03-31 02:51:51 +04:00
|
|
|
nsCString& operator+=(const char aChar) {return Append(aChar);}
|
2000-04-28 00:37:54 +04:00
|
|
|
//nsCString& operator+=(const int anInt) {return Append(anInt,10);}
|
2000-03-31 02:51:51 +04:00
|
|
|
#endif
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/*
|
|
|
|
* Copies n characters from this string to given string,
|
|
|
|
* starting at the leftmost offset.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param aCopy -- Receiving string
|
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
|
|
|
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copies n characters from this string to given string,
|
|
|
|
* starting at the given offset.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param aCopy -- Receiving string
|
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @param anOffset -- position where copying begins
|
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
|
|
|
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copies n characters from this string to given string,
|
|
|
|
* starting at rightmost char.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param aCopy -- Receiving string
|
|
|
|
* @param aCount -- number of chars to copy
|
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
|
|
|
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
|
|
|
|
|
2000-03-31 02:51:51 +04:00
|
|
|
void InsertWithConversion(PRUnichar aChar,PRUint32 anOffset);
|
|
|
|
// Why no |InsertWithConversion(PRUnichar*)|?
|
|
|
|
|
2000-04-15 04:05:17 +04:00
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
virtual void do_InsertFromReadable( const nsAReadableCString&, PRUint32 );
|
|
|
|
#endif
|
|
|
|
|
2000-03-31 02:51:51 +04:00
|
|
|
#ifndef NEW_STRING_APIS
|
1999-10-05 08:47:19 +04:00
|
|
|
/*
|
|
|
|
* This method inserts n chars from given string into this
|
|
|
|
* string at str[anOffset].
|
|
|
|
*
|
|
|
|
* @param aCopy -- String to be inserted into this
|
|
|
|
* @param anOffset -- insertion position within this str
|
|
|
|
* @param aCount -- number of chars to be copied from aCopy
|
1999-11-19 11:05:30 +03:00
|
|
|
* NOTE: IFF you pass -1 as aCount, then your buffer must be null terminated.
|
|
|
|
*
|
1999-10-05 08:47:19 +04:00
|
|
|
* @return number of chars inserted into this.
|
|
|
|
*/
|
2000-04-28 00:37:54 +04:00
|
|
|
void Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a given string into this string at
|
|
|
|
* a specified offset.
|
|
|
|
*
|
|
|
|
* @param aString* to be inserted into this string
|
|
|
|
* @param anOffset is insert pos in str
|
|
|
|
* @return the number of chars inserted into this string
|
|
|
|
*/
|
2000-04-28 00:37:54 +04:00
|
|
|
void Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a single char into this string at
|
|
|
|
* a specified offset.
|
|
|
|
*
|
|
|
|
* @param character to be inserted into this string
|
|
|
|
* @param anOffset is insert pos in str
|
|
|
|
* @return the number of chars inserted into this string
|
|
|
|
*/
|
2000-04-28 00:37:54 +04:00
|
|
|
//void Insert(PRUnichar aChar,PRUint32 anOffset) {InsertWithConversion(aChar,anOffset);}
|
|
|
|
void Insert(char aChar,PRUint32 anOffset);
|
2000-03-31 02:51:51 +04:00
|
|
|
#endif
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This method is used to cut characters in this string
|
|
|
|
* starting at anOffset, continuing for aCount chars.
|
|
|
|
*
|
|
|
|
* @param anOffset -- start pos for cut operation
|
|
|
|
* @param aCount -- number of chars to be cut
|
|
|
|
* @return *this
|
|
|
|
*/
|
2000-03-23 05:12:23 +03:00
|
|
|
#ifndef NEW_STRING_APIS
|
2000-04-28 00:37:54 +04:00
|
|
|
void Cut(PRUint32 anOffset,PRInt32 aCount);
|
2000-03-23 05:12:23 +03:00
|
|
|
#endif
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**********************************************************************
|
|
|
|
Searching methods...
|
|
|
|
*********************************************************************/
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for given substring within this string
|
|
|
|
*
|
|
|
|
* @param aString is substring to be sought in this
|
|
|
|
* @param aIgnoreCase selects case sensitivity
|
|
|
|
* @param anOffset tells us where in this strig to start searching
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-10-05 08:47:19 +04:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-03-24 10:21:56 +03:00
|
|
|
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for given char within this string
|
|
|
|
*
|
|
|
|
* @param aString is substring to be sought in this
|
|
|
|
* @param anOffset tells us where in this strig to start searching
|
|
|
|
* @param aIgnoreCase selects case sensitivity
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-10-05 08:47:19 +04:00
|
|
|
* @return find pos in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-03-24 10:21:56 +03:00
|
|
|
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method searches this string for the first character
|
|
|
|
* found in the given charset
|
|
|
|
* @param aString contains set of chars to be found
|
|
|
|
* @param anOffset tells us where to start searching in this
|
|
|
|
* @return -1 if not found, else the offset in this
|
|
|
|
*/
|
2000-03-24 10:21:56 +03:00
|
|
|
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
|
|
|
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=0) const;
|
|
|
|
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=0) const;
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* This methods scans the string backwards, looking for the given string
|
|
|
|
* @param aString is substring to be sought in this
|
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
2000-02-11 15:11:03 +03:00
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-10-05 08:47:19 +04:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for given char within this string
|
|
|
|
*
|
|
|
|
* @param aString is substring to be sought in this
|
|
|
|
* @param anOffset tells us where in this strig to start searching
|
|
|
|
* @param aIgnoreCase selects case sensitivity
|
|
|
|
* @return find pos in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-02-11 15:11:03 +03:00
|
|
|
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This method searches this string for the last character
|
|
|
|
* found in the given string
|
|
|
|
* @param aString contains set of chars to be found
|
|
|
|
* @param anOffset tells us where to start searching in this
|
|
|
|
* @return -1 if not found, else the offset in this
|
|
|
|
*/
|
|
|
|
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
|
|
|
|
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
|
|
|
|
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**********************************************************************
|
|
|
|
Comparison methods...
|
|
|
|
*********************************************************************/
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* Compares a given string type to this string.
|
|
|
|
* @update gess 7/27/98
|
|
|
|
* @param S is the string to be compared
|
|
|
|
* @param aIgnoreCase tells us how to treat case
|
|
|
|
* @param aCount tells us how many chars to compare
|
|
|
|
* @return -1,0,1
|
|
|
|
*/
|
2000-03-31 11:26:13 +04:00
|
|
|
PRInt32 CompareWithConversion(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 CompareWithConversion(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
|
|
|
|
PRBool EqualsWithConversion(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
PRBool EqualsWithConversion(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
PRBool EqualsWithConversion(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
|
|
|
|
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
|
|
|
|
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
2000-03-23 05:12:23 +03:00
|
|
|
#ifndef NEW_STRING_APIS
|
2000-04-28 00:37:54 +04:00
|
|
|
//virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
|
|
|
|
// return CompareWithConversion(aString,aIgnoreCase,aCount);
|
|
|
|
//}
|
|
|
|
//virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
|
|
|
|
// return CompareWithConversion(aString,aIgnoreCase,aCount);
|
|
|
|
//}
|
2000-03-31 11:26:13 +04:00
|
|
|
|
|
|
|
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare this to given string; note that we compare full strings here.
|
|
|
|
* The optional length argument just lets us know how long the given string is.
|
|
|
|
* If you provide a length, it is compared to length of this string as an
|
|
|
|
* optimization.
|
|
|
|
*
|
|
|
|
* @param aString -- the string to compare to this
|
|
|
|
* @param aCount -- number of chars in given string you want to compare
|
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
|
|
|
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
|
|
|
|
return EqualsWithConversion(aString,aIgnoreCase,aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
|
|
|
|
return EqualsWithConversion(aString,aIgnoreCase,aCount);
|
|
|
|
}
|
|
|
|
|
2000-04-28 00:37:54 +04:00
|
|
|
//PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const {
|
|
|
|
// return EqualsWithConversion(aString,aIgnoreCase,aCount);
|
|
|
|
//}
|
2000-03-31 11:26:13 +04:00
|
|
|
|
|
|
|
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
|
|
|
|
PRBool EqualsIgnoreCase(const nsStr& aString) const;
|
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
/**
|
|
|
|
* These methods compare a given string type to this one
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
|
|
|
PRBool operator==(const nsStr &aString) const;
|
|
|
|
PRBool operator==(const char* aString) const;
|
2000-04-28 00:37:54 +04:00
|
|
|
//PRBool operator==(const PRUnichar* aString) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods perform a !compare of a given string type to this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE
|
|
|
|
*/
|
|
|
|
PRBool operator!=(const nsStr &aString) const;
|
|
|
|
PRBool operator!=(const char* aString) const;
|
2000-04-28 00:37:54 +04:00
|
|
|
//PRBool operator!=(const PRUnichar* aString) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is < than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
|
|
|
PRBool operator<(const nsStr &aString) const;
|
|
|
|
PRBool operator<(const char* aString) const;
|
2000-04-28 00:37:54 +04:00
|
|
|
//PRBool operator<(const PRUnichar* aString) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is > than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
|
|
|
PRBool operator>(const nsStr &S) const;
|
|
|
|
PRBool operator>(const char* aString) const;
|
2000-04-28 00:37:54 +04:00
|
|
|
//PRBool operator>(const PRUnichar* aString) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is <= than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
|
|
|
PRBool operator<=(const nsStr &S) const;
|
|
|
|
PRBool operator<=(const char* aString) const;
|
2000-04-28 00:37:54 +04:00
|
|
|
//PRBool operator<=(const PRUnichar* aString) const;
|
1999-10-05 08:47:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is >= than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
|
|
|
PRBool operator>=(const nsStr &S) const;
|
|
|
|
PRBool operator>=(const char* aString) const;
|
2000-04-28 00:37:54 +04:00
|
|
|
//PRBool operator>=(const PRUnichar* aString) const;
|
2000-03-23 05:12:23 +03:00
|
|
|
#endif // !defined(NEW_STRING_APIS)
|
1999-10-05 08:47:19 +04:00
|
|
|
|
1999-11-19 11:05:30 +03:00
|
|
|
void DebugDump(void) const;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-10-05 08:47:19 +04:00
|
|
|
static void Recycle(nsCString* aString);
|
|
|
|
static nsCString* CreateString(void);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-04-17 15:06:41 +04:00
|
|
|
private:
|
|
|
|
// NOT TO BE IMPLEMENTED
|
|
|
|
// these signatures help clients not accidentally call the wrong thing helped by C++ automatic integral promotion
|
2000-05-12 09:25:26 +04:00
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
void operator=( PRUnichar );
|
|
|
|
#endif
|
2000-04-17 16:22:37 +04:00
|
|
|
void AssignWithConversion( char );
|
|
|
|
void AssignWithConversion( const char*, PRInt32=-1 );
|
|
|
|
void AppendWithConversion( char );
|
|
|
|
void InsertWithConversion( char, PRUint32 );
|
1999-07-17 11:26:16 +04:00
|
|
|
};
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-05-15 05:27:04 +04:00
|
|
|
#ifdef NEW_STRING_APIS
|
2000-05-14 01:39:37 +04:00
|
|
|
NS_DEF_STRING_COMPARISON_OPERATORS(nsCString, char)
|
2000-05-15 11:28:00 +04:00
|
|
|
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCString, char);
|
2000-03-23 05:12:23 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
1999-07-17 14:08:10 +04:00
|
|
|
//ostream& operator<<(ostream& aStream,const nsCString& aString);
|
|
|
|
//virtual void DebugDump(ostream& aStream) const;
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************
|
|
|
|
Here comes the AutoString class which uses internal memory
|
|
|
|
(typically found on the stack) for its default buffer.
|
|
|
|
If the buffer needs to grow, it gets reallocated on the heap.
|
|
|
|
**************************************************************/
|
|
|
|
|
|
|
|
class NS_COM nsCAutoString : public nsCString {
|
|
|
|
public:
|
|
|
|
|
2000-03-31 02:51:51 +04:00
|
|
|
virtual ~nsCAutoString();
|
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
nsCAutoString();
|
2000-04-28 04:21:44 +04:00
|
|
|
nsCAutoString(const nsCString& );
|
2000-05-15 07:10:19 +04:00
|
|
|
nsCAutoString(const char* aString);
|
|
|
|
nsCAutoString(const char* aString,PRInt32 aLength);
|
1999-08-24 04:52:32 +04:00
|
|
|
nsCAutoString(const CBufDescriptor& aBuffer);
|
2000-03-31 02:51:51 +04:00
|
|
|
|
|
|
|
#ifndef NEW_STRING_APIS
|
2000-04-28 00:37:54 +04:00
|
|
|
// nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
|
|
|
|
// nsCAutoString(const nsStr& aString);
|
|
|
|
// nsCAutoString(PRUnichar aChar);
|
2000-03-31 02:51:51 +04:00
|
|
|
#endif
|
1999-07-17 11:26:16 +04:00
|
|
|
|
2000-05-02 02:25:44 +04:00
|
|
|
#if defined(AIX) || defined(XP_OS2_VACPP)
|
|
|
|
nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX and VAC++ require a const
|
1999-07-17 11:26:16 +04:00
|
|
|
#else
|
|
|
|
nsCAutoString(nsSubsumeCStr& aSubsumeStr);
|
2000-05-02 02:25:44 +04:00
|
|
|
#endif // AIX || XP_OS2_VACPP
|
2000-03-29 04:06:31 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|
2000-05-12 09:25:26 +04:00
|
|
|
nsCAutoString& operator=( const nsCAutoString& aString ) { Assign(aString); return *this; }
|
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
private:
|
|
|
|
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
|
|
|
|
public:
|
|
|
|
nsCAutoString& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsCAutoString& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsCAutoString& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
|
|
|
|
nsCAutoString& operator=( char aChar ) { Assign(aChar); return *this; }
|
|
|
|
#else
|
1999-07-25 21:20:37 +04:00
|
|
|
nsCAutoString& operator=(const nsCString& aString) {nsCString::Assign(aString); return *this;}
|
|
|
|
nsCAutoString& operator=(const char* aCString) {nsCString::Assign(aCString); return *this;}
|
2000-04-28 00:37:54 +04:00
|
|
|
// nsCAutoString& operator=(const PRUnichar* aString) {nsCString::Assign(aString); return *this;}
|
|
|
|
// nsCAutoString& operator=(PRUnichar aChar) {nsCString::Assign(aChar); return *this;}
|
1999-07-25 21:20:37 +04:00
|
|
|
nsCAutoString& operator=(char aChar) {nsCString::Assign(aChar); return *this;}
|
2000-03-24 03:41:40 +03:00
|
|
|
#endif
|
1999-07-17 11:26:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the size of this string
|
|
|
|
* @return string length
|
|
|
|
*/
|
1999-08-31 07:04:37 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-08-30 10:55:13 +04:00
|
|
|
char mBuffer[kDefaultStringSize];
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2000-04-04 10:00:01 +04:00
|
|
|
#if 0//def NEW_STRING_APIS
|
2000-05-14 01:39:37 +04:00
|
|
|
NS_DEF_STRING_COMPARISON_OPERATORS(nsCAutoString, char)
|
2000-03-25 01:06:57 +03:00
|
|
|
#endif
|
2000-05-15 12:07:25 +04:00
|
|
|
|
|
|
|
#ifdef NEW_STRING_APIS
|
2000-05-15 11:28:00 +04:00
|
|
|
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCAutoString, char)
|
2000-05-15 12:07:25 +04:00
|
|
|
#endif
|
1999-09-02 11:04:59 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
/***************************************************************
|
|
|
|
The subsumestr class is very unusual.
|
|
|
|
It differs from a normal string in that it doesn't use normal
|
|
|
|
copy semantics when another string is assign to this.
|
|
|
|
Instead, it "steals" the contents of the source string.
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
This is very handy for returning nsString classes as part of
|
|
|
|
an operator+(...) for example, in that it cuts down the number
|
|
|
|
of copy operations that must occur.
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
You should probably not use this class unless you really know
|
|
|
|
what you're doing.
|
|
|
|
***************************************************************/
|
|
|
|
class NS_COM nsSubsumeCStr : public nsCString {
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
1999-07-17 11:26:16 +04:00
|
|
|
nsSubsumeCStr(nsStr& aString);
|
|
|
|
nsSubsumeCStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
|
|
|
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
1999-07-09 10:01:55 +04:00
|
|
|
|
2000-05-12 09:25:26 +04:00
|
|
|
nsSubsumeCStr& operator=( const nsSubsumeCStr& aString ) { Assign(aString); return *this; }
|
|
|
|
#ifdef NEW_STRING_APIS
|
|
|
|
nsSubsumeCStr& operator=( const nsAReadableCString& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsSubsumeCStr& operator=( const nsPromiseReadable<char>& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsSubsumeCStr& operator=( const char* aPtr ) { Assign(aPtr); return *this; }
|
|
|
|
nsSubsumeCStr& operator=( char aChar ) { Assign(aChar); return *this; }
|
|
|
|
private:
|
|
|
|
void operator=( PRUnichar ); // NOT TO BE IMPLEMENTED
|
|
|
|
#endif
|
1999-09-02 11:04:59 +04:00
|
|
|
};
|
1999-07-17 11:26:16 +04:00
|
|
|
|
1999-07-09 10:01:55 +04:00
|
|
|
|
|
|
|
#endif
|
1999-07-09 09:11:25 +04:00
|
|
|
|
1999-07-17 11:26:16 +04:00
|
|
|
|