OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/base/filename_util.h" | 5 #include "net/base/filename_util.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 bool replace_trailing) { | 24 bool replace_trailing) { |
25 const base::FilePath::CharType kReplace[] = FILE_PATH_LITERAL("-"); | 25 const base::FilePath::CharType kReplace[] = FILE_PATH_LITERAL("-"); |
26 if (filename->empty()) | 26 if (filename->empty()) |
27 return; | 27 return; |
28 if (replace_trailing) { | 28 if (replace_trailing) { |
29 // Handle CreateFile() stripping trailing dots and spaces on filenames | 29 // Handle CreateFile() stripping trailing dots and spaces on filenames |
30 // http://support.microsoft.com/kb/115827 | 30 // http://support.microsoft.com/kb/115827 |
31 size_t length = filename->size(); | 31 size_t length = filename->size(); |
32 size_t pos = filename->find_last_not_of(FILE_PATH_LITERAL(" .")); | 32 size_t pos = filename->find_last_not_of(FILE_PATH_LITERAL(" .")); |
33 filename->resize((pos == std::string::npos) ? 0 : (pos + 1)); | 33 filename->resize((pos == std::string::npos) ? 0 : (pos + 1)); |
| 34 #if defined(OS_WIN) |
34 base::TrimWhitespace(*filename, base::TRIM_TRAILING, filename); | 35 base::TrimWhitespace(*filename, base::TRIM_TRAILING, filename); |
| 36 #else |
| 37 base::TrimWhitespaceASCII(*filename, base::TRIM_TRAILING, filename); |
| 38 #endif |
| 39 |
35 if (filename->empty()) | 40 if (filename->empty()) |
36 return; | 41 return; |
37 size_t trimmed = length - filename->size(); | 42 size_t trimmed = length - filename->size(); |
38 if (trimmed) | 43 if (trimmed) |
39 filename->insert(filename->end(), trimmed, kReplace[0]); | 44 filename->insert(filename->end(), trimmed, kReplace[0]); |
40 } | 45 } |
41 base::TrimString(*filename, FILE_PATH_LITERAL("."), filename); | 46 base::TrimString(*filename, FILE_PATH_LITERAL("."), filename); |
42 if (filename->empty()) | 47 if (filename->empty()) |
43 return; | 48 return; |
44 // Replace any path information by changing path separators. | 49 // Replace any path information by changing path separators. |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 base::FilePath generated_name( | 281 base::FilePath generated_name( |
277 base::SysWideToNativeMB(base::UTF16ToWide(file_name))); | 282 base::SysWideToNativeMB(base::UTF16ToWide(file_name))); |
278 #endif | 283 #endif |
279 | 284 |
280 DCHECK(!generated_name.empty()); | 285 DCHECK(!generated_name.empty()); |
281 | 286 |
282 return generated_name; | 287 return generated_name; |
283 } | 288 } |
284 | 289 |
285 } // namespace net | 290 } // namespace net |
OLD | NEW |