Handle +/- before numbers in CSS (#2713)

* src/util: Fix negative number handling

* src/util: Handle decimal numbers with leading plus sign

* src/util: Handle sign symbols before numbers in scientific notation
master
Christian Wesselhoeft 2017-08-30 12:26:11 -06:00 committed by Simon Lydell
parent 9533c17827
commit 87401de0a5
3 changed files with 21 additions and 3 deletions

View File

@ -572,11 +572,11 @@ function printNumber(rawNumber) {
rawNumber
.toLowerCase()
// Remove unnecessary plus and zeroes from scientific notation.
.replace(/^([\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
.replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
// Remove unnecessary scientific notation (1e0).
.replace(/^([\d.]+)e[+-]?0+$/, "$1")
.replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1")
// Make sure numbers always start with a digit.
.replace(/^\./, "0.")
.replace(/^([+-])?\./, "$10.")
// Remove extraneous trailing decimal zeroes.
.replace(/(\.\d+?)0+(?=e|$)/, "$1")
// Remove trailing dot.

View File

@ -11,6 +11,8 @@ exports[`numbers.css 1`] = `
a: .1;
a: 1.;
a: +.1;
a: -.1;
a: 1e1;
a: 1e+1;
@ -19,6 +21,8 @@ exports[`numbers.css 1`] = `
a: .1e1;
a: 1.1e1;
a: 1.1e0010;
a: +1.1e0010;
a: -1.1e0010;
a: .1e+0010;
a: .1e-0010;
@ -38,6 +42,8 @@ exports[`numbers.css 1`] = `
a: 0.5e+00;
a: 0.5e-0;
a: 0.5e-00;
a: +0.5e0;
a: -0.5e0;
a: 1;
a: 1.00500;
@ -75,6 +81,8 @@ exports[`numbers.css 1`] = `
a: 0.1;
a: 1;
a: +0.1;
a: -0.1;
a: 1e1;
a: 1e1;
@ -83,6 +91,8 @@ exports[`numbers.css 1`] = `
a: 0.1e1;
a: 1.1e1;
a: 1.1e10;
a: +1.1e10;
a: -1.1e10;
a: 0.1e10;
a: 0.1e-10;
@ -102,6 +112,8 @@ exports[`numbers.css 1`] = `
a: 0.5;
a: 0.5;
a: 0.5;
a: +0.5;
a: -0.5;
a: 1;
a: 1.005;

View File

@ -8,6 +8,8 @@
a: .1;
a: 1.;
a: +.1;
a: -.1;
a: 1e1;
a: 1e+1;
@ -16,6 +18,8 @@
a: .1e1;
a: 1.1e1;
a: 1.1e0010;
a: +1.1e0010;
a: -1.1e0010;
a: .1e+0010;
a: .1e-0010;
@ -35,6 +39,8 @@
a: 0.5e+00;
a: 0.5e-0;
a: 0.5e-00;
a: +0.5e0;
a: -0.5e0;
a: 1;
a: 1.00500;