1999-03-22 09:54:46 +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/
|
1999-03-22 09:54:46 +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.
|
1999-03-22 09:54:46 +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
|
1999-03-22 09:54:46 +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):
|
2000-09-02 20:53:31 +00:00
|
|
|
* Rick Gessner <rickg@netscape.com> (original author)
|
2000-05-12 05:25:26 +00:00
|
|
|
* Scott Collins <scc@mozilla.org>
|
1999-03-22 09:54:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-07-25 17:21:14 +00:00
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
/***********************************************************************
|
|
|
|
MODULE NOTES:
|
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
See nsStr.h for a more general description of string classes.
|
|
|
|
|
1999-05-06 05:13:08 +00: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
|
1999-03-22 09:54:46 +00:00
|
|
|
***********************************************************************/
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
#ifndef _nsString_
|
|
|
|
#define _nsString_
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include <stdio.h>
|
1999-07-17 07:26:16 +00:00
|
|
|
#include "nsString.h"
|
1999-07-09 06:01:55 +00:00
|
|
|
#include "nsIAtom.h"
|
1999-07-17 07:26:16 +00:00
|
|
|
#include "nsStr.h"
|
1999-08-30 06:55:13 +00:00
|
|
|
#include "nsCRT.h"
|
1999-03-22 09:54:46 +00:00
|
|
|
|
2000-03-23 02:12:23 +00:00
|
|
|
#include "nsAWritableString.h"
|
|
|
|
|
2000-04-15 00:05:17 +00:00
|
|
|
#ifdef STANDALONE_MI_STRING_TESTS
|
|
|
|
class nsAReadableString { public: virtual ~nsAReadableString() { } };
|
|
|
|
class nsAWritableString : public nsAReadableString { public: virtual ~nsAWritableString() { } };
|
|
|
|
#endif
|
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
class nsISizeOfHandler;
|
|
|
|
|
|
|
|
|
1999-05-06 05:13:08 +00:00
|
|
|
#define nsString2 nsString
|
|
|
|
#define nsAutoString2 nsAutoString
|
|
|
|
|
1999-05-29 07:29:46 +00:00
|
|
|
class NS_COM nsSubsumeStr;
|
2000-03-29 00:06:31 +00:00
|
|
|
|
2000-03-23 02:12:23 +00:00
|
|
|
class NS_COM nsString :
|
|
|
|
public nsAWritableString,
|
|
|
|
public nsStr {
|
|
|
|
|
2000-04-23 01:03:28 +00:00
|
|
|
protected:
|
2000-04-15 00:05:17 +00:00
|
|
|
virtual const void* Implementation() const { return "nsString"; }
|
2000-03-24 22:06:57 +00:00
|
|
|
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
|
|
|
|
virtual PRUnichar* GetWritableFragment( nsWritableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 );
|
2000-03-23 02:12:23 +00:00
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
|
2000-03-30 22:51:51 +00:00
|
|
|
public:
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
nsString();
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
2000-03-30 22:51:51 +00:00
|
|
|
* This is our copy constructor
|
|
|
|
* @param reference to another nsString
|
1999-10-05 04:47:19 +00:00
|
|
|
*/
|
2000-03-30 22:51:51 +00:00
|
|
|
nsString(const nsString& aString);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
explicit nsString(const nsAReadableString&);
|
2000-03-30 22:51:51 +00:00
|
|
|
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsString(const PRUnichar*);
|
2000-03-30 22:51:51 +00:00
|
|
|
nsString(const PRUnichar*, PRInt32);
|
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* This constructor takes a subsumestr
|
|
|
|
* @param reference to subsumestr
|
|
|
|
*/
|
2000-05-01 22:25:44 +00:00
|
|
|
#if defined(AIX) || defined(XP_OS2_VACPP)
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ require a const here
|
1999-11-12 03:58:15 +00:00
|
|
|
#else
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsString(nsSubsumeStr& aSubsumeStr);
|
1999-11-12 03:58:15 +00:00
|
|
|
#endif
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
virtual ~nsString();
|
1999-05-07 00:47:24 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the length of this string
|
|
|
|
* @return string length
|
|
|
|
*/
|
2000-03-23 02:12:23 +00:00
|
|
|
virtual PRUint32 Length() const { return mLength; }
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the size of this string
|
|
|
|
* @return string length
|
|
|
|
*/
|
|
|
|
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Call this method if you want to force a different string length
|
|
|
|
* @update gess7/30/98
|
|
|
|
* @param aLength -- contains new length for mStr
|
|
|
|
* @return
|
1999-03-22 09:54:46 +00:00
|
|
|
*/
|
2000-03-23 02:12:23 +00:00
|
|
|
void SetLength(PRUint32 aLength);
|
1999-10-05 04:47:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the new length of the string.
|
|
|
|
* @param aLength is new string length.
|
|
|
|
* @return nada
|
1999-07-17 07:26:16 +00:00
|
|
|
*/
|
1999-10-05 04:47:19 +00:00
|
|
|
void SetCapacity(PRUint32 aLength);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
2000-03-23 02:12:23 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* This method truncates this string to given length.
|
|
|
|
*
|
|
|
|
* @param anIndex -- new length of string
|
|
|
|
* @return nada
|
|
|
|
*/
|
2000-03-23 02:12:23 +00:00
|
|
|
void Truncate(PRUint32 anIndex=0) {
|
|
|
|
NS_ASSERTION(anIndex<=mLength, "Can't use |Truncate()| to make a string longer.");
|
|
|
|
if ( anIndex < mLength )
|
|
|
|
SetLength(anIndex);
|
|
|
|
}
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Determine whether or not the characters in this
|
|
|
|
* string are in store as 1 or 2 byte (unicode) strings.
|
|
|
|
*
|
|
|
|
* @return TRUE if ordered.
|
|
|
|
*/
|
|
|
|
PRBool IsUnicode(void) const {
|
|
|
|
PRBool result=PRBool(mCharSize==eTwoByte);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Getters/Setters...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
|
|
|
*/
|
|
|
|
const char* GetBuffer(void) const;
|
|
|
|
const PRUnichar* GetUnicode(void) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set nth character.
|
|
|
|
*/
|
|
|
|
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
|
|
|
|
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Lexomorphic transforms...
|
|
|
|
*********************************************************************/
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Converts chars in this to lowercase
|
|
|
|
* @update gess 7/27/98
|
|
|
|
*/
|
|
|
|
void ToLowerCase();
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
|
1999-10-05 04:47:19 +00: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(nsString& aString) const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Converts chars in this to uppercase
|
|
|
|
* @update gess 7/27/98
|
|
|
|
*/
|
|
|
|
void ToUpperCase();
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00: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(nsString& aString) const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
|
1999-10-05 04:47:19 +00: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 06:59:14 +00:00
|
|
|
void StripChars( const char* aSet );
|
|
|
|
void StripChar( PRUnichar aChar, PRInt32 anOffset=0 );
|
|
|
|
void StripChar( char aChar, PRInt32 anOffset=0 ) { StripChar((PRUnichar) (unsigned char)aChar,anOffset); }
|
|
|
|
void StripChar( PRInt32 anInt, PRInt32 anOffset=0 ) { StripChar((PRUnichar)anInt,anOffset); }
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* This method strips whitespace throughout the string
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 06:59:14 +00:00
|
|
|
void StripWhitespace();
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* swaps occurence of 1 string for another
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 06:59:14 +00:00
|
|
|
void ReplaceChar( PRUnichar anOldChar, PRUnichar aNewChar );
|
|
|
|
void ReplaceChar( const char* aSet, PRUnichar aNewChar );
|
1999-10-05 04:47:19 +00:00
|
|
|
|
2000-04-21 06:59:14 +00:00
|
|
|
void ReplaceSubstring( const nsString& aTarget, const nsString& aNewValue );
|
|
|
|
void ReplaceSubstring( const PRUnichar* aTarget, const PRUnichar* aNewValue );
|
1999-12-02 10:14:38 +00:00
|
|
|
|
2000-12-12 21:58:14 +00:00
|
|
|
PRInt32 CountChar( PRUnichar aChar ) const;
|
1999-10-05 04:47:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 12:11:03 +00:00
|
|
|
* @param aEliminateLeading
|
|
|
|
* @param aEliminateTrailing
|
|
|
|
* @param aIgnoreQuotes
|
1999-10-05 04:47:19 +00:00
|
|
|
* @return this
|
|
|
|
*/
|
2000-04-21 06:59:14 +00:00
|
|
|
void Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE,PRBool aIgnoreQuotes=PR_FALSE);
|
1999-10-05 04:47:19 +00: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 06:59:14 +00:00
|
|
|
void CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
1999-10-05 04:47:19 +00: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 06:59:14 +00:00
|
|
|
void CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**********************************************************************
|
|
|
|
string conversion methods...
|
|
|
|
*********************************************************************/
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* This method constructs a new nsString is a clone of this string.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
nsString* ToNewString() const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00: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;
|
1999-09-13 22:51:29 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Creates an UTF8 clone of this string
|
|
|
|
* Note that calls to this method should be matched with calls to Recycle().
|
2000-03-29 03:58:50 +00:00
|
|
|
* @return ptr to new null-terminated UTF8 string
|
1999-10-05 04:47:19 +00:00
|
|
|
*/
|
|
|
|
char* ToNewUTF8String() const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00: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;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00: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;
|
1999-06-17 07:24:13 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Perform string to int conversion.
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
2000-02-13 17:46:15 +00: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 04:47:19 +00:00
|
|
|
*/
|
|
|
|
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**********************************************************************
|
|
|
|
String manipulation methods...
|
|
|
|
*********************************************************************/
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* assign given string to this string
|
|
|
|
* @param aStr: buffer to be assigned to this
|
1999-11-19 08:05:30 +00: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 04:47:19 +00:00
|
|
|
* @return this
|
|
|
|
*/
|
2000-03-30 22:51:51 +00:00
|
|
|
|
2000-05-12 05:25:26 +00:00
|
|
|
nsString& operator=( const nsString& aString ) { Assign(aString); return *this; }
|
|
|
|
nsString& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
|
|
|
|
nsString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
|
|
|
|
|
2000-03-30 22:51:51 +00:00
|
|
|
void AssignWithConversion(char);
|
|
|
|
void AssignWithConversion(const char*);
|
|
|
|
void AssignWithConversion(const char*, PRInt32);
|
1999-10-05 04:47:19 +00:00
|
|
|
|
2000-03-30 22:51:51 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/*
|
|
|
|
* Appends n characters from given string to this,
|
|
|
|
* This version computes the length of your given string
|
|
|
|
*
|
|
|
|
* @param aString is the source to be appended to this
|
|
|
|
* @return number of chars copied
|
|
|
|
*/
|
2000-03-30 22:51:51 +00:00
|
|
|
|
2000-04-15 00:05:17 +00:00
|
|
|
void AppendInt(PRInt32, PRInt32=10); //radix=8,10 or 16
|
|
|
|
void AppendFloat(double);
|
2000-04-01 00:24:39 +00:00
|
|
|
void AppendWithConversion(const char*, PRInt32=-1);
|
2000-03-30 22:51:51 +00:00
|
|
|
void AppendWithConversion(char);
|
|
|
|
|
2000-08-18 04:48:29 +00:00
|
|
|
virtual void do_AppendFromElement( PRUnichar );
|
|
|
|
|
1999-05-06 05:13:08 +00:00
|
|
|
|
1999-10-05 04:47:19 +00: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(nsString& 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(nsString& 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(nsString& aCopy,PRInt32 aCount) const;
|
|
|
|
|
2000-03-30 22:51:51 +00:00
|
|
|
|
|
|
|
//void InsertWithConversion(char);
|
|
|
|
void InsertWithConversion(const char*, PRUint32, PRInt32=-1);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**********************************************************************
|
|
|
|
Searching methods...
|
|
|
|
*********************************************************************/
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00: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 12:11:03 +00:00
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-10-05 04:47:19 +00:00
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
2000-03-24 07:21:56 +00:00
|
|
|
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
|
|
|
|
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 04:47:19 +00: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 12:11:03 +00:00
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-10-05 04:47:19 +00:00
|
|
|
* @return find pos in string, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
|
2000-03-24 07:21:56 +00:00
|
|
|
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=0,PRInt32 aCount=-1) const;
|
1999-10-05 04:47:19 +00: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 07:21:56 +00: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-25 17:21:14 +00:00
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00: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 12:11:03 +00:00
|
|
|
* @param anOffset tells us where in this strig to start searching (counting from left)
|
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
1999-10-05 04:47:19 +00:00
|
|
|
*/
|
2000-02-11 12:11:03 +00:00
|
|
|
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 RFind(const nsString& aString,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 04:47:19 +00: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 (counting from left)
|
|
|
|
* @param aIgnoreCase selects case sensitivity
|
2000-02-11 12:11:03 +00:00
|
|
|
* @param aCount tells us how many iterations to make starting at the given offset
|
1999-10-05 04:47:19 +00:00
|
|
|
* @return find pos in string, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
|
2000-02-11 12:11:03 +00:00
|
|
|
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1,PRInt32 aCount=-1) const;
|
1999-10-05 04:47:19 +00: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 in this strig to start searching (counting from left)
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Comparison methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-17 11:06:41 +00:00
|
|
|
|
2000-03-31 07:26:13 +00:00
|
|
|
PRInt32 CompareWithConversion(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 CompareWithConversion(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
|
|
|
PRInt32 CompareWithConversion(const PRUnichar* 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;
|
2000-04-16 11:09:16 +00:00
|
|
|
PRBool EqualsAtom(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
2000-03-31 07:26:13 +00:00
|
|
|
|
|
|
|
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
|
|
|
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
|
|
|
|
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
|
1999-10-05 04:47:19 +00:00
|
|
|
|
2000-03-30 22:51:51 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Determine if given buffer is plain ascii
|
|
|
|
*
|
|
|
|
* @param aBuffer -- if null, then we test *this, otherwise we test given buffer
|
|
|
|
* @return TRUE if is all ascii chars or if strlen==0
|
|
|
|
*/
|
|
|
|
PRBool IsASCII(const PRUnichar* aBuffer=0);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-11-19 08:05:30 +00:00
|
|
|
void DebugDump(void) const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Determine if given char is a valid space character
|
|
|
|
*
|
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if is valid space char
|
|
|
|
*/
|
|
|
|
static PRBool IsSpace(PRUnichar ch);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Determine if given char in valid alpha range
|
|
|
|
*
|
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if in alpha range
|
|
|
|
*/
|
|
|
|
static PRBool IsAlpha(PRUnichar ch);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
/**
|
|
|
|
* Determine if given char is valid digit
|
|
|
|
*
|
|
|
|
* @param aChar is character to be tested
|
|
|
|
* @return TRUE if char is a valid digit
|
|
|
|
*/
|
|
|
|
static PRBool IsDigit(PRUnichar ch);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-10-05 04:47:19 +00:00
|
|
|
static void Recycle(nsString* aString);
|
|
|
|
static nsString* CreateString(void);
|
1999-03-22 09:54:46 +00:00
|
|
|
|
2000-04-17 11:06:41 +00: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 05:25:26 +00:00
|
|
|
void operator=( char );
|
2000-04-17 12:22:37 +00:00
|
|
|
void AssignWithConversion( PRUnichar );
|
|
|
|
void AssignWithConversion( const PRUnichar*, PRInt32=-1 );
|
|
|
|
void AppendWithConversion( PRUnichar );
|
|
|
|
void AppendWithConversion( const PRUnichar*, PRInt32=-1 );
|
|
|
|
void InsertWithConversion( const PRUnichar*, PRUint32, PRInt32=-1 );
|
1999-03-22 09:54:46 +00:00
|
|
|
};
|
|
|
|
|
2000-09-03 03:16:47 +00:00
|
|
|
// NS_DEF_STRING_COMPARISON_OPERATORS(nsString, PRUnichar)
|
2000-09-04 01:34:04 +00:00
|
|
|
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsString, PRUnichar)
|
2000-06-11 01:06:14 +00:00
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
1999-07-17 10:08:10 +00:00
|
|
|
//ostream& operator<<(ostream& aStream,const nsString& aString);
|
|
|
|
//virtual void DebugDump(ostream& aStream) const;
|
1999-03-22 09:54:46 +00: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.
|
|
|
|
**************************************************************/
|
|
|
|
|
1999-07-17 07:26:16 +00:00
|
|
|
class NS_COM nsAutoString : public nsString {
|
1999-03-22 09:54:46 +00:00
|
|
|
public:
|
|
|
|
|
2000-03-30 22:51:51 +00:00
|
|
|
virtual ~nsAutoString();
|
1999-09-02 07:04:59 +00:00
|
|
|
nsAutoString();
|
2000-03-30 22:51:51 +00:00
|
|
|
nsAutoString(const nsAutoString& aString);
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsAutoString(const nsAReadableString& aString);
|
|
|
|
explicit nsAutoString(const nsString& aString);
|
|
|
|
explicit nsAutoString(const PRUnichar* aString);
|
2000-05-15 03:10:19 +00:00
|
|
|
nsAutoString(const PRUnichar* aString,PRInt32 aLength);
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsAutoString(PRUnichar aChar);
|
|
|
|
explicit nsAutoString(const CBufDescriptor& aBuffer);
|
2000-03-29 00:06:31 +00:00
|
|
|
|
2000-05-01 22:25:44 +00:00
|
|
|
#if defined(AIX) || defined(XP_OS2_VACPP)
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX and VAC++ requires a const
|
1999-06-04 22:08:19 +00:00
|
|
|
#else
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsAutoString(nsSubsumeStr& aSubsumeStr);
|
2000-05-01 22:25:44 +00:00
|
|
|
#endif // AIX || XP_OS2_VACPP
|
2000-03-29 00:06:31 +00:00
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
|
2000-05-12 05:25:26 +00:00
|
|
|
nsAutoString& operator=( const nsAutoString& aString ) { Assign(aString); return *this; }
|
|
|
|
private:
|
|
|
|
void operator=( char ); // NOT TO BE IMPLEMENTED
|
|
|
|
public:
|
|
|
|
nsAutoString& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsAutoString& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsAutoString& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
|
|
|
|
nsAutoString& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
|
1999-03-22 09:54:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the size of this string
|
|
|
|
* @return string length
|
|
|
|
*/
|
1999-08-31 03:04:37 +00:00
|
|
|
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
1999-03-22 09:54:46 +00:00
|
|
|
|
1999-08-30 06:55:13 +00:00
|
|
|
char mBuffer[kDefaultStringSize<<eTwoByte];
|
1999-03-22 09:54:46 +00:00
|
|
|
};
|
|
|
|
|
2000-09-03 22:38:38 +00:00
|
|
|
NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsAutoString, PRUnichar)
|
|
|
|
|
2000-04-15 00:05:17 +00:00
|
|
|
class NS_COM NS_ConvertASCIItoUCS2
|
|
|
|
: public nsAutoString
|
|
|
|
/*
|
|
|
|
...
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
public:
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit NS_ConvertASCIItoUCS2( const char* );
|
2000-04-15 00:05:17 +00:00
|
|
|
NS_ConvertASCIItoUCS2( const char*, PRUint32 );
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit NS_ConvertASCIItoUCS2( char );
|
2000-04-23 01:03:28 +00:00
|
|
|
|
2000-09-13 03:44:58 +00:00
|
|
|
const PRUnichar* get() const { return GetUnicode(); }
|
|
|
|
|
2000-06-20 04:25:20 +00:00
|
|
|
operator const PRUnichar*() const
|
|
|
|
{
|
|
|
|
return GetUnicode();
|
|
|
|
}
|
|
|
|
|
2000-06-11 01:06:14 +00:00
|
|
|
operator nsLiteralString() const
|
|
|
|
{
|
|
|
|
return nsLiteralString(mUStr, mLength);
|
|
|
|
}
|
|
|
|
|
2000-04-23 01:03:28 +00:00
|
|
|
private:
|
|
|
|
// NOT TO BE IMPLEMENTED
|
|
|
|
NS_ConvertASCIItoUCS2( PRUnichar );
|
2000-04-15 00:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NS_ConvertToString NS_ConvertASCIItoUCS2
|
|
|
|
|
|
|
|
#if 0
|
2000-04-03 04:52:47 +00:00
|
|
|
inline
|
|
|
|
nsAutoString
|
|
|
|
NS_ConvertToString( const char* aCString )
|
|
|
|
{
|
|
|
|
nsAutoString result;
|
|
|
|
result.AssignWithConversion(aCString);
|
|
|
|
return result;
|
|
|
|
}
|
1999-03-22 09:54:46 +00:00
|
|
|
|
2000-04-03 04:52:47 +00:00
|
|
|
inline
|
|
|
|
nsAutoString
|
|
|
|
NS_ConvertToString( const char* aCString, PRUint32 aLength )
|
|
|
|
{
|
|
|
|
nsAutoString result;
|
|
|
|
result.AssignWithConversion(aCString, aLength);
|
|
|
|
return result;
|
|
|
|
}
|
2000-04-15 00:05:17 +00:00
|
|
|
#endif
|
1999-07-25 17:21:14 +00:00
|
|
|
|
2000-06-02 20:06:54 +00:00
|
|
|
|
|
|
|
class NS_COM NS_ConvertUTF8toUCS2
|
|
|
|
: public nsAutoString
|
|
|
|
{
|
|
|
|
public:
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit
|
2000-06-02 20:06:54 +00:00
|
|
|
NS_ConvertUTF8toUCS2( const char* aCString )
|
2000-06-20 04:25:20 +00:00
|
|
|
{
|
|
|
|
Init( aCString, ~PRUint32(0) /* MAXINT */ );
|
|
|
|
}
|
2000-06-02 20:06:54 +00:00
|
|
|
|
|
|
|
NS_ConvertUTF8toUCS2( const char* aCString, PRUint32 aLength )
|
2000-06-20 04:25:20 +00:00
|
|
|
{
|
|
|
|
Init( aCString, aLength );
|
|
|
|
}
|
2000-06-02 20:06:54 +00:00
|
|
|
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit
|
2000-06-02 20:06:54 +00:00
|
|
|
NS_ConvertUTF8toUCS2( char aChar )
|
2000-06-20 04:25:20 +00:00
|
|
|
{
|
|
|
|
Init( &aChar, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
operator const PRUnichar*() const
|
|
|
|
{
|
|
|
|
return GetUnicode();
|
|
|
|
}
|
2000-06-02 20:06:54 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void Init( const char* aCString, PRUint32 aLength );
|
|
|
|
|
|
|
|
private:
|
|
|
|
NS_ConvertUTF8toUCS2( PRUnichar );
|
|
|
|
};
|
|
|
|
|
1999-05-06 05:13:08 +00: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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should probably not use this class unless you really know
|
|
|
|
what you're doing.
|
|
|
|
***************************************************************/
|
1999-07-17 07:26:16 +00:00
|
|
|
class NS_COM nsSubsumeStr : public nsString {
|
1999-05-06 05:13:08 +00:00
|
|
|
public:
|
2000-02-11 12:11:03 +00:00
|
|
|
nsSubsumeStr();
|
2000-09-02 20:53:31 +00:00
|
|
|
explicit nsSubsumeStr(nsStr& aString);
|
1999-05-29 07:29:46 +00:00
|
|
|
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
|
|
|
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
2000-02-11 15:19:17 +00:00
|
|
|
int Subsume(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
2000-05-12 05:25:26 +00:00
|
|
|
|
|
|
|
nsSubsumeStr& operator=( const nsSubsumeStr& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsSubsumeStr& operator=( const nsAReadableString& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsSubsumeStr& operator=( const nsPromiseReadable<PRUnichar>& aReadable ) { Assign(aReadable); return *this; }
|
|
|
|
nsSubsumeStr& operator=( const PRUnichar* aPtr ) { Assign(aPtr); return *this; }
|
|
|
|
nsSubsumeStr& operator=( PRUnichar aChar ) { Assign(aChar); return *this; }
|
|
|
|
private:
|
|
|
|
void operator=( char ); // NOT TO BE IMPLEMENTED
|
1999-05-06 05:13:08 +00:00
|
|
|
};
|
|
|
|
|
1999-06-03 10:49:14 +00:00
|
|
|
|
1999-03-22 09:54:46 +00:00
|
|
|
#endif
|
|
|
|
|
1999-05-06 05:13:08 +00:00
|
|
|
|