OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <fnmatch.h> | 10 #include <fnmatch.h> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "unicode/coll.h" | 33 #include "unicode/coll.h" |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 class LocaleAwareComparator { | 37 class LocaleAwareComparator { |
38 public: | 38 public: |
39 LocaleAwareComparator() { | 39 LocaleAwareComparator() { |
40 UErrorCode error_code = U_ZERO_ERROR; | 40 UErrorCode error_code = U_ZERO_ERROR; |
41 // Use the default collator. The default locale should have been properly | 41 // Use the default collator. The default locale should have been properly |
42 // set by the time this constructor is called. | 42 // set by the time this constructor is called. |
43 collator_.reset(Collator::createInstance(error_code)); | 43 collator_.reset(icu::Collator::createInstance(error_code)); |
44 DCHECK(U_SUCCESS(error_code)); | 44 DCHECK(U_SUCCESS(error_code)); |
45 // Make it case-sensitive. | 45 // Make it case-sensitive. |
46 collator_->setStrength(Collator::TERTIARY); | 46 collator_->setStrength(icu::Collator::TERTIARY); |
47 // Note: We do not set UCOL_NORMALIZATION_MODE attribute. In other words, we | 47 // Note: We do not set UCOL_NORMALIZATION_MODE attribute. In other words, we |
48 // do not pay performance penalty to guarantee sort order correctness for | 48 // do not pay performance penalty to guarantee sort order correctness for |
49 // non-FCD (http://unicode.org/notes/tn5/#FCD) file names. This should be a | 49 // non-FCD (http://unicode.org/notes/tn5/#FCD) file names. This should be a |
50 // reasonable tradeoff because such file names should be rare and the sort | 50 // reasonable tradeoff because such file names should be rare and the sort |
51 // order doesn't change much anyway. | 51 // order doesn't change much anyway. |
52 } | 52 } |
53 | 53 |
54 // Note: A similar function is available in l10n_util. | 54 // Note: A similar function is available in l10n_util. |
55 // We cannot use it because base should not depend on l10n_util. | 55 // We cannot use it because base should not depend on l10n_util. |
56 // TODO(yuzo): Move some of l10n_util to base. | 56 // TODO(yuzo): Move some of l10n_util to base. |
57 int Compare(const string16& a, const string16& b) { | 57 int Compare(const string16& a, const string16& b) { |
58 // We are not sure if Collator::compare is thread-safe. | 58 // We are not sure if Collator::compare is thread-safe. |
59 // Use an AutoLock just in case. | 59 // Use an AutoLock just in case. |
60 AutoLock auto_lock(lock_); | 60 AutoLock auto_lock(lock_); |
61 | 61 |
62 UErrorCode error_code = U_ZERO_ERROR; | 62 UErrorCode error_code = U_ZERO_ERROR; |
63 UCollationResult result = collator_->compare( | 63 UCollationResult result = collator_->compare( |
64 static_cast<const UChar*>(a.c_str()), | 64 static_cast<const UChar*>(a.c_str()), |
65 static_cast<int>(a.length()), | 65 static_cast<int>(a.length()), |
66 static_cast<const UChar*>(b.c_str()), | 66 static_cast<const UChar*>(b.c_str()), |
67 static_cast<int>(b.length()), | 67 static_cast<int>(b.length()), |
68 error_code); | 68 error_code); |
69 DCHECK(U_SUCCESS(error_code)); | 69 DCHECK(U_SUCCESS(error_code)); |
70 return result; | 70 return result; |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 scoped_ptr<Collator> collator_; | 74 scoped_ptr<icu::Collator> collator_; |
75 Lock lock_; | 75 Lock lock_; |
76 friend struct DefaultSingletonTraits<LocaleAwareComparator>; | 76 friend struct DefaultSingletonTraits<LocaleAwareComparator>; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(LocaleAwareComparator); | 78 DISALLOW_COPY_AND_ASSIGN(LocaleAwareComparator); |
79 }; | 79 }; |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 namespace file_util { | 83 namespace file_util { |
84 | 84 |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 munmap(data_, length_); | 721 munmap(data_, length_); |
722 if (file_ != -1) | 722 if (file_ != -1) |
723 close(file_); | 723 close(file_); |
724 | 724 |
725 data_ = NULL; | 725 data_ = NULL; |
726 length_ = 0; | 726 length_ = 0; |
727 file_ = -1; | 727 file_ = -1; |
728 } | 728 } |
729 | 729 |
730 } // namespace file_util | 730 } // namespace file_util |
OLD | NEW |