📄 nsastring.h
字号:
inline PRBool Equals( const abstract_string_type&, const nsCStringComparator& = nsDefaultCStringComparator() ) const; PRBool Equals( const char_type*, const nsCStringComparator& = nsDefaultCStringComparator() ) const; virtual PRBool IsVoid() const; virtual void SetIsVoid( PRBool ); /** * |CharAt|, |operator[]|, |First()|, and |Last()| are not * guaranteed to be constant-time operations. These signatures * should be pushed down into interfaces that guarantee flat * allocation. (Right now |First| and |Last| are here but * |CharAt| and |operator[]| are on |nsASingleFragmentString|.) * * Clients at _this_ level should always use iterators. For * example, to see if the n-th character is a '-': * * nsACString::const_iterator iter; * if ( *myString.BeginReading(iter).advance(n) == '-' ) * // do something... * */ char_type First() const; char_type Last() const; size_type CountChar( char_type ) const; // Find( ... ) const; PRInt32 FindChar( char_type, index_type aOffset = 0 ) const; // FindCharInSet( ... ) const; // RFind( ... ) const; // RFindChar( ... ) const; // RFindCharInSet( ... ) const; /** * |SetCapacity| is not required to do anything; however, it can be * used as a hint to the implementation to reduce allocations. * |SetCapacity(0)| is a suggestion to discard all associated storage. */ virtual void SetCapacity( size_type ) { } /** * |SetLength| is used in two ways: * 1) to |Cut| a suffix of the string; * 2) to prepare to |Append| or move characters around. * * External callers are not allowed to use |SetLength| is this * latter capacity, and should prefer |Truncate| for the former. * In other words, |SetLength| is deprecated for all use outside * of the string library and the internal use may at some point * be replaced as well. * * Should this really be a public operation? * * Additionally, your implementation of |SetLength| need not * satisfy (2) if and only if you override the |do_...| routines * to not need this facility. * * This distinction makes me think the two different uses should * be split into two distinct functions. */ virtual void SetLength( size_type ) { } void Truncate( size_type aNewLength=0 ) { NS_ASSERTION(aNewLength <= this->Length(), "Can't use |Truncate()| to make a string longer."); SetLength(aNewLength); } // PRBool SetCharAt( char_type, index_type ) = 0; // void ToLowerCase(); // void ToUpperCase(); // void StripChars( const char_type* aSet ); // void StripChar( ... ); // void StripWhitespace(); // void ReplaceChar( ... ); // void ReplaceSubstring( ... ); // void Trim( ... ); // void CompressSet( ... ); // void CompressWhitespace( ... ); /** * |Assign()| and |operator=()| make |this| equivalent to the * string or buffer given as an argument. If possible, they do * this by sharing a refcounted buffer (see * |nsSharableC?String|, |nsXPIDLC?String|. If not, they copy * the buffer into their own buffer. */ void Assign( const self_type& aReadable ) { do_AssignFromReadable(aReadable); } void Assign( const char_type* aPtr ) { aPtr ? do_AssignFromElementPtr(aPtr) : SetLength(0); } void Assign( const char_type* aPtr, size_type aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); } void Assign( char_type aChar ) { do_AssignFromElement(aChar); } // copy-assignment operator. I must define my own if I don't want the compiler to make me one self_type& operator=( const self_type& aReadable ) { Assign(aReadable); return *this; } self_type& operator=( const char_type* aPtr ) { Assign(aPtr); return *this; } self_type& operator=( char_type aChar ) { Assign(aChar); return *this; } // // |Append()|, |operator+=()| // void Append( const self_type& aReadable ) { do_AppendFromReadable(aReadable); } void Append( const char_type* aPtr ) { if (aPtr) do_AppendFromElementPtr(aPtr); } void Append( const char_type* aPtr, size_type aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); } void Append( char_type aChar ) { do_AppendFromElement(aChar); } self_type& operator+=( const self_type& aReadable ) { Append(aReadable); return *this; } self_type& operator+=( const char_type* aPtr ) { Append(aPtr); return *this; } self_type& operator+=( char_type aChar ) { Append(aChar); return *this; } /** * The following index based routines need to be recast with iterators. */ // // |Insert()| // Note: I would really like to move the |atPosition| parameter to the front of the argument list // void Insert( const self_type& aReadable, index_type atPosition ) { do_InsertFromReadable(aReadable, atPosition); } void Insert( const char_type* aPtr, index_type atPosition ) { if (aPtr) do_InsertFromElementPtr(aPtr, atPosition); } void Insert( const char_type* aPtr, index_type atPosition, size_type aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); } void Insert( char_type aChar, index_type atPosition ) { do_InsertFromElement(aChar, atPosition); } virtual void Cut( index_type cutStart, size_type cutLength ); void Replace( index_type cutStart, size_type cutLength, const self_type& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); } private: // NOT TO BE IMPLEMENTED index_type CountChar( incompatible_char_type ) const; void operator= ( incompatible_char_type ); void Assign ( incompatible_char_type ); void operator+= ( incompatible_char_type ); void Append ( incompatible_char_type ); void Insert ( incompatible_char_type, index_type ); protected: void UncheckedAssignFromReadable( const self_type& ); virtual void do_AssignFromReadable( const self_type& ); virtual void do_AssignFromElementPtr( const char_type* ); virtual void do_AssignFromElementPtrLength( const char_type*, size_type ); virtual void do_AssignFromElement( char_type ); void UncheckedAppendFromReadable( const self_type& ); virtual void do_AppendFromReadable( const self_type& ); virtual void do_AppendFromElementPtr( const char_type* ); virtual void do_AppendFromElementPtrLength( const char_type*, size_type ); virtual void do_AppendFromElement( char_type ); void UncheckedInsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromReadable( const self_type&, index_type ); virtual void do_InsertFromElementPtr( const char_type*, index_type ); virtual void do_InsertFromElementPtrLength( const char_type*, index_type, size_type ); virtual void do_InsertFromElement( char_type, index_type ); void UncheckedReplaceFromReadable( index_type, size_type, const self_type& ); virtual void do_ReplaceFromReadable( index_type, size_type, const self_type& );// protected: public: virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 = 0 ) const = 0; virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 = 0 ) = 0; PRBool IsDependentOn( const abstract_string_type& aString ) const; }; /** * Note: measure -- should the |Begin...| and |End...| be |inline|? */inlinensAString::const_iterator&nsAString::BeginReading( const_iterator& aResult ) const { aResult.mOwningString = this; GetReadableFragment(aResult.mFragment, kFirstFragment); aResult.mPosition = aResult.mFragment.mStart; aResult.normalize_forward(); return aResult; }inlinensAString::const_iterator&nsAString::EndReading( const_iterator& aResult ) const { aResult.mOwningString = this; GetReadableFragment(aResult.mFragment, kLastFragment); aResult.mPosition = aResult.mFragment.mEnd; // must not |normalize_backward| as that would likely invalidate tests like |while ( first != last )| return aResult; }inlinensAString::iterator&nsAString::BeginWriting( iterator& aResult ) { aResult.mOwningString = this; GetWritableFragment(aResult.mFragment, kFirstFragment); aResult.mPosition = aResult.mFragment.mStart; aResult.normalize_forward(); return aResult; }inlinensAString::iterator&nsAString::EndWriting( iterator& aResult ) { aResult.mOwningString = this; GetWritableFragment(aResult.mFragment, kLastFragment); aResult.mPosition = aResult.mFragment.mEnd; // must not |normalize_backward| as that would likely invalidate tests like |while ( first != last )| return aResult; }NS_COM int Compare( const nsAString& lhs, const nsAString& rhs, const nsStringComparator& = nsDefaultStringComparator() );inlinePRBoolnsAString::Equals( const abstract_string_type& rhs, const nsStringComparator& aComparator ) const { return Length()==rhs.Length() && Compare(*this, rhs, aComparator)==0; }inlinePRBooloperator!=( const nsAString& lhs, const nsAString& rhs ) { return !lhs.Equals(rhs); }inlinePRBooloperator< ( const nsAString& lhs, const nsAString& rhs ) { return Compare(lhs, rhs)< 0; }inlinePRBooloperator<=( const nsAString& lhs, const nsAString& rhs ) { return Compare(lhs, rhs)<=0; }inlinePRBooloperator==( const nsAString& lhs, const nsAString& rhs ) { return lhs.Equals(rhs); }inlinePRBooloperator>=( const nsAString& lhs, const nsAString& rhs ) { return Compare(lhs, rhs)>=0; }inlinePRBooloperator> ( const nsAString& lhs, const nsAString& rhs ) { return Compare(lhs, rhs)> 0; } /** * */inlinensACString::const_iterator&nsACString::BeginReading( const_iterator& aResult ) const { aResult.mOwningString = this; GetReadableFragment(aResult.mFragment, kFirstFragment); aResult.mPosition = aResult.mFragment.mStart; aResult.normalize_forward(); return aResult; }inlinensACString::const_iterator&nsACString::EndReading( const_iterator& aResult ) const { aResult.mOwningString = this; GetReadableFragment(aResult.mFragment, kLastFragment); aResult.mPosition = aResult.mFragment.mEnd; // must not |normalize_backward| as that would likely invalidate tests like |while ( first != last )| return aResult; }inlinensACString::iterator&nsACString::BeginWriting( iterator& aResult ) { aResult.mOwningString = this; GetWritableFragment(aResult.mFragment, kFirstFragment); aResult.mPosition = aResult.mFragment.mStart; aResult.normalize_forward(); return aResult; }inlinensACString::iterator&nsACString::EndWriting( iterator& aResult ) { aResult.mOwningString = this; GetWritableFragment(aResult.mFragment, kLastFragment); aResult.mPosition = aResult.mFragment.mEnd; // must not |normalize_backward| as that would likely invalidate tests like |while ( first != last )| return aResult; }class NS_COM nsCaseInsensitiveCStringComparator : public nsCStringComparator { public: virtual int operator()( const char_type*, const char_type*, PRUint32 aLength ) const; virtual int operator()( char_type, char_type ) const; };NS_COM int Compare( const nsACString& lhs, const nsACString& rhs, const nsCStringComparator& = nsDefaultCStringComparator() );inlinePRBoolnsACString::Equals( const abstract_string_type& rhs, const nsCStringComparator& aComparator ) const { return Length()==rhs.Length() && Compare(*this, rhs, aComparator)==0; }inlinePRBooloperator!=( const nsACString& lhs, const nsACString& rhs ) { return !lhs.Equals(rhs); }inlinePRBooloperator< ( const nsACString& lhs, const nsACString& rhs ) { return Compare(lhs, rhs)< 0; }inlinePRBooloperator<=( const nsACString& lhs, const nsACString& rhs ) { return Compare(lhs, rhs)<=0; }inlinePRBooloperator==( const nsACString& lhs, const nsACString& rhs ) { return lhs.Equals(rhs); }inlinePRBooloperator>=( const nsACString& lhs, const nsACString& rhs ) { return Compare(lhs, rhs)>=0; }inlinePRBooloperator> ( const nsACString& lhs, const nsACString& rhs ) { return Compare(lhs, rhs)> 0; } // Once you've got strings, you shouldn't need to do anything else to have concatenation#ifndef XPCOM_GLUE#ifndef nsDependentConcatenation_h___#include "nsDependentConcatenation.h"#endif#endif #endif // !defined(nsAString_h___)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -