OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_I18N_FILE_UTIL_ICU_H_ | 5 #ifndef BASE_I18N_FILE_UTIL_ICU_H_ |
6 #define BASE_I18N_FILE_UTIL_ICU_H_ | 6 #define BASE_I18N_FILE_UTIL_ICU_H_ |
7 | 7 |
8 // File utilities that use the ICU library go in this file. | 8 // File utilities that use the ICU library go in this file. |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/i18n/base_i18n_export.h" | 11 #include "base/i18n/base_i18n_export.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 namespace i18n { | 15 namespace i18n { |
16 | 16 |
17 // Returns true if file_name does not have any illegal character. The input | 17 // Returns true if file_name does not have any illegal character. The input |
18 // param has the same restriction as that for ReplaceIllegalCharacters. | 18 // param has the same restriction as that for ReplaceIllegalCharacters. |
19 BASE_I18N_EXPORT bool IsFilenameLegal(const string16& file_name); | 19 BASE_I18N_EXPORT bool IsFilenameLegal(const string16& file_name); |
20 | 20 |
21 // Replaces characters in 'file_name' that are illegal for file names with | 21 // Replaces characters in |file_name| that are illegal for file names with |
22 // 'replace_char'. 'file_name' must not be a full or relative path, but just the | 22 // |replace_char|. |file_name| must not be a full or relative path, but just the |
23 // file name component (since slashes are considered illegal). Any leading or | 23 // file name component (since slashes are considered illegal). Any leading or |
24 // trailing whitespace in 'file_name' is removed. | 24 // trailing whitespace or periods in |file_name| is also replaced with the |
| 25 // |replace_char|. |
| 26 // |
25 // Example: | 27 // Example: |
26 // file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when | 28 // "bad:file*name?.txt" will be turned into "bad_file_name_.txt" when |
27 // 'replace_char' is '-'. | 29 // |replace_char| is '_'. |
| 30 // |
| 31 // Warning: Do not use this function as the sole means of sanitizing a filename. |
| 32 // While the resulting filename itself would be legal, it doesn't necessarily |
| 33 // mean that the file will behave safely. On Windows, certain reserved names |
| 34 // refer to devices rather than files (E.g. LPT1), and some filenames could be |
| 35 // interpreted as shell namespace extensions (E.g. Foo.{<GUID>}). |
| 36 // |
| 37 // TODO(asanka): Move full filename sanitization logic here. |
28 BASE_I18N_EXPORT void ReplaceIllegalCharactersInPath( | 38 BASE_I18N_EXPORT void ReplaceIllegalCharactersInPath( |
29 FilePath::StringType* file_name, | 39 FilePath::StringType* file_name, |
30 char replace_char); | 40 char replace_char); |
31 | 41 |
32 // Compares two filenames using the current locale information. This can be | 42 // Compares two filenames using the current locale information. This can be |
33 // used to sort directory listings. It behaves like "operator<" for use in | 43 // used to sort directory listings. It behaves like "operator<" for use in |
34 // std::sort. | 44 // std::sort. |
35 BASE_I18N_EXPORT bool LocaleAwareCompareFilenames(const FilePath& a, | 45 BASE_I18N_EXPORT bool LocaleAwareCompareFilenames(const FilePath& a, |
36 const FilePath& b); | 46 const FilePath& b); |
37 | 47 |
38 // Calculates the canonical file-system representation of |file_name| base name. | 48 // Calculates the canonical file-system representation of |file_name| base name. |
39 // Modifies |file_name| in place. No-op if not on ChromeOS. | 49 // Modifies |file_name| in place. No-op if not on ChromeOS. |
40 BASE_I18N_EXPORT void NormalizeFileNameEncoding(FilePath* file_name); | 50 BASE_I18N_EXPORT void NormalizeFileNameEncoding(FilePath* file_name); |
41 | 51 |
42 } // namespace i18n | 52 } // namespace i18n |
43 } // namespace base | 53 } // namespace base |
44 | 54 |
45 #endif // BASE_I18N_FILE_UTIL_ICU_H_ | 55 #endif // BASE_I18N_FILE_UTIL_ICU_H_ |
OLD | NEW |