[Bug 28148] Improve parsing of numbers for coords attribute

https://www.w3.org/Bugs/Public/show_bug.cgi?id=28148

--- Comment #10 from Simon Pieters <simonp@opera.com> ---
Forgot about ignoring leading commas:

function newCoords(input) {
  var numbers = [];
  // trim leading separators
  input = input.replace(/^[\s,]+/, '');
  // split
  var tokens = input.split(/[\s,]+/);
  // for each token in tokens
  for (var i = 0; i < tokens.length; ++i) {
    var token = tokens[i];
    // replace garbage with spaces
    token = token.replace(/[^\d\.-]/g, ' ');
    // parse as float; add to numbers
    numbers.push(parseFloat(token, 10) || 0);
  }
  // return numbers
  return numbers;
}

\s here should be HTML's "space characters".

I could go either way with ; as separator.

Maybe also support scientific notation? It would be easy to trim only leading
garbage in each token, and let HTML's float parser deal with trailing garbage.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Thursday, 14 January 2016 08:05:33 UTC