file_util_icu.h 2.4 KB

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