diff --git a/mozilla/content/base/src/nsContentAreaDragDrop.cpp b/mozilla/content/base/src/nsContentAreaDragDrop.cpp index fb6bf819dfb..4d851169022 100644 --- a/mozilla/content/base/src/nsContentAreaDragDrop.cpp +++ b/mozilla/content/base/src/nsContentAreaDragDrop.cpp @@ -307,7 +307,7 @@ nsContentAreaDragDrop::ExtractURLFromData(const nsACString & inFlavor, nsISuppor stringData->GetData(getter_Copies(data)); PRInt32 separator = data.FindChar('\n'); if ( separator >= 0 ) - data.Left(outURL, separator); + outURL = Substring(data, 0, separator); else outURL = data; } diff --git a/mozilla/content/base/src/nsHTMLContentSerializer.cpp b/mozilla/content/base/src/nsHTMLContentSerializer.cpp index bbc4843131e..0eb9b35621e 100644 --- a/mozilla/content/base/src/nsHTMLContentSerializer.cpp +++ b/mozilla/content/base/src/nsHTMLContentSerializer.cpp @@ -43,6 +43,7 @@ #include "nsIDocument.h" #include "nsINameSpaceManager.h" #include "nsString.h" +#include "nsUnicharUtils.h" #include "nsXPIDLString.h" #include "nsParserCIID.h" #include "nsIServiceManager.h" @@ -212,9 +213,8 @@ nsHTMLContentSerializer::IsJavaScript(nsIAtom* aAttrNameAtom, const nsAString& a // this is covered in bug #59604 static const char kJavaScript[] = "javascript"; PRInt32 pos = aValueString.FindChar(':'); - nsAutoString scheme; + const nsAutoString scheme(Substring(aValueString, 0, pos)); if ((pos == (PRInt32)(sizeof kJavaScript - 1)) && - (aValueString.Left(scheme, pos) != -1) && scheme.EqualsIgnoreCase(kJavaScript)) return PR_TRUE; else @@ -278,7 +278,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI // Loop and escape parts by avoiding escaping reserved characters (and '%', '#' ). while ((end = uri.FindCharInSet("%#;/?:@&=+$,", start)) != -1) { - aURI.Mid(part, start, (end-start)); + part = Substring(aURI, start, (end-start)); if (textToSubURI && !part.IsASCII()) { rv = textToSubURI->ConvertAndEscape(documentCharset, part.get(), getter_Copies(escapedURI)); NS_ENSURE_SUCCESS(rv, rv); @@ -289,14 +289,14 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI aEscapedURI.Append(NS_ConvertASCIItoUCS2(escapedURI)); // Append a reserved character without escaping. - aURI.Mid(part, end, 1); + part = Substring(aURI, end, 1); aEscapedURI.Append(part); start = end + 1; } if (start < (PRInt32) aURI.Length()) { // Escape the remaining part. - aURI.Mid(part, start, aURI.Length()-start); + part = Substring(aURI, start, aURI.Length()-start); if (textToSubURI) { rv = textToSubURI->ConvertAndEscape(documentCharset, part.get(), getter_Copies(escapedURI)); NS_ENSURE_SUCCESS(rv, rv); @@ -681,7 +681,7 @@ nsHTMLContentSerializer::AppendToStringWrapped(const nsAString& aStr, } else { lineLength = length - strOffset; - aStr.Right(line, lineLength); + line = Substring(aStr, strOffset, lineLength); AppendToString(line, aOutputStr, aTranslateEntities); } done = PR_TRUE; @@ -690,7 +690,7 @@ nsHTMLContentSerializer::AppendToStringWrapped(const nsAString& aStr, // Add the part of the current old line that's part of the // new line lineLength = indx - strOffset; - aStr.Mid(line, strOffset, lineLength); + line = Substring(aStr, strOffset, lineLength); AppendToString(line, aOutputStr, aTranslateEntities); // if we've reached the end of an old line, don't add the diff --git a/mozilla/content/base/src/nsParserUtils.cpp b/mozilla/content/base/src/nsParserUtils.cpp index 7e4db721247..21472bbd2c6 100644 --- a/mozilla/content/base/src/nsParserUtils.cpp +++ b/mozilla/content/base/src/nsParserUtils.cpp @@ -148,8 +148,9 @@ nsParserUtils::SplitMimeType(const nsAString& aValue, nsString& aType, aParams.Truncate(); PRInt32 semiIndex = aValue.FindChar(PRUnichar(';')); if (-1 != semiIndex) { - aValue.Left(aType, semiIndex); - aValue.Right(aParams, (aValue.Length() - semiIndex) - 1); + aType = Substring(aValue, 0, semiIndex); + aParams = Substring(aValue, semiIndex + 1, + aValue.Length() - (semiIndex + 1)); aParams.StripWhitespace(); } else { diff --git a/mozilla/content/base/src/nsPlainTextSerializer.cpp b/mozilla/content/base/src/nsPlainTextSerializer.cpp index 385a4c470fd..1b64be77538 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.cpp +++ b/mozilla/content/base/src/nsPlainTextSerializer.cpp @@ -1556,8 +1556,7 @@ nsPlainTextSerializer::Write(const nsAString& aString) // Done searching if(newline == kNotFound) { // No new lines. - nsAutoString stringpart; - aString.Right(stringpart, totLen-bol); + nsAutoString stringpart(Substring(aString, bol, totLen - bol)); if(!stringpart.IsEmpty()) { PRUnichar lastchar = stringpart[stringpart.Length()-1]; if((lastchar == '\t') || (lastchar == ' ') || @@ -1575,8 +1574,7 @@ nsPlainTextSerializer::Write(const nsAString& aString) } else { // There is a newline - nsAutoString stringpart; - aString.Mid(stringpart, bol, newline-bol); + nsAutoString stringpart(Substring(aString, bol, newline-bol)); mInWhitespace = PR_TRUE; Output(stringpart); // and write the newline diff --git a/mozilla/content/xml/document/src/nsFIXptr.cpp b/mozilla/content/xml/document/src/nsFIXptr.cpp index 2e14ac4a0df..1fb07ffb0cd 100644 --- a/mozilla/content/xml/document/src/nsFIXptr.cpp +++ b/mozilla/content/xml/document/src/nsFIXptr.cpp @@ -300,9 +300,9 @@ nsFIXptr::Evaluate(nsIDOMDocument *aDocument, nsAutoString expr1, expr2; nsCOMPtr range1, range2; - aExpression.Left(expr1, split); - aExpression.Mid(expr2, split + 1, aExpression.Length()); - + expr1 = Substring(aExpression, 0, split); + expr2 = Substring(aExpression, split + 1, + aExpression.Length() - (split + 1)); rv = GetRange(aDocument, expr1, getter_AddRefs(range1)); if (!range1) return rv; diff --git a/mozilla/content/xul/templates/src/nsXULContentUtils.cpp b/mozilla/content/xul/templates/src/nsXULContentUtils.cpp index 001f07442f0..e6b6dfc1f10 100644 --- a/mozilla/content/xul/templates/src/nsXULContentUtils.cpp +++ b/mozilla/content/xul/templates/src/nsXULContentUtils.cpp @@ -438,7 +438,7 @@ nsXULContentUtils::MakeElementID(nsIDocument* aDocument, const nsAString& aURI, static const PRInt32 kFudge = 0; #endif PRInt32 len = spec.Length(); - aURI.Right(aElementID, aURI.Length() - (len + kFudge)); + aElementID = Substring(aURI, len + kFudge, aURI.Length() - (len + kFudge)); } else { aElementID = aURI; diff --git a/mozilla/editor/libeditor/html/nsHTMLCSSUtils.cpp b/mozilla/editor/libeditor/html/nsHTMLCSSUtils.cpp index b5d9eab81ea..c2c6570b5d3 100644 --- a/mozilla/editor/libeditor/html/nsHTMLCSSUtils.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLCSSUtils.cpp @@ -740,7 +740,7 @@ nsHTMLCSSUtils::ParseLength(const nsAString & aString, float * aValue, nsIAtom * iter++; i++; } - aString.Right(unit, j-i); + unit = Substring(aString, aString.Length() - (j-i), j-i); *aValue = value * sign; *aUnit = NS_NewAtom(unit); } @@ -1164,15 +1164,13 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, } else if (nsIEditProperty::tt == aHTMLProperty) { - nsAutoString val; - valueString.Left(val, 9); - aIsSet = PRBool(val.Equals(NS_LITERAL_STRING("monospace"))); + aIsSet = Substring(valueString, 0, 9).Equals(NS_LITERAL_STRING("monospace")); } else if ((nsIEditProperty::font == aHTMLProperty) && aHTMLAttribute && aHTMLAttribute->Equals(NS_LITERAL_STRING("face"))) { nsAutoString leftCSSValue; - valueString.Left(leftCSSValue, 5); + leftCSSValue = Substring(valueString, 0, 5); ToLowerCase(leftCSSValue); if (!htmlValueString.Equals(NS_LITERAL_STRING(""))) { nsAutoString leftHTMLValue; diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp index 2f137a5c843..08be613b5e9 100644 --- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -1728,8 +1728,8 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(nsIDOMNSRange *aNSRange, { PRInt32 err, sep; sep = aInfoStr.FindChar((PRUnichar)','); - aInfoStr.Left(numstr1, sep); - aInfoStr.Right(numstr2, aInfoStr.Length() - (sep+1)); + numstr1 = Substring(aInfoStr, 0, sep); + numstr2 = Substring(aInfoStr, sep+1, aInfoStr.Length() - (sep+1)); *outRangeStartHint = numstr1.ToInteger(&err) + contextDepth; *outRangeEndHint = numstr2.ToInteger(&err) + contextDepth; } diff --git a/mozilla/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp b/mozilla/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp index a98e8610720..9febb0ad0c4 100644 --- a/mozilla/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp +++ b/mozilla/extensions/webservices/soap/src/nsDefaultSOAPEncoder.cpp @@ -2419,7 +2419,7 @@ static PRUint32 DecodeArrayDimensions(const nsAString& src, PRInt32* aDimensionS ; if (*i2 != ']') { // In this case, not an array dimension PRInt32 len = Distance(i1, i2) - 1; // This is the size to truncate to at the end. - src.Left(dst, len); // Truncate the string. + dst = Substring(src, 0, len); // Truncate the string. return 0; // Eliminated white space. } @@ -2490,7 +2490,7 @@ static PRUint32 DecodeArrayDimensions(const nsAString& src, PRInt32* aDimensionS } } } - src.Left(dst, len); // Truncate the string. + dst = Substring(dst, 0, len); // Truncate the string. return dimensionCount + 1; // Return the number of dimensions } diff --git a/mozilla/extensions/webservices/soap/src/nsSOAPUtils.cpp b/mozilla/extensions/webservices/soap/src/nsSOAPUtils.cpp index b81b73af0a6..dc359019211 100644 --- a/mozilla/extensions/webservices/soap/src/nsSOAPUtils.cpp +++ b/mozilla/extensions/webservices/soap/src/nsSOAPUtils.cpp @@ -344,7 +344,7 @@ nsresult return NS_OK; } nsAutoString prefix; - aQName.Left(prefix, i); + prefix = Substring(aQName, 0, i); nsAutoString result; if (prefix.Equals(kXMLPrefix)) { @@ -396,7 +396,7 @@ nsresult if (i < 0) aLocalName = aQName; else - aQName.Mid(aLocalName, i + 1, aQName.Length() - i); + aLocalName = Substring(aLocalName, i+1, aQName.Length() - (i+1)); return NS_OK; } diff --git a/mozilla/extensions/xmlextras/pointers/src/nsFIXptr.cpp b/mozilla/extensions/xmlextras/pointers/src/nsFIXptr.cpp index 2e14ac4a0df..1fb07ffb0cd 100644 --- a/mozilla/extensions/xmlextras/pointers/src/nsFIXptr.cpp +++ b/mozilla/extensions/xmlextras/pointers/src/nsFIXptr.cpp @@ -300,9 +300,9 @@ nsFIXptr::Evaluate(nsIDOMDocument *aDocument, nsAutoString expr1, expr2; nsCOMPtr range1, range2; - aExpression.Left(expr1, split); - aExpression.Mid(expr2, split + 1, aExpression.Length()); - + expr1 = Substring(aExpression, 0, split); + expr2 = Substring(aExpression, split + 1, + aExpression.Length() - (split + 1)); rv = GetRange(aDocument, expr1, getter_AddRefs(range1)); if (!range1) return rv; diff --git a/mozilla/extensions/xmlextras/soap/src/nsDefaultSOAPEncoder.cpp b/mozilla/extensions/xmlextras/soap/src/nsDefaultSOAPEncoder.cpp index a98e8610720..9febb0ad0c4 100644 --- a/mozilla/extensions/xmlextras/soap/src/nsDefaultSOAPEncoder.cpp +++ b/mozilla/extensions/xmlextras/soap/src/nsDefaultSOAPEncoder.cpp @@ -2419,7 +2419,7 @@ static PRUint32 DecodeArrayDimensions(const nsAString& src, PRInt32* aDimensionS ; if (*i2 != ']') { // In this case, not an array dimension PRInt32 len = Distance(i1, i2) - 1; // This is the size to truncate to at the end. - src.Left(dst, len); // Truncate the string. + dst = Substring(src, 0, len); // Truncate the string. return 0; // Eliminated white space. } @@ -2490,7 +2490,7 @@ static PRUint32 DecodeArrayDimensions(const nsAString& src, PRInt32* aDimensionS } } } - src.Left(dst, len); // Truncate the string. + dst = Substring(dst, 0, len); // Truncate the string. return dimensionCount + 1; // Return the number of dimensions } diff --git a/mozilla/extensions/xmlextras/soap/src/nsSOAPUtils.cpp b/mozilla/extensions/xmlextras/soap/src/nsSOAPUtils.cpp index b81b73af0a6..dc359019211 100644 --- a/mozilla/extensions/xmlextras/soap/src/nsSOAPUtils.cpp +++ b/mozilla/extensions/xmlextras/soap/src/nsSOAPUtils.cpp @@ -344,7 +344,7 @@ nsresult return NS_OK; } nsAutoString prefix; - aQName.Left(prefix, i); + prefix = Substring(aQName, 0, i); nsAutoString result; if (prefix.Equals(kXMLPrefix)) { @@ -396,7 +396,7 @@ nsresult if (i < 0) aLocalName = aQName; else - aQName.Mid(aLocalName, i + 1, aQName.Length() - i); + aLocalName = Substring(aLocalName, i+1, aQName.Length() - (i+1)); return NS_OK; } diff --git a/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp b/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp index 23bff51dc8b..b2eeba992b5 100644 --- a/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp +++ b/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp @@ -962,12 +962,10 @@ nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, // nat PromiseFlatCString(aFontDirName).get())); return PR_FALSE; } - nsCAutoString font_dir_name_tail; - nsCAutoString parent_dir; - aFontDirName.Left(parent_dir, last_slash); int right_len = aFontDirName.Length() - last_slash - 1; - aFontDirName.Right(font_dir_name_tail, right_len); - + nsCAutoString parent_dir(Substring(aFontDirName, 0, last_slash)); + nsCAutoString font_dir_name_tail(Substring(aFontDirName, + last_slash+1, right_len)); // // Get the parent dir's device and inode // diff --git a/mozilla/gfx/src/nsNameValuePairDB.cpp b/mozilla/gfx/src/nsNameValuePairDB.cpp index 0e4af63bec6..c1fabc971d9 100644 --- a/mozilla/gfx/src/nsNameValuePairDB.cpp +++ b/mozilla/gfx/src/nsNameValuePairDB.cpp @@ -521,7 +521,8 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) // // Rename the tmp to current // - current_name.Right(current_name_tail, current_name.Length() - last_slash - 1); + current_name_tail = Substring(current_name, last_slash+1, + current_name.Length() - (last_slash + 1)); rv = tmp_file->MoveToNative(dir, current_name_tail); if (NS_FAILED(rv)) goto Rename_Error; diff --git a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp index 23bff51dc8b..b2eeba992b5 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp +++ b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp @@ -962,12 +962,10 @@ nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, // nat PromiseFlatCString(aFontDirName).get())); return PR_FALSE; } - nsCAutoString font_dir_name_tail; - nsCAutoString parent_dir; - aFontDirName.Left(parent_dir, last_slash); int right_len = aFontDirName.Length() - last_slash - 1; - aFontDirName.Right(font_dir_name_tail, right_len); - + nsCAutoString parent_dir(Substring(aFontDirName, 0, last_slash)); + nsCAutoString font_dir_name_tail(Substring(aFontDirName, + last_slash+1, right_len)); // // Get the parent dir's device and inode // diff --git a/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp b/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp index 0e4af63bec6..c1fabc971d9 100644 --- a/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp +++ b/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp @@ -521,7 +521,8 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) // // Rename the tmp to current // - current_name.Right(current_name_tail, current_name.Length() - last_slash - 1); + current_name_tail = Substring(current_name, last_slash+1, + current_name.Length() - (last_slash + 1)); rv = tmp_file->MoveToNative(dir, current_name_tail); if (NS_FAILED(rv)) goto Rename_Error; diff --git a/mozilla/htmlparser/src/nsDTDUtils.h b/mozilla/htmlparser/src/nsDTDUtils.h index 7d4ede429b4..31f6e7c2870 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.h +++ b/mozilla/htmlparser/src/nsDTDUtils.h @@ -239,7 +239,7 @@ public: PRUnichar theLast=aName.Last(); PRInt32 theLen=aName.Length(); if((2 EXTENSION_LENGTH) { - nsCAutoString extension; - leafName.Right(extension, EXTENSION_LENGTH); + nsCAutoString extension(Substring(leafName, leafName.Length() - EXTENSION_LENGTH, EXTENSION_LENGTH)); // treat .TXT, .Tab, .csV like .txt, .tab, and .csv ToLowerCase(extension); diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.h b/mozilla/parser/htmlparser/src/nsDTDUtils.h index 7d4ede429b4..31f6e7c2870 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.h +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.h @@ -239,7 +239,7 @@ public: PRUnichar theLast=aName.Last(); PRInt32 theLen=aName.Length(); if((2= Length() ) + aResult = *this; + else + aResult = Substring(*this, aStartPos, aLengthToCopy); + + return aResult.Length(); + } + + /********************************************************************** Searching methods... *********************************************************************/ diff --git a/mozilla/string/obsolete/nsString.h b/mozilla/string/obsolete/nsString.h index 3b98561128f..009fb3779ba 100644 --- a/mozilla/string/obsolete/nsString.h +++ b/mozilla/string/obsolete/nsString.h @@ -249,6 +249,28 @@ public: // Takes ownership of aPtr, sets the current length to aLength if specified. void Adopt( char* aPtr, PRInt32 aLength = -1 ); + /* + |Left|, |Mid|, and |Right| are annoying signatures that seem better almost + any _other_ way than they are now. Consider these alternatives + + aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| + aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| + Left(aReadable, 17, aWritable); // ...a global function that does the assignment + + as opposed to the current signature + + aReadable.Left(aWritable, 17); // ...a member function that does the assignment + + or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality + + aWritable = Substring(aReadable, 0, 17); + */ + + size_type Left( self_type&, size_type ) const; + size_type Mid( self_type&, PRUint32, PRUint32 ) const; + size_type Right( self_type&, size_type ) const; + + /********************************************************************** Searching methods... *********************************************************************/ @@ -355,6 +377,22 @@ private: void InsertWithConversion( char, PRUint32 ); }; +inline +nsCString::size_type +nsCString::Left( nsACString& aResult, size_type aLengthToCopy ) const + { + return Mid(aResult, 0, aLengthToCopy); + } + +inline +nsCString::size_type +nsCString::Right( self_type& aResult, size_type aLengthToCopy ) const + { + size_type myLength = Length(); + aLengthToCopy = NS_MIN(myLength, aLengthToCopy); + return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); + } + // NS_DEF_STRING_COMPARISON_OPERATORS(nsCString, char) // NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCString, char) diff --git a/mozilla/string/obsolete/nsString2.cpp b/mozilla/string/obsolete/nsString2.cpp index 79bbfbe769b..dc0ebc3b747 100644 --- a/mozilla/string/obsolete/nsString2.cpp +++ b/mozilla/string/obsolete/nsString2.cpp @@ -829,6 +829,18 @@ void nsString::Adopt(PRUnichar* aPtr, PRInt32 aLength) { nsStrPrivate::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE); } +nsAString::size_type +nsString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const + { + // If we're just assigning our entire self, give |aResult| the opportunity to share + if ( aStartPos == 0 && aLengthToCopy >= Length() ) + aResult = *this; + else + aResult = Substring(*this, aStartPos, aLengthToCopy); + + return aResult.Length(); + } + /********************************************************************** Searching methods... diff --git a/mozilla/string/obsolete/nsString2.h b/mozilla/string/obsolete/nsString2.h index 1b791106941..49a27544f84 100644 --- a/mozilla/string/obsolete/nsString2.h +++ b/mozilla/string/obsolete/nsString2.h @@ -303,6 +303,27 @@ public: // Takes ownership of aPtr, sets the current length to aLength if specified. void Adopt( PRUnichar* aPtr, PRInt32 aLength = -1 ); + /* + |Left|, |Mid|, and |Right| are annoying signatures that seem better almost + any _other_ way than they are now. Consider these alternatives + + aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| + aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| + Left(aReadable, 17, aWritable); // ...a global function that does the assignment + + as opposed to the current signature + + aReadable.Left(aWritable, 17); // ...a member function that does the assignment + + or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality + + aWritable = Substring(aReadable, 0, 17); + */ + + size_type Left( self_type&, size_type ) const; + size_type Mid( self_type&, PRUint32, PRUint32 ) const; + size_type Right( self_type&, size_type ) const; + /********************************************************************** Searching methods... *********************************************************************/ @@ -426,6 +447,22 @@ private: void InsertWithConversion( const PRUnichar*, PRUint32, PRInt32=-1 ); }; +inline +nsString::size_type +nsString::Left( nsAString& aResult, size_type aLengthToCopy ) const + { + return Mid(aResult, 0, aLengthToCopy); + } + +inline +nsString::size_type +nsString::Right( self_type& aResult, size_type aLengthToCopy ) const + { + size_type myLength = Length(); + aLengthToCopy = NS_MIN(myLength, aLengthToCopy); + return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); + } + // NS_DEF_STRING_COMPARISON_OPERATORS(nsString, PRUnichar) // NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsString, PRUnichar) diff --git a/mozilla/string/public/nsAString.h b/mozilla/string/public/nsAString.h index 46d83f19b84..d5d46816f8d 100644 --- a/mozilla/string/public/nsAString.h +++ b/mozilla/string/public/nsAString.h @@ -166,26 +166,6 @@ class NS_COM nsAString size_type CountChar( char_type ) const; - /* - |Left|, |Mid|, and |Right| are annoying signatures that seem better almost - any _other_ way than they are now. Consider these alternatives - - aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| - aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| - Left(aReadable, 17, aWritable); // ...a global function that does the assignment - - as opposed to the current signature - - aReadable.Left(aWritable, 17); // ...a member function that does the assignment - - or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality - - aWritable = Substring(aReadable, 0, 17); - */ - - size_type Left( self_type&, size_type ) const; - size_type Mid( self_type&, PRUint32, PRUint32 ) const; - size_type Right( self_type&, size_type ) const; // Find( ... ) const; PRInt32 FindChar( char_type, index_type aOffset = 0 ) const; @@ -441,27 +421,6 @@ class NS_COM nsACString size_type CountChar( char_type ) const; - /* - |Left|, |Mid|, and |Right| are annoying signatures that seem better almost - any _other_ way than they are now. Consider these alternatives - - aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| - aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| - Left(aReadable, 17, aWritable); // ...a global function that does the assignment - - as opposed to the current signature - - aReadable.Left(aWritable, 17); // ...a member function that does the assignment - - or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality - - aWritable = Substring(aReadable, 0, 17); - */ - - size_type Left( self_type&, size_type ) const; - size_type Mid( self_type&, PRUint32, PRUint32 ) const; - size_type Right( self_type&, size_type ) const; - // Find( ... ) const; PRInt32 FindChar( char_type, index_type aOffset = 0 ) const; // FindCharInSet( ... ) const; @@ -779,13 +738,6 @@ operator> ( const nsAString& lhs, const nsAString& rhs ) return Compare(lhs, rhs)> 0; } -inline -nsAString::size_type -nsAString::Left( nsAString& aResult, size_type aLengthToCopy ) const - { - return Mid(aResult, 0, aLengthToCopy); - } - /** * @@ -896,13 +848,6 @@ operator> ( const nsACString& lhs, const nsACString& rhs ) return Compare(lhs, rhs)> 0; } -inline -nsACString::size_type -nsACString::Left( nsACString& aResult, size_type aLengthToCopy ) const - { - return Mid(aResult, 0, aLengthToCopy); - } - // Once you've got strings, you shouldn't need to do anything else to have concatenation #ifndef nsDependentConcatenation_h___ #include "nsDependentConcatenation.h" diff --git a/mozilla/string/src/nsAString.cpp b/mozilla/string/src/nsAString.cpp index 133ec000cfb..d7ce306228b 100644 --- a/mozilla/string/src/nsAString.cpp +++ b/mozilla/string/src/nsAString.cpp @@ -183,26 +183,6 @@ nsAString::CountChar( char_type c ) const return 0; } -nsAString::size_type -nsAString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const - { - // If we're just assigning our entire self, give |aResult| the opportunity to share - if ( aStartPos == 0 && aLengthToCopy >= Length() ) - aResult = *this; - else - aResult = Substring(*this, aStartPos, aLengthToCopy); - - return aResult.Length(); - } - -nsAString::size_type -nsAString::Right( self_type& aResult, size_type aLengthToCopy ) const - { - size_type myLength = Length(); - aLengthToCopy = NS_MIN(myLength, aLengthToCopy); - return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); - } - PRInt32 nsAString::FindChar( char_type aChar, PRUint32 aOffset ) const { @@ -702,26 +682,6 @@ nsACString::CountChar( char_type c ) const return 0; } -nsACString::size_type -nsACString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const - { - // If we're just assigning our entire self, give |aResult| the opportunity to share - if ( aStartPos == 0 && aLengthToCopy >= Length() ) - aResult = *this; - else - aResult = Substring(*this, aStartPos, aLengthToCopy); - - return aResult.Length(); - } - -nsACString::size_type -nsACString::Right( self_type& aResult, size_type aLengthToCopy ) const - { - size_type myLength = Length(); - aLengthToCopy = NS_MIN(myLength, aLengthToCopy); - return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); - } - PRInt32 nsACString::FindChar( char_type aChar, PRUint32 aOffset ) const { diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index 808ea3e4a00..57241895a91 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -776,6 +776,19 @@ void nsCString::Adopt(char* aPtr, PRInt32 aLength) { nsStrPrivate::Initialize(*this, aPtr, aLength, aLength, eOneByte, PR_TRUE); } +nsCString::size_type +nsCString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const + { + // If we're just assigning our entire self, give |aResult| the opportunity to share + if ( aStartPos == 0 && aLengthToCopy >= Length() ) + aResult = *this; + else + aResult = Substring(*this, aStartPos, aLengthToCopy); + + return aResult.Length(); + } + + /********************************************************************** Searching methods... *********************************************************************/ diff --git a/mozilla/xpcom/string/obsolete/nsString.h b/mozilla/xpcom/string/obsolete/nsString.h index 3b98561128f..009fb3779ba 100644 --- a/mozilla/xpcom/string/obsolete/nsString.h +++ b/mozilla/xpcom/string/obsolete/nsString.h @@ -249,6 +249,28 @@ public: // Takes ownership of aPtr, sets the current length to aLength if specified. void Adopt( char* aPtr, PRInt32 aLength = -1 ); + /* + |Left|, |Mid|, and |Right| are annoying signatures that seem better almost + any _other_ way than they are now. Consider these alternatives + + aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| + aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| + Left(aReadable, 17, aWritable); // ...a global function that does the assignment + + as opposed to the current signature + + aReadable.Left(aWritable, 17); // ...a member function that does the assignment + + or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality + + aWritable = Substring(aReadable, 0, 17); + */ + + size_type Left( self_type&, size_type ) const; + size_type Mid( self_type&, PRUint32, PRUint32 ) const; + size_type Right( self_type&, size_type ) const; + + /********************************************************************** Searching methods... *********************************************************************/ @@ -355,6 +377,22 @@ private: void InsertWithConversion( char, PRUint32 ); }; +inline +nsCString::size_type +nsCString::Left( nsACString& aResult, size_type aLengthToCopy ) const + { + return Mid(aResult, 0, aLengthToCopy); + } + +inline +nsCString::size_type +nsCString::Right( self_type& aResult, size_type aLengthToCopy ) const + { + size_type myLength = Length(); + aLengthToCopy = NS_MIN(myLength, aLengthToCopy); + return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); + } + // NS_DEF_STRING_COMPARISON_OPERATORS(nsCString, char) // NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsCString, char) diff --git a/mozilla/xpcom/string/obsolete/nsString2.cpp b/mozilla/xpcom/string/obsolete/nsString2.cpp index 79bbfbe769b..dc0ebc3b747 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.cpp +++ b/mozilla/xpcom/string/obsolete/nsString2.cpp @@ -829,6 +829,18 @@ void nsString::Adopt(PRUnichar* aPtr, PRInt32 aLength) { nsStrPrivate::Initialize(*this, (char*)aPtr, aLength, aLength, eTwoByte, PR_TRUE); } +nsAString::size_type +nsString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const + { + // If we're just assigning our entire self, give |aResult| the opportunity to share + if ( aStartPos == 0 && aLengthToCopy >= Length() ) + aResult = *this; + else + aResult = Substring(*this, aStartPos, aLengthToCopy); + + return aResult.Length(); + } + /********************************************************************** Searching methods... diff --git a/mozilla/xpcom/string/obsolete/nsString2.h b/mozilla/xpcom/string/obsolete/nsString2.h index 1b791106941..49a27544f84 100644 --- a/mozilla/xpcom/string/obsolete/nsString2.h +++ b/mozilla/xpcom/string/obsolete/nsString2.h @@ -303,6 +303,27 @@ public: // Takes ownership of aPtr, sets the current length to aLength if specified. void Adopt( PRUnichar* aPtr, PRInt32 aLength = -1 ); + /* + |Left|, |Mid|, and |Right| are annoying signatures that seem better almost + any _other_ way than they are now. Consider these alternatives + + aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| + aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| + Left(aReadable, 17, aWritable); // ...a global function that does the assignment + + as opposed to the current signature + + aReadable.Left(aWritable, 17); // ...a member function that does the assignment + + or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality + + aWritable = Substring(aReadable, 0, 17); + */ + + size_type Left( self_type&, size_type ) const; + size_type Mid( self_type&, PRUint32, PRUint32 ) const; + size_type Right( self_type&, size_type ) const; + /********************************************************************** Searching methods... *********************************************************************/ @@ -426,6 +447,22 @@ private: void InsertWithConversion( const PRUnichar*, PRUint32, PRInt32=-1 ); }; +inline +nsString::size_type +nsString::Left( nsAString& aResult, size_type aLengthToCopy ) const + { + return Mid(aResult, 0, aLengthToCopy); + } + +inline +nsString::size_type +nsString::Right( self_type& aResult, size_type aLengthToCopy ) const + { + size_type myLength = Length(); + aLengthToCopy = NS_MIN(myLength, aLengthToCopy); + return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); + } + // NS_DEF_STRING_COMPARISON_OPERATORS(nsString, PRUnichar) // NS_DEF_DERIVED_STRING_OPERATOR_PLUS(nsString, PRUnichar) diff --git a/mozilla/xpcom/string/public/nsAString.h b/mozilla/xpcom/string/public/nsAString.h index 46d83f19b84..d5d46816f8d 100644 --- a/mozilla/xpcom/string/public/nsAString.h +++ b/mozilla/xpcom/string/public/nsAString.h @@ -166,26 +166,6 @@ class NS_COM nsAString size_type CountChar( char_type ) const; - /* - |Left|, |Mid|, and |Right| are annoying signatures that seem better almost - any _other_ way than they are now. Consider these alternatives - - aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| - aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| - Left(aReadable, 17, aWritable); // ...a global function that does the assignment - - as opposed to the current signature - - aReadable.Left(aWritable, 17); // ...a member function that does the assignment - - or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality - - aWritable = Substring(aReadable, 0, 17); - */ - - size_type Left( self_type&, size_type ) const; - size_type Mid( self_type&, PRUint32, PRUint32 ) const; - size_type Right( self_type&, size_type ) const; // Find( ... ) const; PRInt32 FindChar( char_type, index_type aOffset = 0 ) const; @@ -441,27 +421,6 @@ class NS_COM nsACString size_type CountChar( char_type ) const; - /* - |Left|, |Mid|, and |Right| are annoying signatures that seem better almost - any _other_ way than they are now. Consider these alternatives - - aWritable = aReadable.Left(17); // ...a member function that returns a |Substring| - aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring| - Left(aReadable, 17, aWritable); // ...a global function that does the assignment - - as opposed to the current signature - - aReadable.Left(aWritable, 17); // ...a member function that does the assignment - - or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality - - aWritable = Substring(aReadable, 0, 17); - */ - - size_type Left( self_type&, size_type ) const; - size_type Mid( self_type&, PRUint32, PRUint32 ) const; - size_type Right( self_type&, size_type ) const; - // Find( ... ) const; PRInt32 FindChar( char_type, index_type aOffset = 0 ) const; // FindCharInSet( ... ) const; @@ -779,13 +738,6 @@ operator> ( const nsAString& lhs, const nsAString& rhs ) return Compare(lhs, rhs)> 0; } -inline -nsAString::size_type -nsAString::Left( nsAString& aResult, size_type aLengthToCopy ) const - { - return Mid(aResult, 0, aLengthToCopy); - } - /** * @@ -896,13 +848,6 @@ operator> ( const nsACString& lhs, const nsACString& rhs ) return Compare(lhs, rhs)> 0; } -inline -nsACString::size_type -nsACString::Left( nsACString& aResult, size_type aLengthToCopy ) const - { - return Mid(aResult, 0, aLengthToCopy); - } - // Once you've got strings, you shouldn't need to do anything else to have concatenation #ifndef nsDependentConcatenation_h___ #include "nsDependentConcatenation.h" diff --git a/mozilla/xpcom/string/src/nsAString.cpp b/mozilla/xpcom/string/src/nsAString.cpp index 133ec000cfb..d7ce306228b 100644 --- a/mozilla/xpcom/string/src/nsAString.cpp +++ b/mozilla/xpcom/string/src/nsAString.cpp @@ -183,26 +183,6 @@ nsAString::CountChar( char_type c ) const return 0; } -nsAString::size_type -nsAString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const - { - // If we're just assigning our entire self, give |aResult| the opportunity to share - if ( aStartPos == 0 && aLengthToCopy >= Length() ) - aResult = *this; - else - aResult = Substring(*this, aStartPos, aLengthToCopy); - - return aResult.Length(); - } - -nsAString::size_type -nsAString::Right( self_type& aResult, size_type aLengthToCopy ) const - { - size_type myLength = Length(); - aLengthToCopy = NS_MIN(myLength, aLengthToCopy); - return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); - } - PRInt32 nsAString::FindChar( char_type aChar, PRUint32 aOffset ) const { @@ -702,26 +682,6 @@ nsACString::CountChar( char_type c ) const return 0; } -nsACString::size_type -nsACString::Mid( self_type& aResult, index_type aStartPos, size_type aLengthToCopy ) const - { - // If we're just assigning our entire self, give |aResult| the opportunity to share - if ( aStartPos == 0 && aLengthToCopy >= Length() ) - aResult = *this; - else - aResult = Substring(*this, aStartPos, aLengthToCopy); - - return aResult.Length(); - } - -nsACString::size_type -nsACString::Right( self_type& aResult, size_type aLengthToCopy ) const - { - size_type myLength = Length(); - aLengthToCopy = NS_MIN(myLength, aLengthToCopy); - return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy); - } - PRInt32 nsACString::FindChar( char_type aChar, PRUint32 aOffset ) const {