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

Side by Side Diff: utils/pub/path.dart

Issue 11609005: Fix analyzer errors/warnings for Pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// A comprehensive, cross-platform path manipulation library. 5 /// A comprehensive, cross-platform path manipulation library.
6 library path; 6 library path;
7 7
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 /// An internal builder for the current OS so we can provide a straight 10 /// An internal builder for the current OS so we can provide a straight
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 287 }
288 288
289 for (var part in parts) { 289 for (var part in parts) {
290 if (part == null) continue; 290 if (part == null) continue;
291 291
292 if (this.isAbsolute(part)) { 292 if (this.isAbsolute(part)) {
293 // An absolute path discards everything before it. 293 // An absolute path discards everything before it.
294 buffer.clear(); 294 buffer.clear();
295 buffer.add(part); 295 buffer.add(part);
296 } else { 296 } else {
297 if (part.length > 0 && style.separatorPattern.hasMatch(part[0])) { 297 if (part.length > 0 && part[0].contains(style.separatorPattern)) {
Bob Nystrom 2012/12/18 19:40:35 A simpler fix here is to just make separatorPatter
nweiz 2012/12/19 01:10:21 I think using str.contains(pattern) is about as cl
298 // The part starts with a separator, so we don't need to add one. 298 // The part starts with a separator, so we don't need to add one.
299 } else if (needsSeparator) { 299 } else if (needsSeparator) {
300 buffer.add(separator); 300 buffer.add(separator);
301 } 301 }
302 302
303 buffer.add(part); 303 buffer.add(part);
304 } 304 }
305 305
306 // Unless this part ends with a separator, we'll need to add one before 306 // Unless this part ends with a separator, we'll need to add one before
307 // the next part. 307 // the next part.
308 needsSeparator = part.length > 0 && 308 needsSeparator = part.length > 0 &&
309 !style.separatorPattern.hasMatch(part[part.length - 1]); 309 !part[part.length - 1].contains(style.separatorPattern);
310 } 310 }
311 311
312 return buffer.toString(); 312 return buffer.toString();
313 } 313 }
314 314
315 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed. 315 // TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed.
316 /// Splits [path] into its components using the current platform's 316 /// Splits [path] into its components using the current platform's
317 /// [separator]. Example: 317 /// [separator]. Example:
318 /// 318 ///
319 /// builder.split('path/to/foo'); // -> ['path', 'to', 'foo'] 319 /// builder.split('path/to/foo'); // -> ['path', 'to', 'foo']
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 /// "\" is the canonical one. 517 /// "\" is the canonical one.
518 final Pattern separatorPattern; 518 final Pattern separatorPattern;
519 519
520 /// The [Pattern] that can be used to match the root prefix of an absolute 520 /// The [Pattern] that can be used to match the root prefix of an absolute
521 /// path in this style. 521 /// path in this style.
522 final Pattern _rootPattern; 522 final Pattern _rootPattern;
523 523
524 /// Gets the root prefix of [path] if path is absolute. If [path] is relative, 524 /// Gets the root prefix of [path] if path is absolute. If [path] is relative,
525 /// returns `null`. 525 /// returns `null`.
526 String getRoot(String path) { 526 String getRoot(String path) {
527 var match = _rootPattern.firstMatch(path); 527 var matches = _rootPattern.allMatches(path).iterator();
528 if (match == null) return null; 528 if (!matches.hasNext) return null;
529 return match[0]; 529 return matches.next()[0];
530 } 530 }
531 531
532 String toString() => name; 532 String toString() => name;
533 } 533 }
534 534
535 // TODO(rnystrom): Make this public? 535 // TODO(rnystrom): Make this public?
536 class _ParsedPath { 536 class _ParsedPath {
537 /// The [Style] that was used to parse this path. 537 /// The [Style] that was used to parse this path.
538 Style style; 538 Style style;
539 539
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 642
643 var lastDot = file.lastIndexOf('.'); 643 var lastDot = file.lastIndexOf('.');
644 644
645 // If there is no dot, or it's the first character, like '.bashrc', it 645 // If there is no dot, or it's the first character, like '.bashrc', it
646 // doesn't count. 646 // doesn't count.
647 if (lastDot <= 0) return [file, '']; 647 if (lastDot <= 0) return [file, ''];
648 648
649 return [file.substring(0, lastDot), file.substring(lastDot)]; 649 return [file.substring(0, lastDot), file.substring(lastDot)];
650 } 650 }
651 } 651 }
OLDNEW
« utils/pub/http.dart ('K') | « utils/pub/http.dart ('k') | utils/pub/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698