Bug 212272: Switch some Substring users over to String(Begins|Ends)With. r=dwitte, sr=bzbarsky

This commit is contained in:
jaggernaut%netscape.com 2003-07-14 07:37:39 +00:00
parent a6a24fb93b
commit 817298ce0b
49 changed files with 140 additions and 229 deletions

View File

@ -387,9 +387,7 @@ nsFrameLoader::EnsureDocShell()
parentAsItem->GetItemType(&parentType);
nsAutoString value;
PRBool isContent;
isContent = PR_FALSE;
PRBool isContent = PR_FALSE;
if (mOwnerContent->IsContentOfType(nsIContent::eXUL)) {
mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, value);
@ -404,19 +402,14 @@ nsFrameLoader::EnsureDocShell()
// on it being lowercased.
ToLowerCase(value);
nsAutoString::const_iterator start, end;
nsAutoString::const_char_iterator start, end;
value.BeginReading(start);
value.EndReading(end);
nsAutoString::const_iterator iter(start);
iter.advance(7);
nsAutoString::const_char_iterator iter(start + 7);
const nsAString& valuePiece = Substring(start, iter);
if (valuePiece.Equals(NS_LITERAL_STRING("content")) &&
(iter == end || *iter == '-')) {
isContent = PR_TRUE;
}
isContent = Substring(start, iter) == NS_LITERAL_STRING("content") &&
(iter == end || *iter == '-');
}
if (isContent) {
@ -439,7 +432,7 @@ nsFrameLoader::EnsureDocShell()
if(parentTreeOwner) {
PRBool is_primary = parentType == nsIDocShellTreeItem::typeChrome &&
value.Equals(NS_LITERAL_STRING("content-primary"));
value == NS_LITERAL_STRING("content-primary");
parentTreeOwner->ContentShellAdded(docShellAsItem, is_primary,
value.get());

View File

@ -570,8 +570,8 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
aContent->GetAttrCount(count);
NS_NAMED_LITERAL_STRING(mozStr1, "_moz");
NS_NAMED_LITERAL_STRING(_mozStr, "_moz");
for (index = 0; index < count; index++) {
aContent->GetAttrNameAt(index,
&namespaceID,
@ -591,9 +591,8 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
// Filter out special case of <br type="_moz"> or <br _moz*>,
// used by the editor. Bug 16988. Yuck.
//
if ((aTagName == nsHTMLAtoms::br) &&
(attrName.get() == nsHTMLAtoms::type) &&
(mozStr1.Equals(Substring(valueStr, 0, mozStr1.Length())))) {
if (aTagName == nsHTMLAtoms::br && attrName == nsHTMLAtoms::type &&
StringBeginsWith(valueStr, _mozStr)) {
continue;
}

View File

@ -1456,7 +1456,7 @@ nsPlainTextSerializer::AddToLine(const PRUnichar * aLineFragment,
(
restOfLine[0] == '>' ||
restOfLine[0] == ' ' ||
Substring(restOfLine, 0, 5).Equals(NS_LITERAL_STRING("From "))
StringBeginsWith(restOfLine, NS_LITERAL_STRING("From "))
)
&& mCiteQuoteLevel == 0 // We space-stuff quoted lines anyway
)

View File

@ -275,8 +275,8 @@ nsScriptLoader::IsScriptEventHandler(nsIDOMHTMLScriptElement *aScriptElement)
return PR_TRUE;
}
if (!Substring(event_str, 0, 6).Equals(NS_LITERAL_STRING("onload"),
nsCaseInsensitiveStringComparator())) {
if (!StringBeginsWith(event_str, NS_LITERAL_STRING("onload"),
nsCaseInsensitiveStringComparator())) {
// It ain't "onload.*".
return PR_TRUE;

View File

@ -128,24 +128,20 @@ nsStyleLinkElement::GetCharset(nsAString& aCharset)
void nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes,
nsStringArray& aResult)
{
nsReadingIterator<PRUnichar> current;
nsReadingIterator<PRUnichar> done;
aTypes.BeginReading(current);
nsAString::const_iterator start, done;
aTypes.BeginReading(start);
aTypes.EndReading(done);
if (current == done)
if (start == done)
return;
nsReadingIterator<PRUnichar> start;
nsAString::const_iterator current(start);
PRBool inString = !nsCRT::IsAsciiSpace(*current);
nsAutoString subString;
aTypes.BeginReading(start);
while (current != done) {
if (nsCRT::IsAsciiSpace(*current)) {
if (inString) {
subString = Substring(start, current);
ToLowerCase(subString);
ToLowerCase(Substring(start, current), subString);
aResult.AppendString(subString);
inString = PR_FALSE;
}
@ -159,8 +155,7 @@ void nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes,
++current;
}
if (inString) {
subString = Substring(start, current);
ToLowerCase(subString);
ToLowerCase(Substring(start, current), subString);
aResult.AppendString(subString);
}
}

View File

@ -2357,8 +2357,8 @@ nsHTMLInputElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,
//
nsCOMPtr<nsIFile> file;
if (Substring(value, 0, 5).Equals(NS_LITERAL_STRING("file:"),
nsCaseInsensitiveStringComparator())) {
if (StringBeginsWith(value, NS_LITERAL_STRING("file:"),
nsCaseInsensitiveStringComparator())) {
// Converts the URL string into the corresponding nsIFile if possible.
// A local file will be created if the URL string begins with file://.
rv = NS_GetFileFromURLSpec(NS_ConvertUCS2toUTF8(value),

View File

@ -3794,7 +3794,7 @@ HTMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode)
}
/*
* If we didn't find 'SYSTEM' we tread everything after the public id
* If we didn't find 'SYSTEM' we treat everything after the public id
* as the system id.
*/
if (systemStart < 0) {
@ -3809,7 +3809,7 @@ HTMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode)
docTypeStr.Length() - systemStart);
// Strip off 'SYSTEM' if we have it.
if (Substring(systemId, 0, 6).Equals(NS_LITERAL_STRING("SYSTEM")))
if (StringBeginsWith(systemId, NS_LITERAL_STRING("SYSTEM")))
systemId.Cut(0, 6);
systemId.Trim(" \t\n\r");
@ -3843,10 +3843,9 @@ HTMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode)
}
// Cut out "<!DOCTYPE" or "DOCTYPE" from the name.
nsCaseInsensitiveStringComparator ignoreCase;
if (Substring(name, 0, 9).Equals(NS_LITERAL_STRING("<!DOCTYPE"), ignoreCase)) {
if (StringBeginsWith(name, NS_LITERAL_STRING("<!DOCTYPE"), nsCaseInsensitiveStringComparator())) {
name.Cut(0, 9);
} else if (Substring(name, 0, 7).Equals(NS_LITERAL_STRING("DOCTYPE"), ignoreCase)) {
} else if (StringBeginsWith(name, NS_LITERAL_STRING("DOCTYPE"), nsCaseInsensitiveStringComparator())) {
name.Cut(0, 7);
}

View File

@ -3462,13 +3462,11 @@ DashMatchCompare(const nsAString& aAttributeValue,
result = PR_FALSE;
}
else {
const nsAString& attributeSubstring =
Substring(aAttributeValue, 0, selectorLen);
if (aCaseSensitive)
result = attributeSubstring.Equals(aSelectorValue);
result = StringBeginsWith(aAttributeValue, aSelectorValue);
else
result = attributeSubstring.Equals(aSelectorValue,
nsCaseInsensitiveStringComparator());
result = StringBeginsWith(aAttributeValue, aSelectorValue,
nsCaseInsensitiveStringComparator());
}
}
return result;
@ -3496,35 +3494,20 @@ static PRBool AttrMatchesValue(const nsAttrSelector* aAttrSelector,
case NS_ATTR_FUNC_DASHMATCH:
return DashMatchCompare(aValue, aAttrSelector->mValue, isCaseSensitive);
case NS_ATTR_FUNC_ENDSMATCH:
{
PRUint32 selLen = aAttrSelector->mValue.Length();
PRUint32 valLen = aValue.Length();
if (selLen > valLen) {
return PR_FALSE;
} else {
if (isCaseSensitive)
return Substring(aValue, valLen - selLen, selLen).
Equals(aAttrSelector->mValue);
else
return Substring(aValue, valLen - selLen, selLen).
Equals(aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
if (isCaseSensitive) {
return StringEndsWith(aValue, aAttrSelector->mValue);
}
else {
return StringEndsWith(aValue, aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
case NS_ATTR_FUNC_BEGINSMATCH:
{
PRUint32 selLen = aAttrSelector->mValue.Length();
PRUint32 valLen = aValue.Length();
if (selLen > valLen) {
return PR_FALSE;
} else {
if (isCaseSensitive)
return Substring(aValue, 0, selLen).Equals(aAttrSelector->mValue);
else
return Substring(aValue, 0, selLen).
Equals(aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
if (isCaseSensitive) {
return StringBeginsWith(aValue, aAttrSelector->mValue);
}
else {
return StringBeginsWith(aValue, aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
case NS_ATTR_FUNC_CONTAINSMATCH:
return FindInReadable(aAttrSelector->mValue, aValue,

View File

@ -109,7 +109,6 @@
#include "nsHTMLAtoms.h"
static const char kNameSpaceSeparator = ':';
static const char kNameSpaceDef[] = "xmlns";
#ifdef PR_LOGGING
static PRLogModuleInfo* gLog;
@ -1132,26 +1131,21 @@ XULContentSinkImpl::PushNameSpacesFrom(const PRUnichar** aAttributes)
}
static const NS_NAMED_LITERAL_STRING(kNameSpaceDef, "xmlns");
static const PRUint32 xmlns_len = 5; // kNameSpaceDef.Length();
NS_ASSERTION(kNameSpaceDef.Length() == xmlns_len,
"xmlns_len incorrectly set!");
static const PRUint32 xmlns_len = kNameSpaceDef.Length();
for (; *aAttributes; aAttributes += 2) {
nsDependentString key(aAttributes[0]);
// Look for "xmlns" at the start of the attribute name
PRUint32 key_len = key.Length();
if (key_len >= xmlns_len &&
Substring(key, 0, xmlns_len).Equals(kNameSpaceDef)) {
if (StringBeginsWith(key, kNameSpaceDef)) {
nsCOMPtr<nsIAtom> prefixAtom;
// If key_len > xmlns_len we have a xmlns:foo type attribute,
// If key.Length() > xmlns_len we have a xmlns:foo type attribute,
// extract the prefix. If not, we have a xmlns attribute in
// which case there is no prefix.
if (key_len > xmlns_len) {
if (key.Length() > xmlns_len) {
nsDependentString::const_iterator start, end;
key.BeginReading(start);

View File

@ -827,8 +827,7 @@ nsXULPrototypeCache::StartFastLoad(nsIURI* aURI)
nsCAutoString path;
aURI->GetPath(path);
const nsACString& extn = Substring(path, path.Length()-4, 4);
if (! extn.Equals(NS_LITERAL_CSTRING(".xul")))
if (!StringEndsWith(path, NS_LITERAL_CSTRING(".xul")))
return NS_ERROR_NOT_AVAILABLE;
nsIURIKey key(aURI);

View File

@ -2312,7 +2312,7 @@ nsXULTemplateBuilder::AddBindingsFor(nsXULTemplateBuilder* aThis,
{
// We should *only* be recieving "rdf:"-style variables. Make
// sure...
if (Substring(aVariable, PRUint32(0), PRUint32(4)) != NS_LITERAL_STRING("rdf:"))
if (!StringBeginsWith(aVariable, NS_LITERAL_STRING("rdf:")))
return;
nsTemplateRule* rule = NS_STATIC_CAST(nsTemplateRule*, aClosure);

View File

@ -52,6 +52,7 @@
#include "nsIDOMDocumentView.h"
#include "nsIContent.h"
#include "nsTextEditUtils.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsHTMLCSSUtils.h"
#include "nsColor.h"
@ -1234,7 +1235,7 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
}
else if (nsEditProperty::tt == aHTMLProperty) {
aIsSet = Substring(valueString, 0, 9).Equals(NS_LITERAL_STRING("monospace"));
aIsSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace"));
}
else if ((nsEditProperty::font == aHTMLProperty) && aHTMLAttribute

View File

@ -3998,8 +3998,8 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList)
{
nsAutoString href;
if (NS_SUCCEEDED(anchor->GetHref(href)))
if (Substring(href, 0, 5).Equals(NS_LITERAL_STRING("file:"),
nsCaseInsensitiveStringComparator()))
if (StringBeginsWith(href, NS_LITERAL_STRING("file:"),
nsCaseInsensitiveStringComparator()))
(*aNodeList)->AppendElement(node);
}
}

View File

@ -42,6 +42,7 @@
#include "nsIDocumentObserver.h"
#include "nsIContent.h"
#include "nsHTMLEditUtils.h"
#include "nsReadableUtils.h"
// Uncomment the following line if you want to disable
// table deletion when the only column/row is removed
@ -167,7 +168,7 @@ nsHTMLEditor::DoInlineTableEditingAction(nsIDOMElement * aElement)
nsresult res = aElement->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass);
if (NS_FAILED(res)) return res;
if (!Substring(anonclass, 0, 8).Equals(NS_LITERAL_STRING("mozTable")))
if (!StringBeginsWith(anonclass, NS_LITERAL_STRING("mozTable")))
return NS_OK;
nsCOMPtr<nsIDOMNode> cellNode = do_QueryInterface(mInlineEditedCell);

View File

@ -85,7 +85,7 @@ nsAOLCiter::StripCites(const nsAString& aInString, nsAString& aOutString)
nsReadingIterator <PRUnichar> iter,enditer;
aInString.BeginReading(iter);
aInString.EndReading(enditer);
if (Substring(aInString,0,2).Equals(NS_LITERAL_STRING(">>")))
if (StringBeginsWith(aInString, NS_LITERAL_STRING(">>")))
{
iter.advance(2);
while (nsCRT::IsAsciiSpace(*iter))

View File

@ -2693,7 +2693,7 @@ nsresult nsWebBrowserPersist::OnWalkDOMNode(nsIDOMNode *aNode)
linkRel.EndReading(end);
// Walk through space delimited string looking for "stylesheet"
for (current = start; current != end; current++)
for (current = start; current != end; ++current)
{
// Ignore whitespace
if (nsCRT::IsAsciiSpace(*current))
@ -2702,13 +2702,13 @@ nsresult nsWebBrowserPersist::OnWalkDOMNode(nsIDOMNode *aNode)
// Grab the next space delimited word
nsReadingIterator<PRUnichar> startWord = current;
do {
current++;
} while (!nsCRT::IsAsciiSpace(*current) && current != end);
++current;
} while (current != end && !nsCRT::IsAsciiSpace(*current));
// Store the link for fix up if it says "stylesheet"
nsAutoString subString; subString = Substring(startWord, current);
ToLowerCase(subString);
if (subString.Equals(NS_LITERAL_STRING("stylesheet")))
if (Substring(startWord, current)
.Equals(NS_LITERAL_STRING("stylesheet"),
nsCaseInsensitiveStringComparator()))
{
StoreURIAttribute(aNode, "href");
return NS_OK;

View File

@ -616,7 +616,7 @@ nsCookieService::GetCookieStringFromHttp(nsIURI *aHostURI,
// the cookie list is in order of path length; longest to shortest.
// if the nsIURI path is shorter than the cookie path, then we know the path
// isn't on the cookie path.
if (!Substring(pathFromURI, 0, cookiePathLen).Equals(Substring(cookieInList->Path(), 0, cookiePathLen))) {
if (!StringBeginsWith(pathFromURI, Substring(cookieInList->Path(), 0, cookiePathLen))) {
continue;
}
@ -2313,7 +2313,7 @@ nsCookieService::CheckPath(nsCookieAttributes &aCookieAttributes,
// get path from aHostURI
nsCAutoString pathFromURI;
if (NS_FAILED(aHostURI->GetPath(pathFromURI)) ||
!Substring(pathFromURI, 0, aCookieAttributes.path.Length()).Equals(aCookieAttributes.path)) {
!StringBeginsWith(pathFromURI, aCookieAttributes.path)) {
return PR_FALSE;
}
#endif

View File

@ -417,7 +417,7 @@ inDOMView::GetCellText(PRInt32 row, const PRUnichar *colID, nsAString& _retval)
} else if (col.Equals(NS_LITERAL_STRING("colNodeValue")))
domNode->GetNodeValue(_retval);
else {
if (Substring(col, 0, 4).Equals(NS_LITERAL_STRING("col@"))) {
if (StringBeginsWith(col, NS_LITERAL_STRING("col@"))) {
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(node->node);
if (el) {
nsAutoString attr;

View File

@ -321,7 +321,7 @@ NS_IMETHODIMP mozLineTerm::OpenAux(const PRUnichar *command,
if (NS_SUCCEEDED(result) &&
(cookieStr.Length() > cookiePrefix.Length()) &&
(Substring(cookieStr, 0, cookiePrefix.Length()) == cookiePrefix)) {
StringBeginsWith(cookieStr, cookiePrefix)) {
// Cookie value already defined for document; simply copy it
mCookie = cookieStr;

View File

@ -2856,8 +2856,7 @@ GetEncoding(const char *aFontName, char **aEncoding, nsXftFontType &aType,
// '.wide' at the end indicates 'wide' font.
if (encoding.Length() > 5 &&
Substring(encoding, encoding.Length() - 5, 5) ==
NS_LITERAL_STRING(".wide")) {
StringEndsWith(encoding, NS_LITERAL_STRING(".wide"))) {
aType = eFontTypeCustomWide;
encoding.Truncate(encoding.Length() - 5);
}

View File

@ -1309,7 +1309,7 @@ GetConverter(const char* aFontName, nsIUnicodeEncoder** aConverter, PRBool* aIsW
// The encoding name of a wide NonUnicode font in fontEncoding.properties
// has '.wide' suffix which has to be removed to get the converter
// for the encoding.
if (Substring(value, value.Length() - 5, 5) == (NS_LITERAL_CSTRING(".wide"))) {
if (StringEndsWith(value, NS_LITERAL_CSTRING(".wide"))) {
value.Truncate(value.Length()-5);
if (aIsWide)
*aIsWide = PR_TRUE;

View File

@ -970,10 +970,10 @@ nsresult nsHTMLTokenizer::ConsumeSpecialMarkup(PRUnichar aChar,CToken*& aToken,n
if(theIndex==kNotFound) {
if('['==theBufCopy.CharAt(0)) {
aToken = theAllocator->CreateTokenOfType(eToken_cdatasection,eHTMLTag_comment);
} else if (Substring(theBufCopy, 0, 7).Equals(NS_LITERAL_STRING("ELEMENT")) ||
Substring(theBufCopy, 0, 7).Equals(NS_LITERAL_STRING("ATTLIST")) ||
Substring(theBufCopy, 0, 6).Equals(NS_LITERAL_STRING("ENTITY")) ||
Substring(theBufCopy, 0, 8).Equals(NS_LITERAL_STRING("NOTATION"))) {
} else if (StringBeginsWith(theBufCopy, NS_LITERAL_STRING("ELEMENT")) ||
StringBeginsWith(theBufCopy, NS_LITERAL_STRING("ATTLIST")) ||
StringBeginsWith(theBufCopy, NS_LITERAL_STRING("ENTITY")) ||
StringBeginsWith(theBufCopy, NS_LITERAL_STRING("NOTATION"))) {
aToken = theAllocator->CreateTokenOfType(eToken_markupDecl,eHTMLTag_markupDecl);
} else {
aToken = theAllocator->CreateTokenOfType(eToken_comment,eHTMLTag_comment);

View File

@ -547,7 +547,7 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke
mSink->OpenHead(headNode);
// Note that XUL will automatically add the prefix "Source of: "
if (Substring(mFilename, 0, 5).Equals(NS_LITERAL_STRING("data:")) &&
if (StringBeginsWith(mFilename, NS_LITERAL_STRING("data:")) &&
mFilename.Length() > 50) {
nsAutoString dataFilename(Substring(mFilename, 0, 50));
dataFilename.Append(NS_LITERAL_STRING("..."));

View File

@ -294,7 +294,7 @@ nsPropertyEnumeratorByURL::HasMoreElements(PRBool * aResult)
nsCAutoString curKey;
mCurrent->GetKey(curKey);
if (mURL.Equals(Substring(curKey, 0, mURL.Length())))
if (StringBeginsWith(curKey, mURL))
break;
}

View File

@ -3466,8 +3466,8 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
if (optionElement) {
nsAutoString text;
if (NS_OK == optionElement->GetText(text)) {
if (Substring(text, 0, stringLength).Equals(incrementalString,
nsCaseInsensitiveStringComparator())) {
if (StringBeginsWith(text, incrementalString,
nsCaseInsensitiveStringComparator())) {
PRBool wasChanged = PerformSelection(index, isShift, isControl);
if (wasChanged) {
UpdateSelection(); // dispatch event, update combobox, etc.

View File

@ -3466,8 +3466,8 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
if (optionElement) {
nsAutoString text;
if (NS_OK == optionElement->GetText(text)) {
if (Substring(text, 0, stringLength).Equals(incrementalString,
nsCaseInsensitiveStringComparator())) {
if (StringBeginsWith(text, incrementalString,
nsCaseInsensitiveStringComparator())) {
PRBool wasChanged = PerformSelection(index, isShift, isControl);
if (wasChanged) {
UpdateSelection(); // dispatch event, update combobox, etc.

View File

@ -3462,13 +3462,11 @@ DashMatchCompare(const nsAString& aAttributeValue,
result = PR_FALSE;
}
else {
const nsAString& attributeSubstring =
Substring(aAttributeValue, 0, selectorLen);
if (aCaseSensitive)
result = attributeSubstring.Equals(aSelectorValue);
result = StringBeginsWith(aAttributeValue, aSelectorValue);
else
result = attributeSubstring.Equals(aSelectorValue,
nsCaseInsensitiveStringComparator());
result = StringBeginsWith(aAttributeValue, aSelectorValue,
nsCaseInsensitiveStringComparator());
}
}
return result;
@ -3496,35 +3494,20 @@ static PRBool AttrMatchesValue(const nsAttrSelector* aAttrSelector,
case NS_ATTR_FUNC_DASHMATCH:
return DashMatchCompare(aValue, aAttrSelector->mValue, isCaseSensitive);
case NS_ATTR_FUNC_ENDSMATCH:
{
PRUint32 selLen = aAttrSelector->mValue.Length();
PRUint32 valLen = aValue.Length();
if (selLen > valLen) {
return PR_FALSE;
} else {
if (isCaseSensitive)
return Substring(aValue, valLen - selLen, selLen).
Equals(aAttrSelector->mValue);
else
return Substring(aValue, valLen - selLen, selLen).
Equals(aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
if (isCaseSensitive) {
return StringEndsWith(aValue, aAttrSelector->mValue);
}
else {
return StringEndsWith(aValue, aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
case NS_ATTR_FUNC_BEGINSMATCH:
{
PRUint32 selLen = aAttrSelector->mValue.Length();
PRUint32 valLen = aValue.Length();
if (selLen > valLen) {
return PR_FALSE;
} else {
if (isCaseSensitive)
return Substring(aValue, 0, selLen).Equals(aAttrSelector->mValue);
else
return Substring(aValue, 0, selLen).
Equals(aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
if (isCaseSensitive) {
return StringBeginsWith(aValue, aAttrSelector->mValue);
}
else {
return StringBeginsWith(aValue, aAttrSelector->mValue,
nsCaseInsensitiveStringComparator());
}
case NS_ATTR_FUNC_CONTAINSMATCH:
return FindInReadable(aAttrSelector->mValue, aValue,

View File

@ -71,6 +71,7 @@
#include "nsIRootBox.h"
#include "nsIDocShellTreeItem.h"
#include "nsITimerInternal.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#ifdef XP_WIN
#include "nsISound.h"
@ -1781,7 +1782,8 @@ nsMenuPopupFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, PRBool& doActi
else
isShortcut = PR_TRUE;
if (Substring(textKey, 0, stringLength).Equals(incrementalString, nsCaseInsensitiveStringComparator())) {
if (StringBeginsWith(textKey, incrementalString,
nsCaseInsensitiveStringComparator())) {
// mIncrementalString is a prefix of textKey
nsCOMPtr<nsIMenuFrame> menuFrame = do_QueryInterface(currFrame);
if (menuFrame) {

View File

@ -76,7 +76,7 @@ nsTreeUtils::TokenizeProperties(const nsAString& aProperties, nsISupportsArray*
if (iter == first)
break;
nsCOMPtr<nsIAtom> atom = dont_AddRef(NS_NewAtom(Substring(first, iter)));
nsCOMPtr<nsIAtom> atom = do_GetAtom(Substring(first, iter));
aPropertiesArray->AppendElement(atom);
} while (iter != end);

View File

@ -213,7 +213,7 @@ NS_IMETHODIMP nsAbBSDirectory::GetChildNodes(nsIEnumerator* *result)
* a 4.x address book file e.g. pab.na2
* check if the URI ends with ".na2"
*/
if (Substring(URI, URI.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffixLen).Equals(kABFileName_PreviousSuffix)) {
if (StringEndsWith(URI, NS_LITERAL_CSTRING(kABFileName_PreviousSuffix))) {
URI.ReplaceSubstring(URI.get() + kMDBDirectoryRootLen, server->fileName);
}
@ -315,9 +315,7 @@ NS_IMETHODIMP nsAbBSDirectory::CreateDirectoryByURI(const PRUnichar *aDisplayNam
nsresult rv = NS_OK;
const char* fileName = nsnull;
nsCAutoString uriStr(aURI);
if (Substring(uriStr, 0, kMDBDirectoryRootLen).Equals(kMDBDirectoryRoot))
if (StringBeginsWith(nsDependentCString(aURI), NS_LITERAL_CSTRING(kMDBDirectoryRoot)))
fileName = aURI + kMDBDirectoryRootLen;
DIR_Server * server = nsnull;

View File

@ -609,22 +609,13 @@ nsresult nsAbDirectoryQuery::matchCardCondition (nsIAbCard* card,
*matchFound = !FindInReadable(matchValue, value, nsCaseInsensitiveStringComparator());
break;
case nsIAbBooleanConditionTypes::Is:
*matchFound = value.Equals (matchValue, nsCaseInsensitiveStringComparator());
*matchFound = value.Equals(matchValue, nsCaseInsensitiveStringComparator());
break;
case nsIAbBooleanConditionTypes::IsNot:
*matchFound = !value.Equals (matchValue, nsCaseInsensitiveStringComparator());
*matchFound = !value.Equals(matchValue, nsCaseInsensitiveStringComparator());
break;
case nsIAbBooleanConditionTypes::BeginsWith:
{
if (value.Length() < matchValue.Length()) {
*matchFound = PR_FALSE;
break;
}
*matchFound =
matchValue.Equals(Substring(value, 0,
matchValue.Length()),
nsCaseInsensitiveStringComparator());
}
*matchFound = StringBeginsWith(value, matchValue, nsCaseInsensitiveStringComparator());
break;
case nsIAbBooleanConditionTypes::LessThan:
*matchFound = Compare(value, matchValue, nsCaseInsensitiveStringComparator()) < 0;
@ -633,21 +624,8 @@ nsresult nsAbDirectoryQuery::matchCardCondition (nsIAbCard* card,
*matchFound = Compare(value, matchValue, nsCaseInsensitiveStringComparator()) > 0;
break;
case nsIAbBooleanConditionTypes::EndsWith:
{
PRInt32 vl = value.Length ();
PRInt32 mvl = matchValue.Length ();
if (mvl > vl)
{
*matchFound = PR_FALSE;
break;
}
*matchFound = matchValue.Equals(Substring(value, vl - mvl, mvl),
nsCaseInsensitiveStringComparator());
*matchFound = StringEndsWith(value, matchValue, nsCaseInsensitiveStringComparator());
break;
}
case nsIAbBooleanConditionTypes::SoundsLike:
case nsIAbBooleanConditionTypes::RegExp:
*matchFound = PR_FALSE;

View File

@ -147,7 +147,7 @@ NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProp
nsCAutoString fileName;
nsDependentCString uriStr(uri);
if (Substring(uriStr, 0, kMDBDirectoryRootLen).Equals(kMDBDirectoryRoot))
if (StringBeginsWith(uriStr, NS_LITERAL_CSTRING(kMDBDirectoryRoot)))
fileName = Substring(uriStr, kMDBDirectoryRootLen, uriStr.Length() - kMDBDirectoryRootLen);
(*dbPath) += fileName.get();

View File

@ -4081,8 +4081,7 @@ PRBool nsImapMailFolder::ShowDeletedMessages()
{
nsXPIDLString folderName;
GetName(getter_Copies(folderName));
if (Substring(folderName,0,convertedName.Length()).Equals(convertedName,
nsCaseInsensitiveStringComparator()))
if (StringBeginsWith(folderName, convertedName, nsCaseInsensitiveStringComparator()))
showDeleted = PR_TRUE;
}
}

View File

@ -97,11 +97,6 @@ typedef struct
#define kNumAttributes 12
// Define CIDs...
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
#define VCARD_URL "chrome://messenger/locale/vcard.properties"
/* This is the object definition. Note: we will set the superclass

View File

@ -78,7 +78,7 @@ static void PrintImageDecoders()
NS_NAMED_LITERAL_CSTRING(decoderContract, "@mozilla.org/image/decoder;2?type=");
if (Substring(xcs, 0, decoderContract.Length()).Equals(decoderContract)) {
if (StringBeginsWith(xcs, decoderContract)) {
printf("Have decoder for mime type: %s\n", xcs.get()+decoderContract.Length());
}
}

View File

@ -756,7 +756,7 @@ JSBool pref_InitInitialObjects()
rv = aFile->GetNativeLeafName(leafName);
if (NS_SUCCEEDED(rv)) {
// Skip non-js files
if ((leafName.Length() < 3) || !Substring(leafName, leafName.Length() - 3, 3).Equals(NS_LITERAL_CSTRING(".js")))
if (!StringEndsWith(leafName, NS_LITERAL_CSTRING(".js")))
shouldParse = PR_FALSE;
// Skip files in the special list.
if (shouldParse) {

View File

@ -254,16 +254,15 @@ PRBool nsPluginsDir::IsPluginFile(nsIFile* file)
if (NS_FAILED(file->GetNativeLeafName(filename)))
return PR_FALSE;
int len = filename.Length();
nsCAutoString suffix (LOCAL_PLUGIN_DLL_SUFFIX);
int slen = suffix.Length();
if (len > slen && suffix.Equals(Substring(filename,len-slen,slen)))
NS_NAMED_LITERAL_CSTRING(dllSuffix, LOCAL_PLUGIN_DLL_SUFFIX);
if (filename.Length() > dllSuffix.Length() &&
StringEndsWith(filename, dllSuffix))
return PR_TRUE;
#ifdef LOCAL_PLUGIN_DLL_ALT_SUFFIX
suffix.Assign(LOCAL_PLUGIN_DLL_ALT_SUFFIX);
slen = suffix.Length();
if (len > slen && suffix.Equals(Substring(filename,len-slen,slen)))
NS_NAMED_LITERAL_CSTRING(dllAltSuffix, LOCAL_PLUGIN_DLL_ALT_SUFFIX);
if (filename.Length() > dllAltSuffix.Length() &&
StringEndsWith(filename, dllAltSuffix))
return PR_TRUE;
#endif
return PR_FALSE;

View File

@ -226,8 +226,8 @@ NS_IMETHODIMP nsIDNService::ConvertACEtoUTF8(const nsACString & input, nsACStrin
NS_IMETHODIMP nsIDNService::IsACE(const nsACString & input, PRBool *_retval)
{
nsDependentCString prefix(mACEPrefix, kACEPrefixLen);
*_retval = Substring(input, 0, kACEPrefixLen).Equals(prefix,
nsCaseInsensitiveCStringComparator());
*_retval = StringBeginsWith(input, prefix,
nsCaseInsensitiveCStringComparator());
// also check for the case like "www.xn--ENCODED.com"
// in case for this is called for an entire domain name
if (!*_retval) {

View File

@ -2522,7 +2522,7 @@ nsFtpState::SendFTPCommand(nsCString& command)
// we don't want to log the password:
nsCAutoString logcmd(command);
if (Substring(command, 0, 5).Equals(NS_LITERAL_CSTRING("PASS ")))
if (StringBeginsWith(command, NS_LITERAL_CSTRING("PASS ")))
logcmd = "PASS xxxxx";
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("(%x)(dwait=%d) Writing \"%s\"\n", this, mWaitingForDConn, logcmd.get()));

View File

@ -970,10 +970,10 @@ nsresult nsHTMLTokenizer::ConsumeSpecialMarkup(PRUnichar aChar,CToken*& aToken,n
if(theIndex==kNotFound) {
if('['==theBufCopy.CharAt(0)) {
aToken = theAllocator->CreateTokenOfType(eToken_cdatasection,eHTMLTag_comment);
} else if (Substring(theBufCopy, 0, 7).Equals(NS_LITERAL_STRING("ELEMENT")) ||
Substring(theBufCopy, 0, 7).Equals(NS_LITERAL_STRING("ATTLIST")) ||
Substring(theBufCopy, 0, 6).Equals(NS_LITERAL_STRING("ENTITY")) ||
Substring(theBufCopy, 0, 8).Equals(NS_LITERAL_STRING("NOTATION"))) {
} else if (StringBeginsWith(theBufCopy, NS_LITERAL_STRING("ELEMENT")) ||
StringBeginsWith(theBufCopy, NS_LITERAL_STRING("ATTLIST")) ||
StringBeginsWith(theBufCopy, NS_LITERAL_STRING("ENTITY")) ||
StringBeginsWith(theBufCopy, NS_LITERAL_STRING("NOTATION"))) {
aToken = theAllocator->CreateTokenOfType(eToken_markupDecl,eHTMLTag_markupDecl);
} else {
aToken = theAllocator->CreateTokenOfType(eToken_comment,eHTMLTag_comment);

View File

@ -547,7 +547,7 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke
mSink->OpenHead(headNode);
// Note that XUL will automatically add the prefix "Source of: "
if (Substring(mFilename, 0, 5).Equals(NS_LITERAL_STRING("data:")) &&
if (StringBeginsWith(mFilename, NS_LITERAL_STRING("data:")) &&
mFilename.Length() > 50) {
nsAutoString dataFilename(Substring(mFilename, 0, 50));
dataFilename.Append(NS_LITERAL_STRING("..."));

View File

@ -63,7 +63,7 @@ nsNameSpaceMap::const_iterator
nsNameSpaceMap::GetNameSpaceOf(const nsAString& aURI) const
{
for (Entry* entry = mEntries; entry != nsnull; entry = entry->mNext) {
if (Substring(aURI, 0, entry->mURI.Length()) == entry->mURI)
if (StringBeginsWith(aURI, entry->mURI))
return const_iterator(entry);
}

View File

@ -1498,9 +1498,9 @@ RDFServiceImpl::GetDataSource(const char* aURI, PRBool aBlock, nsIRDFDataSource*
// useless (and expensive) protocol handler lookups.
nsCAutoString spec(aURI);
if (Substring(spec, 0, 4) != NS_LITERAL_CSTRING("rdf:")) {
if (!StringBeginsWith(spec, NS_LITERAL_CSTRING("rdf:"))) {
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURI));
NS_NewURI(getter_AddRefs(uri), spec);
if (uri)
uri->GetSpec(spec);
}
@ -1520,7 +1520,7 @@ RDFServiceImpl::GetDataSource(const char* aURI, PRBool aBlock, nsIRDFDataSource*
// Nope. So go to the repository to try to create it.
nsCOMPtr<nsIRDFDataSource> ds;
if (Substring(spec, 0, 4) == NS_LITERAL_CSTRING("rdf:")) {
if (StringBeginsWith(spec, NS_LITERAL_CSTRING("rdf:"))) {
// It's a built-in data source. Convert it to a contract ID.
nsCAutoString contractID(
NS_LITERAL_CSTRING(NS_RDF_DATASOURCE_CONTRACTID_PREFIX) +

View File

@ -76,7 +76,7 @@ rdf_MakeRelativeRef(const nsString& aBaseURI, nsString& aURI)
// relative paths, or anything fancy like that. If the context URI
// is not a prefix of the URI in question, we'll just bail.
PRUint32 prefixLen = aBaseURI.Length();
if (prefixLen && Substring(aURI, 0, prefixLen) == aBaseURI) {
if (prefixLen != 0 && StringBeginsWith(aURI, aBaseURI)) {
if (prefixLen < aURI.Length() && aURI.CharAt(prefixLen) == '/')
++prefixLen; // chop the leading slash so it's not `absolute'
@ -90,13 +90,10 @@ static PRBool
rdf_RequiresAbsoluteURI(const nsString& uri)
{
// cheap shot at figuring out if this requires an absolute url translation
if (Substring(uri, 0, 4).Equals(NS_LITERAL_STRING("urn:")) ||
Substring(uri, 0, 9).Equals(NS_LITERAL_STRING("chrome:")) ||
Substring(uri, 0, 3).Equals(NS_LITERAL_STRING("nc:"),
nsCaseInsensitiveStringComparator())) {
return PR_FALSE;
}
return PR_TRUE;
return !(StringBeginsWith(uri, NS_LITERAL_STRING("urn:")) ||
StringBeginsWith(uri, NS_LITERAL_STRING("chrome:")) ||
StringBeginsWith(uri, NS_LITERAL_STRING("nc:"),
nsCaseInsensitiveStringComparator()));
}
nsresult

View File

@ -487,8 +487,8 @@ IsNetscapeFormat(const nsAString& aBuffer) {
"#--Netscape Communications Corporation MIME Information");
NS_NAMED_LITERAL_STRING(MCOMHeader, "#--MCOM MIME Information");
return Substring(aBuffer, 0, netscapeHeader.Length()).Equals(netscapeHeader) ||
Substring(aBuffer, 0, MCOMHeader.Length()).Equals(MCOMHeader);
return StringBeginsWith(aBuffer, netscapeHeader) ||
StringBeginsWith(aBuffer, MCOMHeader);
}
/*

View File

@ -420,8 +420,8 @@ IsNetscapeFormat(const nsAString& aBuffer) {
"#--Netscape Communications Corporation MIME Information");
NS_NAMED_LITERAL_STRING(MCOMHeader, "#--MCOM MIME Information");
return Substring(aBuffer, 0, netscapeHeader.Length()).Equals(netscapeHeader) ||
Substring(aBuffer, 0, MCOMHeader.Length()).Equals(MCOMHeader);
return StringBeginsWith(aBuffer, netscapeHeader) ||
StringBeginsWith(aBuffer, MCOMHeader);
}
/*

View File

@ -427,10 +427,10 @@ NS_METHOD
nsDirectoryService::Create(nsISupports *outer, REFNSIID aIID, void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
if (mService == nsnull)
if (!mService)
{
mService = new nsDirectoryService();
if (mService == NULL)
if (!mService)
return NS_ERROR_OUT_OF_MEMORY;
}
return mService->QueryInterface(aIID, aResult);
@ -636,9 +636,7 @@ nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result)
{
nsCOMPtr<nsIFile> cloneFile;
nsCOMPtr<nsIFile> cachedFile = do_QueryInterface(value);
if (!cachedFile)
return NS_ERROR_NULL_POINTER;
NS_ASSERTION(cachedFile, "nsIFile expected");
cachedFile->Clone(getter_AddRefs(cloneFile));
return cloneFile->QueryInterface(uuid, result);

View File

@ -4007,9 +4007,8 @@ nsGlobalHistory::AutoCompleteSearch(const nsAString& aSearchString,
if (aPrevResults) {
nsXPIDLString prevURL;
aPrevResults->GetSearchString(getter_Copies(prevURL));
nsDependentString prevURLStr(prevURL);
// if search string begins with the previous search string, it's a go
searchPrevious = Substring(aSearchString, 0, prevURLStr.Length()).Equals(prevURLStr);
searchPrevious = StringBeginsWith(aSearchString, prevURL);
}
nsCOMPtr<nsISupportsArray> resultItems;
@ -4131,7 +4130,7 @@ nsGlobalHistory::AutoCompleteGetExcludeInfo(const nsAString& aURL, AutocompleteE
PRInt32 i;
for (i = 0; i < mIgnoreSchemes.Count(); ++i) {
nsString* string = mIgnoreSchemes.StringAt(i);
if (Substring(aURL, 0, string->Length()).Equals(*string)) {
if (StringBeginsWith(aURL, *string)) {
aExclude->schemePrefix = i;
index = string->Length();
break;
@ -4160,7 +4159,7 @@ nsGlobalHistory::AutoCompleteCutPrefix(nsAString& aURL, AutocompleteExclude* aEx
if (aExclude && i == aExclude->schemePrefix)
continue;
nsString* string = mIgnoreSchemes.StringAt(i);
if (Substring(aURL, 0, string->Length()).Equals(*string)) {
if (StringBeginsWith(aURL, *string)) {
idx = string->Length();
break;
}
@ -4174,7 +4173,7 @@ nsGlobalHistory::AutoCompleteCutPrefix(nsAString& aURL, AutocompleteExclude* aEx
if (aExclude && i == aExclude->hostnamePrefix)
continue;
nsString* string = mIgnoreHostnames.StringAt(i);
if (Substring(aURL, 0, string->Length()).Equals(*string)) {
if (StringBeginsWith(aURL, *string)) {
idx = string->Length();
break;
}
@ -4213,7 +4212,7 @@ nsGlobalHistory::AutoCompleteCompare(nsAString& aHistoryURL,
{
AutoCompleteCutPrefix(aHistoryURL, aExclude);
return Substring(aHistoryURL, 0, aUserURL.Length()).Equals(aUserURL);
return StringBeginsWith(aHistoryURL, aUserURL);
}
int PR_CALLBACK

View File

@ -68,7 +68,7 @@ class nsXPITriggerItem
nsCOMPtr<nsIPrincipal> mPrincipal;
PRBool IsFileURL() { return Substring(mURL, 0, 6).Equals(NS_LITERAL_STRING("file:/")); }
PRBool IsFileURL() { return StringBeginsWith(mURL, NS_LITERAL_STRING("file:/")); }
PRBool IsRelativeURL();
void SetPrincipal(nsIPrincipal* aPrincipal);