Bug 321180, better space-separated string parsing, r+sr=jonas

This commit is contained in:
Neil Deakin 2008-12-19 08:43:24 -05:00
parent f5177ae51d
commit 4ed141a6e6
2 changed files with 16 additions and 22 deletions

View File

@ -67,6 +67,7 @@
#include "nsXULContentUtils.h"
#include "nsString.h"
#include "nsQuickSort.h"
#include "nsWhitespaceTokenizer.h"
#include "nsXULSortService.h"
#include "nsIDOMXULElement.h"
#include "nsIXULTemplateBuilder.h"
@ -414,26 +415,14 @@ XULSortServiceImpl::InitializeSortState(nsIContent* aRootElement,
aSortState->sortKeys.AppendObject(sortkeyatom2);
sort.AppendLiteral(" ");
sort.Append(sortResource2);
}
}
}
}
else {
PRInt32 start = 0, end = 0;
while ((end = sort.FindChar(' ',start)) >= 0) {
if (end > start) {
nsCOMPtr<nsIAtom> keyatom = do_GetAtom(Substring(sort, start, end - start));
if (!keyatom)
return NS_ERROR_OUT_OF_MEMORY;
aSortState->sortKeys.AppendObject(keyatom);
}
start = end + 1;
}
if (start < (PRInt32)sort.Length()) {
nsCOMPtr<nsIAtom> keyatom = do_GetAtom(Substring(sort, start));
if (!keyatom)
return NS_ERROR_OUT_OF_MEMORY;
else {
nsWhitespaceTokenizer tokenizer(sort);
while (tokenizer.hasMoreTokens()) {
nsCOMPtr<nsIAtom> keyatom = do_GetAtom(tokenizer.nextToken());
NS_ENSURE_TRUE(keyatom, NS_ERROR_OUT_OF_MEMORY);
aSortState->sortKeys.AppendObject(keyatom);
}
}

View File

@ -91,6 +91,7 @@
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
#include "nsWhitespaceTokenizer.h"
#include "nsGkAtoms.h"
#include "nsXULElement.h"
#include "jsapi.h"
@ -1753,12 +1754,16 @@ nsXULTemplateBuilder::CompileQueries()
mRoot->GetAttr(kNameSpaceID_None, nsGkAtoms::flags, flags);
// if the dont-test-empty flag is set, containers should not be checked to
// see if they are empty
if (flags.Find(NS_LITERAL_STRING("dont-test-empty")) >= 0)
// see if they are empty. If dont-recurse is set, then don't process the
// template recursively and only show one level of results.
nsWhitespaceTokenizer tokenizer(flags);
while (tokenizer.hasMoreTokens()) {
const nsDependentSubstring& token(tokenizer.nextToken());
if (token.EqualsLiteral("dont-test-empty"))
mFlags |= eDontTestEmpty;
if (flags.Find(NS_LITERAL_STRING("dont-recurse")) >= 0)
else if (token.EqualsLiteral("dont-recurse"))
mFlags |= eDontRecurse;
}
nsCOMPtr<nsIDOMNode> rootnode = do_QueryInterface(mRoot);
nsresult rv =