зеркало из https://github.com/mozilla/gecko-dev.git
Bug 699147 - Simplify lengthList parsing. r=jwatt
This commit is contained in:
Родитель
9af9ebbaed
Коммит
032d99d10e
|
@ -42,6 +42,7 @@
|
|||
#include "nsContentUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsSVGUtils.h"
|
||||
#include "nsCharSeparatedTokenizer.h"
|
||||
#include "string.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -85,32 +86,23 @@ SVGLengthList::SetValueFromString(const nsAString& aValue)
|
|||
{
|
||||
SVGLengthList temp;
|
||||
|
||||
NS_ConvertUTF16toUTF8 value(aValue);
|
||||
char* start = SkipWhitespace(value.BeginWriting());
|
||||
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
||||
tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
|
||||
|
||||
// We can't use strtok with SVG_COMMA_WSP_DELIM because to correctly handle
|
||||
// invalid input in the form of two commas without a value between them, we
|
||||
// would need to know if strtok overwrote a comma or not.
|
||||
nsCAutoString str; // outside loop to minimize memory churn
|
||||
|
||||
while (*start != '\0') {
|
||||
int end = strcspn(start, SVG_COMMA_WSP_DELIM);
|
||||
if (end == 0) {
|
||||
// found comma in an invalid location
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
SVGLength length;
|
||||
if (!length.SetValueFromString(NS_ConvertUTF8toUTF16(start, PRUint32(end)))) {
|
||||
if (!length.SetValueFromString(tokenizer.nextToken())) {
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
if (!temp.AppendItem(length)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
start = SkipWhitespace(start + end);
|
||||
if (*start == ',') {
|
||||
start = SkipWhitespace(start + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (tokenizer.lastTokenEndedWithSeparator()) {
|
||||
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
||||
}
|
||||
return CopyFrom(temp);
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,9 @@ SVGNumberList::SetValueFromString(const nsAString& aValue)
|
|||
if (*end != '\0' || !NS_finite(num)) {
|
||||
return NS_ERROR_DOM_SYNTAX_ERR;
|
||||
}
|
||||
temp.AppendItem(num);
|
||||
if (!temp.AppendItem(num)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (tokenizer.lastTokenEndedWithSeparator()) {
|
||||
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
||||
|
|
Загрузка…
Ссылка в новой задаче