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 // File utilities that use the ICU library go in this file. | 5 // File utilities that use the ICU library go in this file. |
6 | 6 |
7 #include "base/i18n/file_util_icu.h" | 7 #include "base/i18n/file_util_icu.h" |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return IllegalCharacters::GetInstance()->containsNone(file_name); | 90 return IllegalCharacters::GetInstance()->containsNone(file_name); |
91 } | 91 } |
92 | 92 |
93 void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name, | 93 void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name, |
94 char replace_char) { | 94 char replace_char) { |
95 DCHECK(file_name); | 95 DCHECK(file_name); |
96 | 96 |
97 DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char))); | 97 DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char))); |
98 | 98 |
99 // Remove leading and trailing whitespace. | 99 // Remove leading and trailing whitespace. |
100 TrimWhitespace(*file_name, TRIM_ALL, file_name); | 100 base::TrimWhitespace(*file_name, base::TRIM_ALL, file_name); |
101 | 101 |
102 IllegalCharacters* illegal = IllegalCharacters::GetInstance(); | 102 IllegalCharacters* illegal = IllegalCharacters::GetInstance(); |
103 int cursor = 0; // The ICU macros expect an int. | 103 int cursor = 0; // The ICU macros expect an int. |
104 while (cursor < static_cast<int>(file_name->size())) { | 104 while (cursor < static_cast<int>(file_name->size())) { |
105 int char_begin = cursor; | 105 int char_begin = cursor; |
106 uint32 code_point; | 106 uint32 code_point; |
107 #if defined(OS_MACOSX) | 107 #if defined(OS_MACOSX) |
108 // Mac uses UTF-8 encoding for filenames. | 108 // Mac uses UTF-8 encoding for filenames. |
109 U8_NEXT(file_name->data(), cursor, static_cast<int>(file_name->length()), | 109 U8_NEXT(file_name->data(), cursor, static_cast<int>(file_name->length()), |
110 code_point); | 110 code_point); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 std::string normalized_str; | 165 std::string normalized_str; |
166 if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(), | 166 if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(), |
167 base::kCodepageUTF8, | 167 base::kCodepageUTF8, |
168 &normalized_str)) { | 168 &normalized_str)) { |
169 *file_name = file_name->DirName().Append(base::FilePath(normalized_str)); | 169 *file_name = file_name->DirName().Append(base::FilePath(normalized_str)); |
170 } | 170 } |
171 #endif | 171 #endif |
172 } | 172 } |
173 | 173 |
174 } // namespace | 174 } // namespace |
OLD | NEW |