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

Side by Side Diff: pkg/third_party/html5lib/lib/src/utils.dart

Issue 157983005: pkg/third_party/html5lib: lots of cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: bump version 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 /** Misc things that were useful when porting the code from Python. */ 1 /** Misc things that were useful when porting the code from Python. */
2 library utils; 2 library utils;
3 3
4 import 'dart:collection';
5 import 'constants.dart'; 4 import 'constants.dart';
6 5
7 typedef bool Predicate(); 6 typedef bool Predicate();
8 7
9 class Pair<F, S> { 8 class Pair<F, S> {
10 final F first; 9 final F first;
11 final S second; 10 final S second;
12 11
13 const Pair(this.first, this.second); 12 const Pair(this.first, this.second);
14 13
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 for (int i = 0; i < size; i++) result.write('0'); 67 for (int i = 0; i < size; i++) result.write('0');
69 result.write(str); 68 result.write(str);
70 return result.toString(); 69 return result.toString();
71 } 70 }
72 71
73 // TODO(jmesserly): this implementation is pretty wrong, but I need something 72 // TODO(jmesserly): this implementation is pretty wrong, but I need something
74 // quick until dartbug.com/1694 is fixed. 73 // quick until dartbug.com/1694 is fixed.
75 /** 74 /**
76 * Format a string like Python's % string format operator. Right now this only 75 * Format a string like Python's % string format operator. Right now this only
77 * supports a [data] dictionary used with %s or %08x. Those were the only things 76 * supports a [data] dictionary used with %s or %08x. Those were the only things
78 * needed for [errorMessages]. 77 * needed for [ERROR_MESSAGES].
79 */ 78 */
80 String formatStr(String format, Map data) { 79 String formatStr(String format, Map data) {
81 if (data == null) return format; 80 if (data == null) return format;
82 data.forEach((key, value) { 81 data.forEach((key, value) {
83 var result = new StringBuffer(); 82 var result = new StringBuffer();
84 var search = '%($key)'; 83 var search = '%($key)';
85 int last = 0, match; 84 int last = 0, match;
86 while ((match = format.indexOf(search, last)) >= 0) { 85 while ((match = format.indexOf(search, last)) >= 0) {
87 result.write(format.substring(last, match)); 86 result.write(format.substring(last, match));
88 match += search.length; 87 match += search.length;
(...skipping 26 matching lines...) Expand all
115 114
116 last = match + 1; 115 last = match + 1;
117 } 116 }
118 117
119 result.write(format.substring(last, format.length)); 118 result.write(format.substring(last, format.length));
120 format = result.toString(); 119 format = result.toString();
121 }); 120 });
122 121
123 return format; 122 return format;
124 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698