OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <io.h> | 8 #include <io.h> |
9 #endif | 9 #endif |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <fstream> | 12 #include <fstream> |
13 | 13 |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 | 17 |
18 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
19 #include "base/sys_string_conversions.h" | 19 #include "base/sys_string_conversions.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.'); | 23 const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.'); |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 namespace file_util { | 27 namespace file_util { |
28 | 28 |
29 void PathComponents(const FilePath& path, | |
30 std::vector<FilePath::StringType>* components) { | |
31 DCHECK(components); | |
32 if (!components) | |
33 return; | |
34 | |
35 FilePath::StringType path_str = path.value(); | |
36 FilePath::StringType::size_type start = 0; | |
37 FilePath::StringType::size_type end = | |
38 path_str.find_first_of(FilePath::kSeparators); | |
39 | |
40 // If the path starts with a separator, add it to components. | |
41 if (end == start) { | |
42 components->push_back(FilePath::StringType(path_str, 0, 1)); | |
43 start = end + 1; | |
44 end = path_str.find_first_of(FilePath::kSeparators, start); | |
45 } | |
46 while (end != FilePath::StringType::npos) { | |
47 FilePath::StringType component = | |
48 FilePath::StringType(path_str, start, end - start); | |
49 components->push_back(component); | |
50 start = end + 1; | |
51 end = path_str.find_first_of(FilePath::kSeparators, start); | |
52 } | |
53 | |
54 components->push_back(FilePath::StringType(path_str, start)); | |
55 } | |
56 | |
57 bool EndsWithSeparator(const FilePath& path) { | 29 bool EndsWithSeparator(const FilePath& path) { |
58 FilePath::StringType value = path.value(); | 30 FilePath::StringType value = path.value(); |
59 if (value.empty()) | 31 if (value.empty()) |
60 return false; | 32 return false; |
61 | 33 |
62 return FilePath::IsSeparator(value[value.size() - 1]); | 34 return FilePath::IsSeparator(value[value.size() - 1]); |
63 } | 35 } |
64 | 36 |
65 bool EnsureEndsWithSeparator(FilePath* path) { | 37 bool EnsureEndsWithSeparator(FilePath* path) { |
66 if (!DirectoryExists(*path)) | 38 if (!DirectoryExists(*path)) |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 411 |
440 bool FileEnumerator::IsDot(const FilePath& path) { | 412 bool FileEnumerator::IsDot(const FilePath& path) { |
441 return FILE_PATH_LITERAL(".") == path.BaseName().value(); | 413 return FILE_PATH_LITERAL(".") == path.BaseName().value(); |
442 } | 414 } |
443 | 415 |
444 bool FileEnumerator::IsDotDot(const FilePath& path) { | 416 bool FileEnumerator::IsDotDot(const FilePath& path) { |
445 return FILE_PATH_LITERAL("..") == path.BaseName().value(); | 417 return FILE_PATH_LITERAL("..") == path.BaseName().value(); |
446 } | 418 } |
447 | 419 |
448 } // namespace | 420 } // namespace |
OLD | NEW |