Bug 555291: Replace multiple string-literals of SVG whitespace/comma delimeters with a single #define. r=jwatt

This commit is contained in:
Daniel Holbert 2010-03-26 20:55:28 -07:00
parent 43090d95fb
commit d527d95aca
4 changed files with 15 additions and 9 deletions

View File

@ -38,6 +38,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsSVGLength.h"
#include "nsSVGUtils.h"
#include "nsGkAtoms.h"
#include "nsSVGValue.h"
#include "nsTextFormatter.h"
@ -361,8 +362,8 @@ nsSVGLength::SetValueAsString(const nsAString & aValueAsString)
if (*number) {
char *rest;
float value = float(PR_strtod(number, &rest));
if (rest!=number) {
const char* unitStr = nsCRT::strtok(rest, "\x20\x9\xD\xA", &rest);
if (rest != number) {
const char* unitStr = nsCRT::strtok(rest, SVG_WSP_DELIM, &rest);
PRUint16 unitType = SVG_LENGTHTYPE_UNKNOWN;
if (!unitStr || *unitStr=='\0') {
unitType = SVG_LENGTHTYPE_NUMBER;

View File

@ -38,6 +38,7 @@
#include "nsSVGPointList.h"
#include "nsSVGPoint.h"
#include "nsSVGUtils.h"
#include "nsDOMError.h"
#include "prdtoa.h"
#include "nsReadableUtils.h"
@ -167,11 +168,10 @@ nsSVGPointList::SetValueString(const nsAString& aValue)
char* rest = str;
char* token1;
char* token2;
const char* delimiters = ",\x20\x9\xD\xA";
nsCOMArray<nsIDOMSVGPoint> points;
while ( (token1 = nsCRT::strtok(rest, delimiters, &rest)) &&
(token2 = nsCRT::strtok(rest, delimiters, &rest)) ) {
while ( (token1 = nsCRT::strtok(rest, SVG_COMMA_WSP_DELIM, &rest)) &&
(token2 = nsCRT::strtok(rest, SVG_COMMA_WSP_DELIM, &rest)) ) {
char *end;

View File

@ -37,6 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsSVGViewBox.h"
#include "nsSVGUtils.h"
#include "prdtoa.h"
#include "nsTextFormatter.h"
#ifdef MOZ_SMIL
@ -143,18 +144,19 @@ ToSVGViewBoxRect(const nsAString& aStr, nsSVGViewBoxRect *aViewBox)
char *rest = str;
char *token;
const char *delimiters = ",\x20\x9\xD\xA";
float vals[4];
PRUint32 i;
for (i = 0; i < 4; ++i) {
if (!(token = nsCRT::strtok(rest, delimiters, &rest))) break; // parse error
if (!(token = nsCRT::strtok(rest, SVG_COMMA_WSP_DELIM, &rest)))
break; // parse error
char *end;
vals[i] = float(PR_strtod(token, &end));
if (*end != '\0' || !NS_FloatIsFinite(vals[i])) break; // parse error
if (*end != '\0' || !NS_FloatIsFinite(vals[i]))
break; // parse error
}
if (i!=4 || nsCRT::strtok(rest, delimiters, &rest)!=0) {
if (i != 4 || (nsCRT::strtok(rest, SVG_COMMA_WSP_DELIM, &rest) != 0)) {
// there was a parse error.
rv = NS_ERROR_DOM_SYNTAX_ERR;
} else {

View File

@ -116,6 +116,9 @@ class nsSVGDisplayContainerFrame;
// In fact Macs can't even manage that
#define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096
#define SVG_WSP_DELIM "\x20\x9\xD\xA"
#define SVG_COMMA_WSP_DELIM "," SVG_WSP_DELIM
/*
* Checks the svg enable preference and if a renderer could
* successfully be created. Declared as a function instead of a