Ver código fonte

move strip quotes to _.lang

Evan You 11 anos atrás
pai
commit
20b26a619b
2 arquivos alterados com 17 adições e 6 exclusões
  1. 2 6
      src/parse/directive.js
  2. 15 0
      src/util/lang.js

+ 2 - 6
src/parse/directive.js

@@ -1,3 +1,4 @@
+var _ = require('../util')
 var Cache = require('../cache')
 var Cache = require('../cache')
 var cache = new Cache(1000)
 var cache = new Cache(1000)
 var argRE = /^[\w\$-]+$|^'[^']*'$|^"[^"]*"$/
 var argRE = /^[\w\$-]+$|^'[^']*'$|^"[^"]*"$/
@@ -20,7 +21,6 @@ var dirs
 var dir
 var dir
 var lastFilterIndex
 var lastFilterIndex
 var arg
 var arg
-var argC
 
 
 /**
 /**
  * Push a directive object into the result Array
  * Push a directive object into the result Array
@@ -121,11 +121,7 @@ exports.parse = function (s) {
       // an object literal or a ternary expression.
       // an object literal or a ternary expression.
       if (argRE.test(arg)) {
       if (argRE.test(arg)) {
         argIndex = i + 1
         argIndex = i + 1
-        argC = arg.charCodeAt(0)
-        // strip quotes
-        dir.arg = argC === 0x22 || argC === 0x27
-          ? arg.slice(1, -1)
-          : arg
+        dir.arg = _.stripQuotes(arg)
       }
       }
     } else if (
     } else if (
       c === 0x7C && // pipe
       c === 0x7C && // pipe

+ 15 - 0
src/util/lang.js

@@ -12,6 +12,21 @@ exports.guard = function (value) {
     : value
     : value
 }
 }
 
 
+/**
+ * Strip quotes from a string
+ *
+ * @param {String} str
+ * @return {String}
+ */
+
+exports.stripQuotes = function (str) {
+  var a = str.charCodeAt(0)
+  var b = str.charCodeAt(str.length - 1)
+  return a === b && (a === 0x22 || a === 0x27)
+    ? str.slice(1, -1)
+    : str
+}
+
 /**
 /**
  * Check and convert possible numeric numbers before
  * Check and convert possible numeric numbers before
  * setting back to data
  * setting back to data