/* -*- 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. */ /*********************************************************************** MODULE NOTES: 1. There are two philosophies to building string classes: A. Hide the underlying buffer & offer API's allow indirect iteration B. Reveal underlying buffer, risk corruption, but gain performance We chose the option B for performance reasons. 2 Our internal buffer always holds capacity+1 bytes. The nsStr struct is a simple structure (no methods) that contains the necessary info to be described as a string. This simple struct is manipulated by the static methods provided in this class. (Which effectively makes this a library that works on structs). There are also object-based versions called nsString and nsAutoString which use nsStr but makes it look at feel like an object. ***********************************************************************/ /*********************************************************************** ASSUMPTIONS: 1. nsStrings and nsAutoString are always null terminated. 2. If you try to set a null char (via SetChar()) a new length is set 3. nsCStrings can be upsampled into nsString without data loss 4. Char searching is faster than string searching. Use char interfaces if your needs will allow it. 5. It's easy to use the stack for nsAutostring buffer storage (fast too!). See the CBufDescriptor class in this file. 6. It's ONLY ok to provide non-null-terminated buffers to Append() and Insert() provided you specify a 0 */ static PRInt32 Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase); /** * These methods scan the given string for 1 or more chars in a given direction * * @update gess 01/04/99 * @param aDest is the nsStr to be searched to * @param aSource (or aChar) is the substr we're looking to find * @param aIgnoreCase tells us whether to search in a case-sensitive manner * @param anOffset tells us where in the dest string to start searching * @return the index of the source (substr) in dest, or -1 (kNotFound) if not found. */ static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset); static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset); PRUint32 mLength; PRUint32 mCapacity; eCharSize mCharSize; PRBool mOwnsBuffer; union { char* mStr; PRUnichar* mUStr; }; }; /************************************************************** A couple of tiny helper methods used in the string classes. **************************************************************/ inline PRInt32 MinInt(PRInt32 anInt1,PRInt32 anInt2){ return (anInt1