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

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

Issue 180873006: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback Created 6 years, 9 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
8 class Interpolation { 3 class Interpolation {
9 final String template; 4 final String template;
10 final List<String> seperators; 5 final List<String> seperators;
11 final List<Getter> watchExpressions; 6 final List<String> expressions;
12 Function setter = (_) => _; 7 Function setter = (_) => _;
13 8
14 Interpolation(this.template, this.seperators, this.watchExpressions); 9 Interpolation(this.template, this.seperators, this.expressions);
15 10
16 String call(List parts, [_, __]) { 11 String call(List parts, [_]) {
12 if (parts == null) return seperators.join('');
17 var str = []; 13 var str = [];
18 for(var i = 0, ii = parts.length; i < ii; i++) { 14 for (var i = 0; i < parts.length; i++) {
19 str.add(seperators[i]); 15 str.add(seperators[i]);
20 var value = parts[i]; 16 var value = parts[i];
21 str.add(value == null ? '' : '$value'); 17 str.add(value == null ? '' : '$value');
22 } 18 }
23 str.add(seperators.last); 19 str.add(seperators.last);
24 return setter(str.join('')); 20 return setter(str.join(''));
25 } 21 }
26 } 22 }
27 23
28 /** 24 /**
(...skipping 12 matching lines...) Expand all
41 Interpolate(this._parse); 37 Interpolate(this._parse);
42 38
43 /** 39 /**
44 * Compiles markup text into interpolation function. 40 * Compiles markup text into interpolation function.
45 * 41 *
46 * - `text`: The markup text to interpolate in form `foo {{expr}} bar`. 42 * - `text`: The markup text to interpolate in form `foo {{expr}} bar`.
47 * - `mustHaveExpression`: if set to true then the interpolation string must 43 * - `mustHaveExpression`: if set to true then the interpolation string must
48 * have embedded expression in order to return an interpolation function. 44 * have embedded expression in order to return an interpolation function.
49 * Strings with no embedded expression will return null for the 45 * Strings with no embedded expression will return null for the
50 * interpolation function. 46 * interpolation function.
47 * - `startSymbol`: The symbol to start interpolation. '{{' by default.
48 * - `endSymbol`: The symbol to end interpolation. '}}' by default.
51 */ 49 */
52 Interpolation call(String template, [bool mustHaveExpression = false]) { 50 Interpolation call(String template, [bool mustHaveExpression = false,
51 String startSymbol = '{{', String endSymbol = '}}']) {
52 int startSymbolLength = startSymbol.length;
53 int endSymbolLength = endSymbol.length;
53 int startIndex; 54 int startIndex;
54 int endIndex; 55 int endIndex;
55 int index = 0; 56 int index = 0;
56 int length = template.length; 57 int length = template.length;
57 bool hasInterpolation = false; 58 bool hasInterpolation = false;
58 bool shouldAddSeparator = true; 59 bool shouldAddSeparator = true;
59 String exp; 60 String exp;
60 List<String> separators = []; 61 List<String> separators = [];
61 List<Getter> watchExpressions = []; 62 List<String> expressions = [];
62 63
63 while(index < length) { 64 while(index < length) {
64 if ( ((startIndex = template.indexOf(_startSymbol, index)) != -1) && 65 if ( ((startIndex = template.indexOf(startSymbol, index)) != -1) &&
65 ((endIndex = template.indexOf(_endSymbol, startIndex + _startSymbolLe ngth)) != -1) ) { 66 ((endIndex = template.indexOf(endSymbol, startIndex + startSymbolLeng th)) != -1) ) {
66 separators.add(template.substring(index, startIndex)); 67 separators.add(template.substring(index, startIndex));
67 exp = template.substring(startIndex + _startSymbolLength, endIndex); 68 exp = template.substring(startIndex + startSymbolLength, endIndex);
68 Expression expression = _parse(exp); 69 expressions.add(exp);
69 watchExpressions.add(expression.eval); 70 index = endIndex + endSymbolLength;
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 if (!mustHaveExpression || hasInterpolation) { 82 return (!mustHaveExpression || hasInterpolation)
83 return new Interpolation(template, separators, watchExpressions); 83 ? new Interpolation(template, separators, expressions)
84 } 84 : null;
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