Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: third_party/pkg/angular/lib/core/interpolate.dart

Issue 180843004: Revert revision 33053 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 part of angular.core; 1 part of angular.core;
2 2
3 String _startSymbol = '{{';
4 String _endSymbol = '}}';
5 int _startSymbolLength = _startSymbol.length;
6 int _endSymbolLength = _endSymbol.length;
7
3 class Interpolation { 8 class Interpolation {
4 final String template; 9 final String template;
5 final List<String> seperators; 10 final List<String> seperators;
6 final List<String> expressions; 11 final List<Getter> watchExpressions;
7 Function setter = (_) => _; 12 Function setter = (_) => _;
8 13
9 Interpolation(this.template, this.seperators, this.expressions); 14 Interpolation(this.template, this.seperators, this.watchExpressions);
10 15
11 String call(List parts, [_]) { 16 String call(List parts, [_, __]) {
12 if (parts == null) return seperators.join('');
13 var str = []; 17 var str = [];
14 for (var i = 0; i < parts.length; i++) { 18 for(var i = 0, ii = parts.length; i < ii; i++) {
15 str.add(seperators[i]); 19 str.add(seperators[i]);
16 var value = parts[i]; 20 var value = parts[i];
17 str.add(value == null ? '' : '$value'); 21 str.add(value == null ? '' : '$value');
18 } 22 }
19 str.add(seperators.last); 23 str.add(seperators.last);
20 return setter(str.join('')); 24 return setter(str.join(''));
21 } 25 }
22 } 26 }
23 27
24 /** 28 /**
(...skipping 12 matching lines...) Expand all
37 Interpolate(this._parse); 41 Interpolate(this._parse);
38 42
39 /** 43 /**
40 * Compiles markup text into interpolation function. 44 * Compiles markup text into interpolation function.
41 * 45 *
42 * - `text`: The markup text to interpolate in form `foo {{expr}} bar`. 46 * - `text`: The markup text to interpolate in form `foo {{expr}} bar`.
43 * - `mustHaveExpression`: if set to true then the interpolation string must 47 * - `mustHaveExpression`: if set to true then the interpolation string must
44 * have embedded expression in order to return an interpolation function. 48 * have embedded expression in order to return an interpolation function.
45 * Strings with no embedded expression will return null for the 49 * Strings with no embedded expression will return null for the
46 * interpolation function. 50 * interpolation function.
47 * - `startSymbol`: The symbol to start interpolation. '{{' by default.
48 * - `endSymbol`: The symbol to end interpolation. '}}' by default.
49 */ 51 */
50 Interpolation call(String template, [bool mustHaveExpression = false, 52 Interpolation call(String template, [bool mustHaveExpression = false]) {
51 String startSymbol = '{{', String endSymbol = '}}']) {
52 int startSymbolLength = startSymbol.length;
53 int endSymbolLength = endSymbol.length;
54 int startIndex; 53 int startIndex;
55 int endIndex; 54 int endIndex;
56 int index = 0; 55 int index = 0;
57 int length = template.length; 56 int length = template.length;
58 bool hasInterpolation = false; 57 bool hasInterpolation = false;
59 bool shouldAddSeparator = true; 58 bool shouldAddSeparator = true;
60 String exp; 59 String exp;
61 List<String> separators = []; 60 List<String> separators = [];
62 List<String> expressions = []; 61 List<Getter> watchExpressions = [];
63 62
64 while(index < length) { 63 while(index < length) {
65 if ( ((startIndex = template.indexOf(startSymbol, index)) != -1) && 64 if ( ((startIndex = template.indexOf(_startSymbol, index)) != -1) &&
66 ((endIndex = template.indexOf(endSymbol, startIndex + startSymbolLeng th)) != -1) ) { 65 ((endIndex = template.indexOf(_endSymbol, startIndex + _startSymbolLe ngth)) != -1) ) {
67 separators.add(template.substring(index, startIndex)); 66 separators.add(template.substring(index, startIndex));
68 exp = template.substring(startIndex + startSymbolLength, endIndex); 67 exp = template.substring(startIndex + _startSymbolLength, endIndex);
69 expressions.add(exp); 68 Expression expression = _parse(exp);
70 index = endIndex + endSymbolLength; 69 watchExpressions.add(expression.eval);
70 index = endIndex + _endSymbolLength;
71 hasInterpolation = true; 71 hasInterpolation = true;
72 } else { 72 } else {
73 // we did not find anything, so we have to add the remainder to the chun ks array 73 // we did not find anything, so we have to add the remainder to the chun ks array
74 separators.add(template.substring(index)); 74 separators.add(template.substring(index));
75 shouldAddSeparator = false; 75 shouldAddSeparator = false;
76 break; 76 break;
77 } 77 }
78 } 78 }
79 if (shouldAddSeparator) { 79 if (shouldAddSeparator) {
80 separators.add(''); 80 separators.add('');
81 } 81 }
82 return (!mustHaveExpression || hasInterpolation) 82 if (!mustHaveExpression || hasInterpolation) {
83 ? new Interpolation(template, separators, expressions) 83 return new Interpolation(template, separators, watchExpressions);
84 : null; 84 }
85 } 85 }
86 } 86 }
OLDNEW
« no previous file with comments | « third_party/pkg/angular/lib/core/exception_handler.dart ('k') | third_party/pkg/angular/lib/core/module.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698