diff --git a/mozilla/htmlparser/src/nsHTMLEntities.cpp b/mozilla/htmlparser/src/nsHTMLEntities.cpp index 8da989edb42..165611f5214 100644 --- a/mozilla/htmlparser/src/nsHTMLEntities.cpp +++ b/mozilla/htmlparser/src/nsHTMLEntities.cpp @@ -182,7 +182,7 @@ nsHTMLEntities::EntityToUnicode(const nsCString& aEntity) if(';'==aEntity.Last()) { nsCAutoString temp(aEntity); - temp.Truncate(aEntity.mLength-1); + temp.Truncate(aEntity.Length()-1); return EntityToUnicode(temp); } diff --git a/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp b/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp index 2e6af6745ab..822092fda44 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp +++ b/mozilla/layout/mathml/content/src/nsMathMLOperators.cpp @@ -34,24 +34,10 @@ // operator dictionary entry struct OperatorData { OperatorData(void) - : mStr(), - mFlags(0), + : mFlags(0), mLeftSpace(0.0f), mRightSpace(0.0f) { - nsStr::Initialize(mStr, eTwoByte); // with MathML, we are two-byte by default - } - - OperatorData(const nsStr& aStringValue, const nsOperatorFlags aFlags) - : mStr(), - mFlags(aFlags), - mLeftSpace(0.0f), - mRightSpace(0.0f) - { // point to the incomming buffer - // note that the incomming buffer may really be 2 byte - nsStr::Initialize(mStr, aStringValue.mStr, aStringValue.mCapacity, - aStringValue.mLength, eCharSize(aStringValue.mCharSize), - PR_FALSE); } // member data diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index 5f86277baa6..eaf410dac42 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -189,7 +189,7 @@ static void TranslateLineEnding(nsString& data) PRUnichar* sPtr; //Start data pointer PRUnichar* ePtr; //End data pointer - rPtr = wPtr = sPtr = data.mUStr; + rPtr = wPtr = sPtr = NS_CONST_CAST(PRUnichar*, data.get()); ePtr = rPtr + data.Length(); while (rPtr < ePtr) diff --git a/mozilla/netwerk/streamconv/converters/nsDirIndexParser.cpp b/mozilla/netwerk/streamconv/converters/nsDirIndexParser.cpp index c7d01267c31..899babde565 100644 --- a/mozilla/netwerk/streamconv/converters/nsDirIndexParser.cpp +++ b/mozilla/netwerk/streamconv/converters/nsDirIndexParser.cpp @@ -201,7 +201,7 @@ nsDirIndexParser::ParseFormat(const char* aFormatStr) { aFormatStr += len; // Okay, we're gonna monkey with the nsStr. Bold! - name.mLength = nsUnescapeCount(name.mStr); + name.SetLength(nsUnescapeCount(NS_CONST_CAST(char*, name.get()))); // All tokens are case-insensitive - http://www.area.com/~roeber/file_format.html if (name.EqualsIgnoreCase("description")) @@ -359,22 +359,19 @@ nsDirIndexParser::OnDataAvailable(nsIRequest *aRequest, nsISupports *aCtxt, // Ensure that our mBuf has capacity to hold the data we're about to // read. mBuf.SetCapacity(len + aCount + 1); - if (! mBuf.mStr) + if (! mBuf.get()) return NS_ERROR_OUT_OF_MEMORY; // Now read the data into our buffer. nsresult rv; PRUint32 count; - rv = aStream->Read(mBuf.mStr + len, aCount, &count); + rv = aStream->Read(NS_CONST_CAST(char*, mBuf.get() + len), aCount, &count); if (NS_FAILED(rv)) return rv; // Set the string's length according to the amount of data we've read. - // - // XXX You'd think that mBuf.SetLength() would do this, but it - // doesn't. It calls Truncate(), so you can't set the length to - // something longer. - mBuf.mLength = len + count; - AddNullTerminator(mBuf); + // Note: we know this to work on nsCString. This isn't guaranteed to + // work on other strings. + mBuf.SetLength(len + count); return ProcessData(aRequest, aCtxt); } @@ -393,7 +390,7 @@ nsDirIndexParser::ProcessData(nsIRequest *aRequest, nsISupports *aCtxt) { if (eol < 0) break; mBuf.SetCharAt(PRUnichar('\0'), eol); - const char *line = &mBuf.mStr[mLineStart]; + const char *line = mBuf.get() + mLineStart; PRInt32 lineLen = eol - mLineStart; mLineStart = eol + 1; diff --git a/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp b/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp index 8da989edb42..165611f5214 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLEntities.cpp @@ -182,7 +182,7 @@ nsHTMLEntities::EntityToUnicode(const nsCString& aEntity) if(';'==aEntity.Last()) { nsCAutoString temp(aEntity); - temp.Truncate(aEntity.mLength-1); + temp.Truncate(aEntity.Length()-1); return EntityToUnicode(temp); } diff --git a/mozilla/string/obsolete/nsStr.h b/mozilla/string/obsolete/nsStr.h index 3fb76fae389..1a5ff59686a 100644 --- a/mozilla/string/obsolete/nsStr.h +++ b/mozilla/string/obsolete/nsStr.h @@ -453,6 +453,7 @@ struct NS_COM nsStr { static void Print(const nsStr& aDest, FILE* out, PRBool truncate = PR_FALSE); #endif +protected: PRUint32 mLength; PRUint32 mCapacity; @@ -469,6 +470,11 @@ private: static PRBool Realloc(nsStr& aString,PRUint32 aCount); static PRBool Free(nsStr& aString); +public: + friend inline void AddNullTerminator(nsStr& aDest); + friend inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex); + friend class nsString; + friend class nsCString; }; diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index 0b83f00c816..db37021917f 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -83,6 +83,9 @@ class NS_COM nsCString : public nsAFlatCString, public nsStr { +public: + friend class nsString; + protected: virtual const nsBufferHandle* GetFlatBufferHandle() const; virtual const char* GetReadableFragment( nsReadableFragment&, nsFragmentRequest, PRUint32 ) const; @@ -490,6 +493,9 @@ class NS_COM NS_ConvertUCS2toUTF8 ... */ { + public: + friend NS_COM char* ToNewUTF8String( const nsAString& aSource ); + public: explicit NS_ConvertUCS2toUTF8( const PRUnichar* aString ) diff --git a/mozilla/string/obsolete/nsString2.h b/mozilla/string/obsolete/nsString2.h index c31f942fcb4..97ddf7e2889 100644 --- a/mozilla/string/obsolete/nsString2.h +++ b/mozilla/string/obsolete/nsString2.h @@ -83,6 +83,10 @@ class NS_COM nsString : public nsAFlatString, public nsStr { +public: + friend class nsCString; + friend class nsLinebreakConverter; + protected: virtual const nsBufferHandle* GetFlatBufferHandle() const; virtual const PRUnichar* GetReadableFragment( nsReadableFragment&, nsFragmentRequest, PRUint32 ) const; diff --git a/mozilla/widget/src/gtk/nsGtkIMEHelper.cpp b/mozilla/widget/src/gtk/nsGtkIMEHelper.cpp index aef4d3ccc84..9c12f25d7e5 100644 --- a/mozilla/widget/src/gtk/nsGtkIMEHelper.cpp +++ b/mozilla/widget/src/gtk/nsGtkIMEHelper.cpp @@ -203,9 +203,7 @@ void nsIMEPreedit::Reset() { mCaretPosition = 0; mIMECompUnicode->SetCapacity(0); - mIMECompUnicode->mLength = 0; mIMECompAttr->SetCapacity(0); - mIMECompAttr->mLength = 0; } PRUnichar* diff --git a/mozilla/widget/src/mac/nsMacEventHandler.cpp b/mozilla/widget/src/mac/nsMacEventHandler.cpp index 3d07fa73f30..a808589e044 100644 --- a/mozilla/widget/src/mac/nsMacEventHandler.cpp +++ b/mozilla/widget/src/mac/nsMacEventHandler.cpp @@ -1857,7 +1857,7 @@ nsresult nsMacEventHandler::HandleUpdateInputArea(char* text,Size text_size, Scr len = 0; err = ::ConvertFromTextToUnicode(textToUnicodeInfo,committedLen,text,kUnicodeLooseMappingsMask, 0,NULL,NULL,NULL, - mIMECompositionStr->mCapacity *sizeof(PRUnichar), + (text_size + 1) * sizeof(PRUnichar), &source_read,&len,NS_REINTERPRET_CAST(PRUint16*, ubuf)); NS_ASSERTION(err==noErr,"nsMacEventHandler::UpdateInputArea: ConvertFromTextToUnicode failed.\n"); if (err!=noErr) @@ -1877,7 +1877,7 @@ nsresult nsMacEventHandler::HandleUpdateInputArea(char* text,Size text_size, Scr } len = d; ubuf[len] = '\0'; // null terminate - mIMECompositionStr->mLength = len; + mIMECompositionStr->SetLength(len); // for committed text, set no highlight ? (Do we need to set CaretPosition here ??? ) #ifdef DEBUG_TSM printf("1.2====================================\n"); @@ -2006,7 +2006,7 @@ nsresult nsMacEventHandler::HandleUpdateInputArea(char* text,Size text_size, Scr // Note : The TEC will return -50 if sourceOffset[0,1] >= text_size-committedLen err = ::ConvertFromTextToUnicode(textToUnicodeInfo,text_size-committedLen,text+committedLen,kUnicodeLooseMappingsMask, destinationLength,sourceOffset,&destinationLength,destinationOffset, - mIMECompositionStr->mCapacity *sizeof(PRUnichar), + (text_size + 1) * sizeof(PRUnichar), &source_read,&len, NS_REINTERPRET_CAST(PRUint16*, ubuf)); NS_ASSERTION(err==noErr,"nsMacEventHandler::UpdateInputArea: ConvertFromTextToUnicode failed.\n"); if (err!=noErr) @@ -2094,8 +2094,7 @@ nsresult nsMacEventHandler::HandleUpdateInputArea(char* text,Size text_size, Scr //------------------------------------------------------------------------------------------------ // 2.2.3 null terminate the uncommitted text //------------------------------------------------------------------------------------------------ - ubuf[len] = '\0'; // null terminate // we convert the text in 2.2.2 ... - mIMECompositionStr->mLength = len; + mIMECompositionStr->SetLength(len); //------------------------------------------------------------------------------------------------ // 2.2.4 send the text event //------------------------------------------------------------------------------------------------ @@ -2116,8 +2115,7 @@ nsresult nsMacEventHandler::HandleUpdateInputArea(char* text,Size text_size, Scr // This is needed when we input some uncommitted text, and then delete all of them // When the last delete come, we will got a text_size = 0 and fixedLength = 0 // In that case, we need to send a text event to clean un the input hole.... - ubuf[0] = '\0'; // null terminate - mIMECompositionStr->mLength = 0; + mIMECompositionStr->SetLength(0); #ifdef DEBUG_TSM printf("3.====================================\n"); #endif diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 4eb4392c345..653e168d031 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -4748,9 +4748,8 @@ nsWindow::HandleTextEvent(HIMC hIMEContext,PRBool aCheckAttr) mIMECompString->get(), mIMECompString->Length(), (PRUnichar*)mIMECompUnicode->get(), - mIMECompUnicode->mCapacity); - ((PRUnichar*)mIMECompUnicode->get())[unicharSize] = (PRUnichar) 0; - mIMECompUnicode->mLength = unicharSize; + unicharSize+1); + mIMECompUnicode->SetLength(unicharSize); } // @@ -5053,19 +5052,17 @@ BOOL nsWindow::OnIMEComposition(LPARAM aGCS) mIMECompUnicode->SetCapacity((compStrLen / sizeof(WCHAR))+1); NS_IMM_GETCOMPOSITIONSTRINGW(hIMEContext, GCS_RESULTSTR, - (LPVOID)mIMECompUnicode->get(), (mIMECompString->mCapacity * sizeof(WCHAR)), compStrLen); + (LPVOID)mIMECompUnicode->get(), compStrLen, compStrLen); compStrLen = compStrLen / sizeof(WCHAR); - ((PRUnichar*)mIMECompUnicode->get())[compStrLen] = '\0'; - mIMECompUnicode->mLength = compStrLen; + mIMECompUnicode->SetLength(compStrLen); } else { NS_IMM_GETCOMPOSITIONSTRING(hIMEContext, GCS_RESULTSTR, NULL, 0, compStrLen); mIMECompString->SetCapacity(compStrLen+1); NS_IMM_GETCOMPOSITIONSTRING(hIMEContext, GCS_RESULTSTR, - (LPVOID)mIMECompString->get(), mIMECompString->mCapacity, compStrLen); - ((char*)mIMECompString->get())[compStrLen] = '\0'; - mIMECompString->mLength = compStrLen; + (LPVOID)mIMECompString->get(), compStrLen+1, compStrLen); + mIMECompString->SetLength(compStrLen); } #ifdef DEBUG_IME fprintf(stderr,"GCS_RESULTSTR compStrLen = %d\n", compStrLen); @@ -5191,10 +5188,9 @@ BOOL nsWindow::OnIMEComposition(LPARAM aGCS) NS_IMM_GETCOMPOSITIONSTRINGW(hIMEContext, GCS_COMPSTR, (LPVOID)mIMECompUnicode->get(), - (mIMECompUnicode->mCapacity * sizeof(WCHAR)), compStrLen); + compStrLen, compStrLen); compStrLen = compStrLen / sizeof(WCHAR); - ((PRUnichar*)mIMECompUnicode->get())[compStrLen] = '\0'; - mIMECompUnicode->mLength = compStrLen; + mIMECompUnicode->SetLength(compStrLen); } else { NS_IMM_GETCOMPOSITIONSTRING(hIMEContext, GCS_COMPSTR, NULL, 0, compStrLen); mIMECompString->SetCapacity(compStrLen+1); @@ -5202,9 +5198,8 @@ BOOL nsWindow::OnIMEComposition(LPARAM aGCS) NS_IMM_GETCOMPOSITIONSTRING(hIMEContext, GCS_COMPSTR, (char*)mIMECompString->get(), - mIMECompString->mCapacity, compStrLen); - ((char*)mIMECompString->get())[compStrLen] = '\0'; - mIMECompString->mLength = compStrLen; + compStrLen+1, compStrLen); + mIMECompString->SetLength(compStrLen); } #ifdef DEBUG_IME fprintf(stderr,"GCS_COMPSTR compStrLen = %d\n", compStrLen); @@ -5212,7 +5207,7 @@ BOOL nsWindow::OnIMEComposition(LPARAM aGCS) #ifdef DEBUG for(int kk=0;kkmLength : mIMECompString->mLength), "illegal pos"); + NS_ASSERTION(mIMECompClauseString[kk] <= (nsToolkit::mIsNT ? mIMECompUnicode->Length() : mIMECompString->Length()), "illegal pos"); } #endif //-------------------------------------------------------- @@ -5230,11 +5225,9 @@ BOOL nsWindow::OnIMEComposition(LPARAM aGCS) HandleStartComposition(hIMEContext); if (nsToolkit::mIsNT) { - ((PRUnichar*)mIMECompUnicode->get())[0] = '\0'; - mIMECompUnicode->mLength = 0; + mIMECompUnicode->Truncate(); } else { - ((char*)mIMECompString->get())[0] = '\0'; - mIMECompString->mLength = 0; + mIMECompString->Truncate(); } HandleTextEvent(hIMEContext,PR_FALSE); result = PR_TRUE; @@ -5276,11 +5269,9 @@ BOOL nsWindow::OnIMEEndComposition() // we need to clear out the current composition string // in that case. if (nsToolkit::mIsNT) { - ((PRUnichar*)mIMECompUnicode->get())[0] = '\0'; - mIMECompUnicode->mLength = 0; + mIMECompUnicode->Truncate(0); } else { - ((char*)mIMECompString->get())[0] = '\0'; - mIMECompString->mLength = 0; + mIMECompString->Truncate(0); } HandleTextEvent(hIMEContext, PR_FALSE); diff --git a/mozilla/xpcom/string/obsolete/nsStr.h b/mozilla/xpcom/string/obsolete/nsStr.h index 3fb76fae389..1a5ff59686a 100644 --- a/mozilla/xpcom/string/obsolete/nsStr.h +++ b/mozilla/xpcom/string/obsolete/nsStr.h @@ -453,6 +453,7 @@ struct NS_COM nsStr { static void Print(const nsStr& aDest, FILE* out, PRBool truncate = PR_FALSE); #endif +protected: PRUint32 mLength; PRUint32 mCapacity; @@ -469,6 +470,11 @@ private: static PRBool Realloc(nsStr& aString,PRUint32 aCount); static PRBool Free(nsStr& aString); +public: + friend inline void AddNullTerminator(nsStr& aDest); + friend inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex); + friend class nsString; + friend class nsCString; }; diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index 0b83f00c816..db37021917f 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -83,6 +83,9 @@ class NS_COM nsCString : public nsAFlatCString, public nsStr { +public: + friend class nsString; + protected: virtual const nsBufferHandle* GetFlatBufferHandle() const; virtual const char* GetReadableFragment( nsReadableFragment&, nsFragmentRequest, PRUint32 ) const; @@ -490,6 +493,9 @@ class NS_COM NS_ConvertUCS2toUTF8 ... */ { + public: + friend NS_COM char* ToNewUTF8String( const nsAString& aSource ); + public: explicit NS_ConvertUCS2toUTF8( const PRUnichar* aString ) diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index c31f942fcb4..97ddf7e2889 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -83,6 +83,10 @@ class NS_COM nsString : public nsAFlatString, public nsStr { +public: + friend class nsCString; + friend class nsLinebreakConverter; + protected: virtual const nsBufferHandle* GetFlatBufferHandle() const; virtual const PRUnichar* GetReadableFragment( nsReadableFragment&, nsFragmentRequest, PRUint32 ) const; diff --git a/mozilla/xpinstall/src/nsInstallFile.cpp b/mozilla/xpinstall/src/nsInstallFile.cpp index 9822ef88759..90354cf9e95 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -114,7 +114,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, nsString subString; location = inPartialPath.FindChar('/',PR_FALSE, offset); - if (location == ((PRInt32)inPartialPath.mLength - 1)) //trailing slash + if (location == ((PRInt32)inPartialPath.Length() - 1)) //trailing slash { *error = nsInstall::INVALID_ARGUMENTS; return; @@ -124,7 +124,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, { if (location == kNotFound) //no separators were found { - nodeLength = inPartialPath.mLength - offset; + nodeLength = inPartialPath.Length() - offset; finished = PR_TRUE; } else