/**
 * cssfilter
 *
 * @author 老雷<leizongmin@gmail.com>
 */




/**
 * 解析Style
 *
 * @param {String} css
 * @param {Function} onAttr 处理属性的函数
 *   参数格式： function (sourcePosition, position, name, value, source)
 * @return {String}
 */
function parseStyle (css, onAttr) {
  if (css[css.length - 1] !== ';') css += ';';
  var cssLength = css.length;
  var isParenthesisOpen = false;
  var lastPos = 0;
  var retCSS = '';

  for (var i = 0; i < cssLength; i++) {
    var c = css[i];
    if (c === '(') {
      isParenthesisOpen = true;
    } else if (c === ')') {
      isParenthesisOpen = false;
    } else if (c === ';') {
      if (isParenthesisOpen) {
        // 在圆括号里面，忽略
      } else {
        var source = css.slice(lastPos, i).trim();
        var j = source.indexOf(':');
        if (j !== -1) {
          var name = source.slice(0, j).trim();
          var value = source.slice(j + 1).trim();
          retCSS += onAttr(lastPos, retCSS.length, name, value, source) + '; ';
        }
        lastPos = i + 1;
      }
    }
  }

  return retCSS;
}


exports.parseStyle = parseStyle;


console.log(parseStyle('y; position:fixed; width:100px; x; height:100px; background:url(baidu;;);\n\nbackground:#aaa',
function (sourcePosition, position, name, value, source) {
  console.log(sourcePosition, position, name, value, source);
  return source;
}));

@@ -401,293 +401,122 @@
 var 
-retCSS = '';%0A%0A  for (var i = 0; i %3C cssLength; i++) %7B%0A 
+i = 0;%0A
   
- 
 var 
-c = css%5Bi%5D;%0A    if (c === '(') %7B%0A      isParenthesisOpen = true;%0A    %7D else if (c === ')') %7B%0A      isParenthesisOpen = false;%0A    %7D else if (c === ';') %7B%0A      if (isParenthesisOpen) %7B%0A        // %E5%9C%A8%E5%9C%86%E6%8B%AC%E5%8F%B7%E9%87%8C%E9%9D%A2%EF%BC%8C%E5%BF%BD%E7%95%A5%0A      %7D else %7B%0A  
+retCSS = '';%0A%0A  function addNewAttr () %7B%0A    // %E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89%E6%AD%A3%E5%B8%B8%E7%9A%84%E9%97%AD%E5%90%88%E5%9C%86%E6%8B%AC%E5%8F%B7%EF%BC%8C%E5%88%99%E7%9B%B4%E6%8E%A5%E5%BF%BD%E7%95%A5%E5%BD%93%E5%89%8D%E5%B1%9E%E6%80%A7%0A    if (!isParenthesisOpen) %7B%0A
     
@@ -562,26 +562,24 @@
 im();%0A      
-  
 var j = sour
@@ -601,18 +601,16 @@
 ;%0A      
-  
 if (j !=
@@ -621,26 +621,24 @@
 ) %7B%0A        
- 
- 
 var name = s
@@ -655,34 +655,32 @@
 e(0, j).trim();%0A
-  
         var valu
@@ -703,32 +703,71 @@
 (j + 1).trim();%0A
+        // %E5%BF%85%E9%A1%BB%E6%9C%89%E5%B1%9E%E6%80%A7%E5%90%8D%E7%A7%B0%0A        if (name) %7B%0A
           retCSS
@@ -840,24 +840,34 @@
       %7D%0A    
+  %7D%0A    %7D%0A
     lastPos 
@@ -877,21 +877,357 @@
  + 1;%0A  
-    %7D
+%7D%0A%0A  for (; i %3C cssLength; i++) %7B%0A    var c = css%5Bi%5D;%0A    if (c === '(') %7B%0A      isParenthesisOpen = true;%0A    %7D else if (c === ')') %7B%0A      isParenthesisOpen = false;%0A    %7D else if (c === ';') %7B%0A      if (isParenthesisOpen) %7B%0A        // %E5%9C%A8%E5%9C%86%E6%8B%AC%E5%8F%B7%E9%87%8C%E9%9D%A2%EF%BC%8C%E5%BF%BD%E7%95%A5%0A      %7D else %7B%0A        addNewAttr();%0A      %7D%0A    %7D else if (c === '%5Cn') %7B%0A      addNewAttr();
 %0A    %7D%0A 
@@ -1344,16 +1344,27 @@
 00px; x;
+ y:(aa%5Cnc);
  height:

修正 parseStyle()，换行符强制结束一个属性