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

Side by Side Diff: frog/file_system.dart

Issue 10548047: Remove frog from the repository. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move test and update apidoc.gyp. Created 8 years, 6 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
« no previous file with comments | « frog/evaluator.dart ('k') | frog/file_system_dom.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /** Abstraction for file systems and utility functions to manipulate paths. */
6 #library('file_system');
7
8 /**
9 * Abstraction around file system access to work in a variety of different
10 * environments.
11 */
12 interface FileSystem {
13 String readAll(String filename);
14
15 void writeString(String outfile, String text);
16
17 bool fileExists(String filename);
18
19 void createDirectory(String path, [bool recursive]);
20 void removeDirectory(String path, [bool recursive]);
21 }
22
23 /**
24 * Replaces all back slashes (\) with forward slashes (/) in [path] and
25 * return the result.
26 */
27 String canonicalizePath(String path) {
28 return path.replaceAll('\\', '/');
29 }
30
31 /** Join [path1] to [path2]. */
32 String joinPaths(String path1, String path2) {
33 path1 = canonicalizePath(path1);
34 path2 = canonicalizePath(path2);
35
36 var pieces = path1.split('/');
37 for (var piece in path2.split('/')) {
38 if (piece == '..' && pieces.length > 0 && pieces.last() != '.'
39 && pieces.last() != '..') {
40 pieces.removeLast();
41 } else if (piece != '') {
42 if (pieces.length > 0 && pieces.last() == '.') {
43 pieces.removeLast();
44 }
45 pieces.add(piece);
46 }
47 }
48 return Strings.join(pieces, '/');
49 }
50
51 /** Returns the directory name for the [path]. */
52 String dirname(String path) {
53 path = canonicalizePath(path);
54
55 int lastSlash = path.lastIndexOf('/', path.length);
56 if (lastSlash == -1) {
57 return '.';
58 } else {
59 return path.substring(0, lastSlash);
60 }
61 }
62
63 /** Returns the file name without directory for the [path]. */
64 String basename(String path) {
65 path = canonicalizePath(path);
66
67 int lastSlash = path.lastIndexOf('/', path.length);
68 if (lastSlash == -1) {
69 return path;
70 } else {
71 return path.substring(lastSlash + 1);
72 }
73 }
OLDNEW
« no previous file with comments | « frog/evaluator.dart ('k') | frog/file_system_dom.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698