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

Side by Side Diff: base/i18n/file_util_icu.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/files/scoped_file.h ('k') | base/i18n/icu_string_conversions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory>
12
11 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
12 #include "base/i18n/icu_string_conversions.h" 14 #include "base/i18n/icu_string_conversions.h"
13 #include "base/i18n/string_compare.h" 15 #include "base/i18n/string_compare.h"
14 #include "base/logging.h" 16 #include "base/logging.h"
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/strings/sys_string_conversions.h" 20 #include "base/strings/sys_string_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 #include "third_party/icu/source/common/unicode/uniset.h" 23 #include "third_party/icu/source/common/unicode/uniset.h"
23 #include "third_party/icu/source/i18n/unicode/coll.h" 24 #include "third_party/icu/source/i18n/unicode/coll.h"
24 25
25 namespace base { 26 namespace base {
26 namespace i18n { 27 namespace i18n {
(...skipping 22 matching lines...) Expand all
49 } 50 }
50 51
51 private: 52 private:
52 friend class Singleton<IllegalCharacters>; 53 friend class Singleton<IllegalCharacters>;
53 friend struct DefaultSingletonTraits<IllegalCharacters>; 54 friend struct DefaultSingletonTraits<IllegalCharacters>;
54 55
55 IllegalCharacters(); 56 IllegalCharacters();
56 ~IllegalCharacters() { } 57 ~IllegalCharacters() { }
57 58
58 // set of characters considered invalid anywhere inside a filename. 59 // set of characters considered invalid anywhere inside a filename.
59 scoped_ptr<icu::UnicodeSet> illegal_anywhere_; 60 std::unique_ptr<icu::UnicodeSet> illegal_anywhere_;
60 61
61 // set of characters considered invalid at either end of a filename. 62 // set of characters considered invalid at either end of a filename.
62 scoped_ptr<icu::UnicodeSet> illegal_at_ends_; 63 std::unique_ptr<icu::UnicodeSet> illegal_at_ends_;
63 64
64 DISALLOW_COPY_AND_ASSIGN(IllegalCharacters); 65 DISALLOW_COPY_AND_ASSIGN(IllegalCharacters);
65 }; 66 };
66 67
67 IllegalCharacters::IllegalCharacters() { 68 IllegalCharacters::IllegalCharacters() {
68 UErrorCode everywhere_status = U_ZERO_ERROR; 69 UErrorCode everywhere_status = U_ZERO_ERROR;
69 UErrorCode ends_status = U_ZERO_ERROR; 70 UErrorCode ends_status = U_ZERO_ERROR;
70 // Control characters, formatting characters, non-characters, path separators, 71 // Control characters, formatting characters, non-characters, path separators,
71 // and some printable ASCII characters regarded as dangerous ('"*/:<>?\\'). 72 // and some printable ASCII characters regarded as dangerous ('"*/:<>?\\').
72 // See http://blogs.msdn.com/michkap/archive/2006/11/03/941420.aspx 73 // See http://blogs.msdn.com/michkap/archive/2006/11/03/941420.aspx
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // character again. 143 // character again.
143 cursor = char_begin + 1; 144 cursor = char_begin + 1;
144 } 145 }
145 } 146 }
146 } 147 }
147 148
148 bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { 149 bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) {
149 UErrorCode error_code = U_ZERO_ERROR; 150 UErrorCode error_code = U_ZERO_ERROR;
150 // Use the default collator. The default locale should have been properly 151 // Use the default collator. The default locale should have been properly
151 // set by the time this constructor is called. 152 // set by the time this constructor is called.
152 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); 153 std::unique_ptr<icu::Collator> collator(
154 icu::Collator::createInstance(error_code));
153 DCHECK(U_SUCCESS(error_code)); 155 DCHECK(U_SUCCESS(error_code));
154 // Make it case-sensitive. 156 // Make it case-sensitive.
155 collator->setStrength(icu::Collator::TERTIARY); 157 collator->setStrength(icu::Collator::TERTIARY);
156 158
157 #if defined(OS_WIN) 159 #if defined(OS_WIN)
158 return CompareString16WithCollator(*collator, WideToUTF16(a.value()), 160 return CompareString16WithCollator(*collator, WideToUTF16(a.value()),
159 WideToUTF16(b.value())) == UCOL_LESS; 161 WideToUTF16(b.value())) == UCOL_LESS;
160 162
161 #elif defined(OS_POSIX) 163 #elif defined(OS_POSIX)
162 // On linux, the file system encoding is not defined. We assume 164 // On linux, the file system encoding is not defined. We assume
(...skipping 12 matching lines...) Expand all
175 if (ConvertToUtf8AndNormalize(file_name->BaseName().value(), 177 if (ConvertToUtf8AndNormalize(file_name->BaseName().value(),
176 kCodepageUTF8, 178 kCodepageUTF8,
177 &normalized_str)) { 179 &normalized_str)) {
178 *file_name = file_name->DirName().Append(FilePath(normalized_str)); 180 *file_name = file_name->DirName().Append(FilePath(normalized_str));
179 } 181 }
180 #endif 182 #endif
181 } 183 }
182 184
183 } // namespace i18n 185 } // namespace i18n
184 } // namespace base 186 } // namespace base
OLDNEW
« no previous file with comments | « base/files/scoped_file.h ('k') | base/i18n/icu_string_conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698