OLD | NEW |
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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 | 8 |
9 import 'package:async/async.dart' hide StreamQueue; | 9 import 'package:async/async.dart' hide StreamQueue; |
10 import 'package:crypto/crypto.dart'; | 10 import 'package:crypto/crypto.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 /// A typedef for a zero-argument callback function. | 27 /// A typedef for a zero-argument callback function. |
28 typedef void Callback(); | 28 typedef void Callback(); |
29 | 29 |
30 /// A converter that decodes bytes using UTF-8 and splits them on newlines. | 30 /// A converter that decodes bytes using UTF-8 and splits them on newlines. |
31 final lineSplitter = UTF8.decoder.fuse(const LineSplitter()); | 31 final lineSplitter = UTF8.decoder.fuse(const LineSplitter()); |
32 | 32 |
33 /// A regular expression to match the exception prefix that some exceptions' | 33 /// A regular expression to match the exception prefix that some exceptions' |
34 /// [Object.toString] values contain. | 34 /// [Object.toString] values contain. |
35 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); | 35 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); |
36 | 36 |
| 37 /// A regular expression matching a single vowel. |
| 38 final _vowel = new RegExp('[aeiou]'); |
| 39 |
37 /// Directories that are specific to OS X. | 40 /// Directories that are specific to OS X. |
38 /// | 41 /// |
39 /// This is used to try to distinguish OS X and Linux in [currentOSGuess]. | 42 /// This is used to try to distinguish OS X and Linux in [currentOSGuess]. |
40 final _macOSDirectories = new Set<String>.from([ | 43 final _macOSDirectories = new Set<String>.from([ |
41 "/Applications", | 44 "/Applications", |
42 "/Library", | 45 "/Library", |
43 "/Network", | 46 "/Network", |
44 "/System", | 47 "/System", |
45 "/Users" | 48 "/Users" |
46 ]); | 49 ]); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 /// Returns [name] if [number] is 1, or the plural of [name] otherwise. | 114 /// Returns [name] if [number] is 1, or the plural of [name] otherwise. |
112 /// | 115 /// |
113 /// By default, this just adds "s" to the end of [name] to get the plural. If | 116 /// By default, this just adds "s" to the end of [name] to get the plural. If |
114 /// [plural] is passed, that's used instead. | 117 /// [plural] is passed, that's used instead. |
115 String pluralize(String name, int number, {String plural}) { | 118 String pluralize(String name, int number, {String plural}) { |
116 if (number == 1) return name; | 119 if (number == 1) return name; |
117 if (plural != null) return plural; | 120 if (plural != null) return plural; |
118 return '${name}s'; | 121 return '${name}s'; |
119 } | 122 } |
120 | 123 |
| 124 /// Returns [noun] with an indefinite article ("a" or "an") added, based on |
| 125 /// whether its first letter is a vowel. |
| 126 String a(String noun) => noun.startsWith(_vowel) ? "an $noun" : "a $noun"; |
| 127 |
121 /// Wraps [text] so that it fits within [lineLength], which defaults to 100 | 128 /// Wraps [text] so that it fits within [lineLength], which defaults to 100 |
122 /// characters. | 129 /// characters. |
123 /// | 130 /// |
124 /// This preserves existing newlines and doesn't consider terminal color escapes | 131 /// This preserves existing newlines and doesn't consider terminal color escapes |
125 /// part of a word's length. | 132 /// part of a word's length. |
126 String wordWrap(String text, {int lineLength}) { | 133 String wordWrap(String text, {int lineLength}) { |
127 if (lineLength == null) lineLength = _lineLength; | 134 if (lineLength == null) lineLength = _lineLength; |
128 return text.split("\n").map((originalLine) { | 135 return text.split("\n").map((originalLine) { |
129 var buffer = new StringBuffer(); | 136 var buffer = new StringBuffer(); |
130 var lengthSoFar = 0; | 137 var lengthSoFar = 0; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 urlSafe: urlSafe, addLineSeparator: addLineSeparator); | 416 urlSafe: urlSafe, addLineSeparator: addLineSeparator); |
410 } | 417 } |
411 | 418 |
412 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 419 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
413 shelf.Middleware nestingMiddleware(String beneath) { | 420 shelf.Middleware nestingMiddleware(String beneath) { |
414 return (handler) { | 421 return (handler) { |
415 var pathHandler = new PathHandler()..add(beneath, handler); | 422 var pathHandler = new PathHandler()..add(beneath, handler); |
416 return pathHandler.handler; | 423 return pathHandler.handler; |
417 }; | 424 }; |
418 } | 425 } |
OLD | NEW |