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

Side by Side Diff: base/file_util.cc

Issue 7461132: base: Get rid of a deprecated version of file_util::GetFileExtensionFromPath(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 | « no previous file | base/file_util_deprecated.h » ('j') | base/file_util_deprecated.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
(...skipping 29 matching lines...) Expand all
40 if (EndsWithSeparator(*path)) 40 if (EndsWithSeparator(*path))
41 return true; 41 return true;
42 42
43 FilePath::StringType& path_str = 43 FilePath::StringType& path_str =
44 const_cast<FilePath::StringType&>(path->value()); 44 const_cast<FilePath::StringType&>(path->value());
45 path_str.append(&FilePath::kSeparators[0], 1); 45 path_str.append(&FilePath::kSeparators[0], 1);
46 46
47 return true; 47 return true;
48 } 48 }
49 49
50 FilePath::StringType GetFileExtensionFromPath(const FilePath& path) {
51 FilePath::StringType file_name = path.BaseName().value();
52 const FilePath::StringType::size_type last_dot =
53 file_name.rfind(kExtensionSeparator);
54 return FilePath::StringType(last_dot == FilePath::StringType::npos ?
55 FILE_PATH_LITERAL("") :
56 file_name, last_dot+1);
57 }
58
59 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) { 50 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) {
60 FilePath::StringType& value = 51 FilePath::StringType& value =
61 const_cast<FilePath::StringType&>(path->value()); 52 const_cast<FilePath::StringType&>(path->value());
62 53
63 const FilePath::StringType::size_type last_dot = 54 const FilePath::StringType::size_type last_dot =
64 value.rfind(kExtensionSeparator); 55 value.rfind(kExtensionSeparator);
65 const FilePath::StringType::size_type last_separator = 56 const FilePath::StringType::size_type last_separator =
66 value.find_last_of(FilePath::StringType(FilePath::kSeparators)); 57 value.find_last_of(FilePath::StringType(FilePath::kSeparators));
67 58
68 if (last_dot == FilePath::StringType::npos || 59 if (last_dot == FilePath::StringType::npos ||
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 bool CopyDirectory(const std::wstring& from_path, const std::wstring& to_path, 366 bool CopyDirectory(const std::wstring& from_path, const std::wstring& to_path,
376 bool recursive) { 367 bool recursive) {
377 return CopyDirectory(FilePath::FromWStringHack(from_path), 368 return CopyDirectory(FilePath::FromWStringHack(from_path),
378 FilePath::FromWStringHack(to_path), 369 FilePath::FromWStringHack(to_path),
379 recursive); 370 recursive);
380 } 371 }
381 bool Delete(const std::wstring& path, bool recursive) { 372 bool Delete(const std::wstring& path, bool recursive) {
382 return Delete(FilePath::FromWStringHack(path), recursive); 373 return Delete(FilePath::FromWStringHack(path), recursive);
383 } 374 }
384 std::wstring GetFileExtensionFromPath(const std::wstring& path) { 375 std::wstring GetFileExtensionFromPath(const std::wstring& path) {
385 FilePath::StringType extension = 376 std::wstring file_name = FilePath(path).BaseName().value();
386 GetFileExtensionFromPath(FilePath::FromWStringHack(path)); 377 const std::wstring::size_type last_dot = file_name.rfind(kExtensionSeparator);
387 return extension; 378 return std::wstring(last_dot == std::wstring::npos ? L""
379 : file_name, last_dot + 1);
388 } 380 }
389 FILE* OpenFile(const std::wstring& filename, const char* mode) { 381 FILE* OpenFile(const std::wstring& filename, const char* mode) {
390 return OpenFile(FilePath::FromWStringHack(filename), mode); 382 return OpenFile(FilePath::FromWStringHack(filename), mode);
391 } 383 }
392 int ReadFile(const std::wstring& filename, char* data, int size) { 384 int ReadFile(const std::wstring& filename, char* data, int size) {
393 return ReadFile(FilePath::FromWStringHack(filename), data, size); 385 return ReadFile(FilePath::FromWStringHack(filename), data, size);
394 } 386 }
395 int WriteFile(const std::wstring& filename, const char* data, int size) { 387 int WriteFile(const std::wstring& filename, const char* data, int size) {
396 return WriteFile(FilePath::FromWStringHack(filename), data, size); 388 return WriteFile(FilePath::FromWStringHack(filename), data, size);
397 } 389 }
398 #endif // OS_WIN 390 #endif // OS_WIN
399 391
400 /////////////////////////////////////////////// 392 ///////////////////////////////////////////////
401 // FileEnumerator 393 // FileEnumerator
402 // 394 //
403 // Note: the main logic is in file_util_<platform>.cc 395 // Note: the main logic is in file_util_<platform>.cc
404 396
405 bool FileEnumerator::ShouldSkip(const FilePath& path) { 397 bool FileEnumerator::ShouldSkip(const FilePath& path) {
406 FilePath::StringType basename = path.BaseName().value(); 398 FilePath::StringType basename = path.BaseName().value();
407 return IsDot(path) || (IsDotDot(path) && !(INCLUDE_DOT_DOT & file_type_)); 399 return IsDot(path) || (IsDotDot(path) && !(INCLUDE_DOT_DOT & file_type_));
408 } 400 }
409 401
410 } // namespace 402 } // namespace
OLDNEW
« no previous file with comments | « no previous file | base/file_util_deprecated.h » ('j') | base/file_util_deprecated.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698