summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-09-08 16:36:19 +0200
committerXavier Morel <xmo@openerp.com>2014-10-06 19:13:40 +0200
commit35f5fb46e78aef1feda4d9cfddd93bd356bdca28 (patch)
treeaecb22510b568be2b76533d11d310f45f15c1554 /addons/web/static
parent9fe71a5d18a9d9f765ff0315951ec8a96e0de9d4 (diff)
[IMP] qweb-js: reimplement string interpolation compilation as a single pass
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/lib/qweb/qweb2.js30
1 files changed, 16 insertions, 14 deletions
diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js
index c7fa24b8e22..983a3d4187d 100644
--- a/addons/web/static/lib/qweb/qweb2.js
+++ b/addons/web/static/lib/qweb/qweb2.js
@@ -601,24 +601,26 @@ QWeb2.Element = (function() {
return r;
},
string_interpolation : function(s) {
+ var _this = this;
if (!s) {
return "''";
}
- var regex = /^{(.*)}(.*)/,
- src = s.split(/#/),
- r = [];
- for (var i = 0, ilen = src.length; i < ilen; i++) {
- var val = src[i],
- m = val.match(regex);
- if (m) {
- r.push("(" + this.format_expression(m[1]) + ")");
- if (m[2]) {
- r.push(this.engine.tools.js_escape(m[2]));
- }
- } else if (!(i === 0 && val === '')) {
- r.push(this.engine.tools.js_escape((i === 0 ? '' : '#') + val));
- }
+ function append_literal(s) {
+ s && r.push(_this.engine.tools.js_escape(s));
}
+
+ var re = /#{(.*?)}/g, start = 0, r = [], m;
+ while (m = re.exec(s)) {
+ // extract literal string between previous and current match
+ append_literal(s.slice(start, re.lastIndex - m[0].length));
+ // extract matched expression
+ r.push('(' + this.format_expression(m[1]) + ')');
+ // update position of new matching
+ start = re.lastIndex;
+ }
+ // remaining text after last expression
+ append_literal(s.slice(start));
+
return r.join(' + ');
},
indent : function() {