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

Side by Side Diff: pkg/barback/lib/src/utils.dart

Issue 198103003: Support extensions with multiple periods in Transformer.allowedExtensions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library barback.utils; 5 library barback.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 /// Converts a number in the range [0-255] to a two digit hex string. 87 /// Converts a number in the range [0-255] to a two digit hex string.
88 /// 88 ///
89 /// For example, given `255`, returns `ff`. 89 /// For example, given `255`, returns `ff`.
90 String byteToHex(int byte) { 90 String byteToHex(int byte) {
91 assert(byte >= 0 && byte <= 255); 91 assert(byte >= 0 && byte <= 255);
92 92
93 const DIGITS = "0123456789abcdef"; 93 const DIGITS = "0123456789abcdef";
94 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16]; 94 return DIGITS[(byte ~/ 16) % 16] + DIGITS[byte % 16];
95 } 95 }
96 96
97 /// Returns a sentence fragment listing the elements of [iter].
98 ///
99 /// This converts each element of [iter] to a string and separates them with
100 /// commas and/or "and" where appropriate.
101 String toSentence(Iterable iter) {
102 if (iter.length == 1) return iter.first.toString();
103 return iter.take(iter.length - 1).join(", ") + " and ${iter.last}";
104 }
105
106 /// Returns [name] if [number] is 1, or the plural of [name] otherwise.
107 ///
108 /// By default, this just adds "s" to the end of [name] to get the plural. If
109 /// [plural] is passed, that's used instead.
110 String pluralize(String name, int number, {String plural}) {
111 if (number == 1) return name;
112 if (plural != null) return plural;
113 return '${name}s';
114 }
115
97 /// Converts [input] into a [Uint8List]. 116 /// Converts [input] into a [Uint8List].
98 /// 117 ///
99 /// If [input] is a [TypedData], this just returns a view on [input]. 118 /// If [input] is a [TypedData], this just returns a view on [input].
100 Uint8List toUint8List(List<int> input) { 119 Uint8List toUint8List(List<int> input) {
101 if (input is Uint8List) return input; 120 if (input is Uint8List) return input;
102 if (input is TypedData) { 121 if (input is TypedData) {
103 // TODO(nweiz): remove "as" when issue 11080 is fixed. 122 // TODO(nweiz): remove "as" when issue 11080 is fixed.
104 return new Uint8List.view((input as TypedData).buffer); 123 return new Uint8List.view((input as TypedData).buffer);
105 } 124 }
106 return new Uint8List.fromList(input); 125 return new Uint8List.fromList(input);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 subscription = callback().listen(controller.add, 301 subscription = callback().listen(controller.add,
283 onError: controller.addError, 302 onError: controller.addError,
284 onDone: controller.close); 303 onDone: controller.close);
285 }, 304 },
286 onCancel: () => subscription.cancel(), 305 onCancel: () => subscription.cancel(),
287 onPause: () => subscription.pause(), 306 onPause: () => subscription.pause(),
288 onResume: () => subscription.resume(), 307 onResume: () => subscription.resume(),
289 sync: true); 308 sync: true);
290 return controller.stream; 309 return controller.stream;
291 } 310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698