this.separator = separator;
}
-Splitter.prototype.split = function (value) {
+Splitter.prototype.split = function (value, withSeparator) {
if (value.indexOf(this.separator) === -1)
return [value];
- if (value.indexOf('(') === -1)
+ if (value.indexOf('(') === -1 && !withSeparator)
return value.split(this.separator);
var level = 0;
} else if (value[cursor] == ')') {
level--;
} else if (value[cursor] == this.separator && level === 0) {
- tokens.push(value.substring(lastStart, cursor));
+ tokens.push(value.substring(lastStart, cursor + (withSeparator ? 1 : 0)));
lastStart = cursor + 1;
}
}
var assert = require('assert');
var Splitter = require('../../lib/utils/splitter');
-function split(value, expectedValue, separator) {
+function split(value, expectedValue, separator, withSeparator) {
return function () {
- assert.deepEqual(new Splitter(separator).split(value), expectedValue);
+ assert.deepEqual(new Splitter(separator).split(value, withSeparator), expectedValue);
};
}
'space separated - level 1': split('rgb(0, 0, 0) #fff', ['rgb(0, 0, 0)', '#fff'], ' '),
'space separated - level 2': split('linear-gradient(0, #fff, rgba(0, 0, 0)) red', ['linear-gradient(0, #fff, rgba(0, 0, 0))', 'red'], ' ')
})
+ .addBatch({
+ 'leading space and quote with separator': split(' "Font"', [' "Font"'], ' ', true),
+ 'comma separated - level 2 - with separator': split('linear-gradient(0,#fff,rgba(0,0,0)),red', ['linear-gradient(0,#fff,rgba(0,0,0)),', 'red'], ',', true),
+ 'space separated - level 2 - with separator': split('linear-gradient(0, #fff, rgba(0, 0, 0)) red', ['linear-gradient(0, #fff, rgba(0, 0, 0)) ', 'red'], ' ', true)
+ })
.export(module);