| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/ftp/ftp_util.h" | 5 #include "net/ftp/ftp_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 return result; | 126 return result; |
| 127 } | 127 } |
| 128 | 128 |
| 129 namespace { | 129 namespace { |
| 130 | 130 |
| 131 // Lazy-initialized map of abbreviated month names. | 131 // Lazy-initialized map of abbreviated month names. |
| 132 class AbbreviatedMonthsMap { | 132 class AbbreviatedMonthsMap { |
| 133 public: | 133 public: |
| 134 static AbbreviatedMonthsMap* GetInstance() { | 134 static AbbreviatedMonthsMap* GetInstance() { |
| 135 return Singleton<AbbreviatedMonthsMap>::get(); | 135 return base::Singleton<AbbreviatedMonthsMap>::get(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Converts abbreviated month name |text| to its number (in range 1-12). | 138 // Converts abbreviated month name |text| to its number (in range 1-12). |
| 139 // On success returns true and puts the number in |number|. | 139 // On success returns true and puts the number in |number|. |
| 140 bool GetMonthNumber(const base::string16& text, int* number) { | 140 bool GetMonthNumber(const base::string16& text, int* number) { |
| 141 // Ignore the case of the month names. The simplest way to handle that | 141 // Ignore the case of the month names. The simplest way to handle that |
| 142 // is to make everything lowercase. | 142 // is to make everything lowercase. |
| 143 base::string16 text_lower(base::i18n::ToLower(text)); | 143 base::string16 text_lower(base::i18n::ToLower(text)); |
| 144 | 144 |
| 145 if (map_.find(text_lower) == map_.end()) | 145 if (map_.find(text_lower) == map_.end()) |
| 146 return false; | 146 return false; |
| 147 | 147 |
| 148 *number = map_[text_lower]; | 148 *number = map_[text_lower]; |
| 149 return true; | 149 return true; |
| 150 } | 150 } |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 friend struct DefaultSingletonTraits<AbbreviatedMonthsMap>; | 153 friend struct base::DefaultSingletonTraits<AbbreviatedMonthsMap>; |
| 154 | 154 |
| 155 // Constructor, initializes the map based on ICU data. It is much faster | 155 // Constructor, initializes the map based on ICU data. It is much faster |
| 156 // to do that just once. | 156 // to do that just once. |
| 157 AbbreviatedMonthsMap() { | 157 AbbreviatedMonthsMap() { |
| 158 int32_t locales_count; | 158 int32_t locales_count; |
| 159 const icu::Locale* locales = | 159 const icu::Locale* locales = |
| 160 icu::DateFormat::getAvailableLocales(locales_count); | 160 icu::DateFormat::getAvailableLocales(locales_count); |
| 161 | 161 |
| 162 for (int32_t locale = 0; locale < locales_count; locale++) { | 162 for (int32_t locale = 0; locale < locales_count; locale++) { |
| 163 UErrorCode status(U_ZERO_ERROR); | 163 UErrorCode status(U_ZERO_ERROR); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 while (!iter.end() && !u_isspace(iter.get())) | 366 while (!iter.end() && !u_isspace(iter.get())) |
| 367 iter.Advance(); | 367 iter.Advance(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 base::string16 result(text.substr(iter.array_pos())); | 370 base::string16 result(text.substr(iter.array_pos())); |
| 371 base::TrimWhitespace(result, base::TRIM_ALL, &result); | 371 base::TrimWhitespace(result, base::TRIM_ALL, &result); |
| 372 return result; | 372 return result; |
| 373 } | 373 } |
| 374 | 374 |
| 375 } // namespace | 375 } // namespace |
| OLD | NEW |