1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
MODULE NOTES:
|
|
|
|
|
|
|
|
A. There are two philosophies to building string classes:
|
|
|
|
1. Hide the underlying buffer & offer API's allow indirect iteration
|
|
|
|
2. Reveal underlying buffer, risk corruption, but gain performance
|
|
|
|
|
|
|
|
We chose the second option for performance reasons.
|
|
|
|
|
|
|
|
B Our internal buffer always holds capacity+1 bytes.
|
|
|
|
***********************************************************************/
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-04-25 07:10:44 +04:00
|
|
|
#ifndef _NSSTRING
|
|
|
|
#define _NSSTRING
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include <iostream.h>
|
|
|
|
#include <stdio.h>
|
1998-06-06 01:38:36 +04:00
|
|
|
class nsISizeOfHandler;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-04-25 07:10:44 +04:00
|
|
|
class NS_BASE nsString {
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
/**
|
|
|
|
* Default constructor. Note that we actually allocate a small buffer
|
|
|
|
* to begin with. This is because the "philosophy" of the string class
|
|
|
|
* was to allow developers direct access to the underlying buffer for
|
|
|
|
* performance reasons.
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString();
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor accepts an isolatin string
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param an ascii is a ptr to a 1-byte cstr
|
1998-09-04 21:26:37 +04:00
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString(const char* aCString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is our copy constructor
|
1999-04-25 07:10:44 +04:00
|
|
|
* @param reference to another nsString
|
1998-09-04 21:26:37 +04:00
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString(const nsString&);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor from a unicode string
|
|
|
|
* @param anicodestr pts to a unicode string
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString(const PRUnichar* aUnicode);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual Destructor
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
virtual ~nsString();
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the length of this string
|
|
|
|
* @return string length
|
|
|
|
*/
|
|
|
|
PRInt32 Length() const { return mLength; }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the new length of the string.
|
|
|
|
* @param aLength is new string length.
|
|
|
|
* @return nada
|
|
|
|
*/
|
|
|
|
void SetLength(PRInt32 aLength);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method truncates this string to given length.
|
|
|
|
*
|
|
|
|
* @param anIndex -- new length of string
|
|
|
|
* @return nada
|
|
|
|
*/
|
|
|
|
void Truncate(PRInt32 anIndex=0);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method gets called when the internal buffer needs
|
|
|
|
* to grow to a given size.
|
|
|
|
* @param aNewLength -- new capacity of string
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
virtual void EnsureCapacityFor(PRInt32 aNewLength);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
*/
|
|
|
|
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether or not the characters in this
|
|
|
|
* string are in sorted order.
|
|
|
|
*
|
|
|
|
* @return TRUE if ordered.
|
|
|
|
*/
|
|
|
|
PRBool IsOrdered(void) const;
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Accessor methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve pointer to internal string value
|
|
|
|
* @return PRUnichar* to internal string
|
|
|
|
*/
|
|
|
|
const PRUnichar* GetUnicode(void) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
operator const PRUnichar*() const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve unicode char at given index
|
|
|
|
* @param offset into string
|
|
|
|
* @return PRUnichar* to internal string
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRUnichar operator()(PRInt32 anIndex) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve reference to unicode char at given index
|
|
|
|
* @param offset into string
|
|
|
|
* @return PRUnichar& from internal string
|
|
|
|
*/
|
|
|
|
PRUnichar& operator[](PRInt32 anIndex) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve reference to unicode char at given index
|
|
|
|
* @param offset into string
|
|
|
|
* @return PRUnichar& from internal string
|
|
|
|
*/
|
|
|
|
PRUnichar& CharAt(PRInt32 anIndex) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve reference to first unicode char in string
|
|
|
|
* @return PRUnichar from internal string
|
|
|
|
*/
|
|
|
|
PRUnichar& First() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve reference to last unicode char in string
|
|
|
|
* @return PRUnichar from internal string
|
|
|
|
*/
|
|
|
|
PRUnichar& Last() const;
|
|
|
|
|
1999-03-22 11:29:26 +03:00
|
|
|
PRBool SetCharAt(PRUnichar aChar,PRInt32 anIndex);
|
|
|
|
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
/**********************************************************************
|
|
|
|
String creation methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new string by appending given string to this
|
|
|
|
* @param aString -- 2nd string to be appended
|
|
|
|
* @return new string
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString operator+(const nsString& aString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given buffer.
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString is a ptr to cstring to be added to this
|
1998-09-04 21:26:37 +04:00
|
|
|
* @return newly created string
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString operator+(const char* aCString);
|
1998-09-04 21:26:37 +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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString operator+(char aChar);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given buffer.
|
|
|
|
* @param aStr unichar buffer to be added to this
|
|
|
|
* @return newly created string
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString operator+(const PRUnichar* aBuffer);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create a new string by adding this to the given char.
|
|
|
|
* @param aChar is a unichar to be added to this
|
|
|
|
* @return newly created string
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString operator+(PRUnichar aChar);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts all chars in internal string to lower
|
|
|
|
*/
|
|
|
|
void ToLowerCase();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts all chars in given string to lower
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
void ToLowerCase(nsString& aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts all chars in given string to upper
|
|
|
|
*/
|
|
|
|
void ToUpperCase();
|
|
|
|
|
1999-01-09 04:09:39 +03:00
|
|
|
/**
|
|
|
|
* Converts all chars in given string to UCS2
|
|
|
|
* which ensure that the lower 256 chars are correct.
|
|
|
|
*/
|
|
|
|
void ToUCS2(PRInt32 aStartOffset);
|
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
/**
|
|
|
|
* Converts all chars in internal string to upper
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
void ToUpperCase(nsString& aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a duplicate clone (ptr) of this string.
|
|
|
|
* @return ptr to clone of this string
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString* ToNewString() const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
1998-11-21 01:11:09 +03:00
|
|
|
* Creates an ascii clone of this string
|
|
|
|
* NOTE: This string is allocated with new; YOU MUST deallocate with delete[]!
|
|
|
|
* @return ptr to new c-String string
|
1998-09-04 21:26:37 +04:00
|
|
|
*/
|
|
|
|
char* ToNewCString() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies data from internal buffer onto given char* buffer
|
|
|
|
* @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,PRInt32 aBufLength) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies contents of this onto given string.
|
|
|
|
* @param aString to hold copy of this
|
|
|
|
* @return nada.
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
void Copy(nsString& aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an unichar clone of this string
|
|
|
|
* @return ptr to new unichar string
|
|
|
|
*/
|
|
|
|
PRUnichar* ToNewUnicode() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform string to float conversion.
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return float rep of string value
|
|
|
|
*/
|
|
|
|
float ToFloat(PRInt32* aErrorCode) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform string to int conversion.
|
|
|
|
* @param aErrorCode will contain error if one occurs
|
|
|
|
* @return int rep of string value
|
|
|
|
*/
|
1998-10-04 08:52:10 +04:00
|
|
|
PRInt32 ToInteger(PRInt32* aErrorCode,PRInt32 aRadix=10) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
String manipulation methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given PRUnichar* to this string
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aStr: buffer to be assigned to this
|
1998-09-04 21:26:37 +04:00
|
|
|
* @param alength is the length of the given str (or -1)
|
|
|
|
if you want me to determine its length
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char* to this string
|
|
|
|
* @param aCString: buffer to be assigned to this
|
|
|
|
* @param alength is the length of the given str (or -1)
|
|
|
|
if you want me to determine its length
|
|
|
|
* @return this
|
|
|
|
*/
|
|
|
|
nsString& SetString(const char* aCString,PRInt32 aLength=-1);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given string to this one
|
|
|
|
* @param aString: string to be added to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator=(const nsString& aString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char* to this string
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString: buffer to be assigned to this
|
1998-09-04 21:26:37 +04:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator=(const char* aCString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char to this string
|
|
|
|
* @param aChar: char to be assignd to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator=(char aChar);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given unichar* to this string
|
|
|
|
* @param aBuffer: unichar buffer to be assigned to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator=(const PRUnichar* aBuffer);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* assign given char to this string
|
|
|
|
* @param aChar: char to be assignd to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator=(PRUnichar aChar);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given string to this string
|
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator+=(const nsString& aString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given buffer to this string
|
1998-11-21 01:11:09 +03:00
|
|
|
* @param aCString: buffer to be appended to this
|
1998-09-04 21:26:37 +04:00
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator+=(const char* aCString);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given buffer to this string
|
|
|
|
* @param aBuffer: buffer to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator+=(const PRUnichar* aBuffer);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given char to this string
|
|
|
|
* @param aChar: char to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& operator+=(PRUnichar aChar);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given string to this string
|
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @param alength is the length of the given str (or -1)
|
|
|
|
if you want me to determine its length
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given string to this string
|
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @param alength is the length of the given str (or -1)
|
|
|
|
if you want me to determine its length
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Append(const char* aCString,PRInt32 aLength=-1);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given string to this string
|
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Append(char aChar);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given unichar buffer to this string
|
|
|
|
* @param aString : string to be appended to this
|
|
|
|
* @param alength is the length of the given str (or -1)
|
|
|
|
if you want me to determine its length
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append given unichar character to this string
|
|
|
|
* @param aChar is the char to be appended to this
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Append(PRUnichar aChar);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append an integer onto this string
|
|
|
|
* @param aInteger is the int to be appended
|
|
|
|
* @param aRadix specifies 8,10,16
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append a float value onto this string
|
|
|
|
* @param aFloat is the float to be appended
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Append(float aFloat);
|
1998-09-04 21:26:37 +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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 Left(nsString& aCopy,PRInt32 aCount) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 Right(nsString& aCopy,PRInt32 aCount) const;
|
1998-09-04 21:26:37 +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
|
|
|
|
* @return number of chars inserted into this.
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 Insert(const nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a single unicode char into this string at
|
|
|
|
* a specified offset.
|
|
|
|
*
|
|
|
|
* @param aChar char to be inserted into this string
|
|
|
|
* @param anOffset is insert pos in str
|
|
|
|
* @return the number of chars inserted into this string
|
|
|
|
*/
|
|
|
|
PRInt32 Insert(PRUnichar aChar,PRInt32 anOffset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
1998-09-04 21:26:37 +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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& StripChars(const char* aSet);
|
1998-09-04 21:26:37 +04:00
|
|
|
|
1999-02-16 09:47:00 +03:00
|
|
|
/**
|
|
|
|
* This method is used to replace all occurances of the
|
|
|
|
* given source char with the given dest char
|
|
|
|
*
|
|
|
|
* @param
|
|
|
|
* @return *this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& ReplaceChar(PRUnichar aSourceChar, PRUnichar aDestChar);
|
1999-02-16 09:47:00 +03:00
|
|
|
|
1998-09-04 21:26:37 +04:00
|
|
|
/**
|
|
|
|
* This method strips whitespace throughout the string
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& StripWhitespace();
|
1998-09-04 21:26:37 +04: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
|
|
|
|
* @return this
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& Trim(const char* aSet,
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool aEliminateLeading=PR_TRUE,
|
|
|
|
PRBool aEliminateTrailing=PR_TRUE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool aEliminateTrailing=PR_TRUE);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
Searching methods...
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for given character within this string.
|
|
|
|
* This method does so by using a binary search,
|
|
|
|
* so your string HAD BETTER BE ORDERED!
|
|
|
|
*
|
|
|
|
* @param aChar is the unicode char to be found
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
PRInt32 BinarySearch(PRUnichar aChar) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for given substring within this string
|
|
|
|
*
|
|
|
|
* @param aString is substring to be sought in this
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
PRInt32 Find(const char* aString) const;
|
|
|
|
PRInt32 Find(const PRUnichar* aString) const;
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 Find(const nsString& aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for given char within this string
|
|
|
|
*
|
|
|
|
* @param aChar - char to be found
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method searches this string for the first 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 FindCharInSet(const char* aString,PRInt32 anOffset=0) const;
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 FindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
1998-09-04 21:26:37 +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=0) const;
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 RFindCharInSet(nsString& aString,PRInt32 anOffset=0) const;
|
1998-09-04 21:26:37 +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
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
1998-11-21 01:11:09 +03:00
|
|
|
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
1999-04-25 07:10:44 +04:00
|
|
|
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This methods scans the string backwards, looking for the given char
|
|
|
|
* @param char is the char to be sought in this
|
|
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
|
|
* @return offset in string, or -1 (kNotFound)
|
|
|
|
*/
|
|
|
|
PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) 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
|
|
|
|
* @return -1,0,1
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
virtual PRInt32 Compare(const nsString &aString,PRBool aIgnoreCase=PR_FALSE) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
virtual PRInt32 Compare(const char *aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
|
|
|
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aLength=-1) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods compare a given string type to this one
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool operator==(const nsString &aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool operator==(const char *aString) const;
|
|
|
|
PRBool operator==(const PRUnichar* aString) const;
|
1999-02-10 11:22:47 +03:00
|
|
|
PRBool operator==(PRUnichar* aString) const;
|
1998-09-04 21:26:37 +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
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool operator!=(const nsString &aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool operator!=(const char *aString) const;
|
|
|
|
PRBool operator!=(const PRUnichar* aString) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is < than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool operator<(const nsString &aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool operator<(const char *aString) const;
|
|
|
|
PRBool operator<(const PRUnichar* aString) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is > than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool operator>(const nsString &S) const;
|
1998-11-21 01:11:09 +03:00
|
|
|
PRBool operator>(const char *aCString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool operator>(const PRUnichar* aString) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is <= than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool operator<=(const nsString &S) const;
|
1998-11-21 01:11:09 +03:00
|
|
|
PRBool operator<=(const char *aCString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool operator<=(const PRUnichar* aString) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These methods test if a given string is >= than this
|
|
|
|
* @param aString is the string to be compared to this
|
|
|
|
* @return TRUE or FALSE
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool operator>=(const nsString &S) const;
|
1998-11-21 01:11:09 +03:00
|
|
|
PRBool operator>=(const char* aCString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool operator>=(const PRUnichar* aString) 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 aLength -- optional length of given string.
|
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool Equals(const nsString& aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool Equals(const char* aString,PRInt32 aLength=-1) const;
|
|
|
|
PRBool Equals(const nsIAtom *aAtom) const;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares to unichar string ptrs to each other
|
|
|
|
* @param s1 is a ptr to a unichar buffer
|
|
|
|
* @param s2 is a ptr to a unichar buffer
|
|
|
|
* @return TRUE if they match
|
|
|
|
*/
|
|
|
|
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) 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 aLength -- optional length of given string.
|
|
|
|
* @return TRUE if equal
|
|
|
|
*/
|
1999-04-25 07:10:44 +04:00
|
|
|
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
1998-09-04 21:26:37 +04:00
|
|
|
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aLength=-1) const;
|
|
|
|
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares to unichar string ptrs to each other without respect to case
|
|
|
|
* @param s1 is a ptr to a unichar buffer
|
|
|
|
* @param s2 is a ptr to a unichar buffer
|
|
|
|
* @return TRUE if they match
|
|
|
|
*/
|
|
|
|
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
|
|
|
|
|
|
|
|
|
|
|
|
static void SelfTest();
|
|
|
|
virtual void DebugDump(ostream& aStream) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef PRUnichar chartype;
|
|
|
|
|
|
|
|
chartype* mStr;
|
|
|
|
PRInt32 mLength;
|
|
|
|
PRInt32 mCapacity;
|
1999-04-25 05:27:51 +04:00
|
|
|
#ifdef RICKG_DEBUG
|
1998-08-04 00:46:38 +04:00
|
|
|
static PRBool mSelfTested;
|
1999-03-19 11:47:20 +03:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1999-04-25 07:10:44 +04:00
|
|
|
ostream& operator<<(ostream& os,nsString& aString);
|
|
|
|
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
1999-04-25 07:10:44 +04:00
|
|
|
* A version of nsString which is designed to be used as an automatic
|
1998-04-14 00:24:54 +04:00
|
|
|
* variable. It attempts to operate out of a fixed size internal
|
|
|
|
* buffer until too much data is added; then a dynamic buffer is
|
|
|
|
* allocated and grown as necessary.
|
|
|
|
*/
|
|
|
|
// XXX template this with a parameter for the size of the buffer?
|
1999-04-25 07:10:44 +04:00
|
|
|
class NS_BASE nsAutoString : public nsString {
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
1999-04-25 07:10:44 +04:00
|
|
|
nsAutoString();
|
|
|
|
nsAutoString(const nsString& other);
|
|
|
|
nsAutoString(const nsAutoString& other);
|
|
|
|
nsAutoString(PRUnichar aChar);
|
|
|
|
nsAutoString(const char* aCString);
|
|
|
|
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
|
|
|
virtual ~nsAutoString();
|
|
|
|
|
|
|
|
nsAutoString& operator=(const nsString& aString) {nsString::operator=(aString); return *this;}
|
|
|
|
nsAutoString& operator=(const nsAutoString& aString) {nsString::operator=(aString); return *this;}
|
|
|
|
nsAutoString& operator=(const char* aCString) {nsString::operator=(aCString); return *this;}
|
|
|
|
nsAutoString& operator=(char aChar) {nsString::operator=(aChar); return *this;}
|
|
|
|
nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::operator=(aBuffer); return *this;}
|
|
|
|
nsAutoString& operator=(PRUnichar aChar) {nsString::operator=(aChar); return *this;}
|
1998-07-23 01:38:48 +04:00
|
|
|
|
1998-06-06 01:38:36 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler* aHandler) const;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
static void SelfTest();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void EnsureCapacityFor(PRInt32 aNewLength);
|
|
|
|
|
1998-08-27 12:15:40 +04:00
|
|
|
chartype mBuf[32];
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
1999-04-25 07:10:44 +04:00
|
|
|
ostream& operator<<(ostream& os,nsAutoString& aString);
|
1998-08-22 21:50:13 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
|
|
|
|