| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/i18n/char_iterator.h" | 9 #include "base/i18n/char_iterator.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 continue; | 132 continue; |
| 133 | 133 |
| 134 int32_t months_count; | 134 int32_t months_count; |
| 135 const icu::UnicodeString* months = | 135 const icu::UnicodeString* months = |
| 136 format_symbols.getShortMonths(months_count); | 136 format_symbols.getShortMonths(months_count); |
| 137 | 137 |
| 138 // Loop over all abbreviated month names in given locale. | 138 // Loop over all abbreviated month names in given locale. |
| 139 // An alternative solution (to parse |text| in given locale) is more | 139 // An alternative solution (to parse |text| in given locale) is more |
| 140 // lenient, and may accept more than we want even with setLenient(false). | 140 // lenient, and may accept more than we want even with setLenient(false). |
| 141 for (int32_t month = 0; month < months_count; month++) { | 141 for (int32_t month = 0; month < months_count; month++) { |
| 142 if (months[month].caseCompare(unicode_text, 0) == 0) { | 142 // Compare (case-insensitive), but just first three characters. Sometimes |
| 143 // ICU returns longer strings (for example for Russian locale), and in FTP |
| 144 // listings they are abbreviated to just three characters. |
| 145 // Note: ICU may also return strings shorter than three characters, |
| 146 // and those also should be accepted. |
| 147 if (months[month].caseCompare(0, 3, unicode_text, 0) == 0) { |
| 143 *number = month + 1; | 148 *number = month + 1; |
| 144 return true; | 149 return true; |
| 145 } | 150 } |
| 146 } | 151 } |
| 147 } | 152 } |
| 148 | 153 |
| 149 return false; | 154 return false; |
| 150 } | 155 } |
| 151 | 156 |
| 152 // static | 157 // static |
| 153 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, | 158 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, |
| 154 const string16& rest, | 159 const string16& rest, |
| 155 const base::Time& current_time, | 160 const base::Time& current_time, |
| 156 base::Time* result) { | 161 base::Time* result) { |
| 157 base::Time::Exploded time_exploded = { 0 }; | 162 base::Time::Exploded time_exploded = { 0 }; |
| 158 | 163 |
| 159 if (!AbbreviatedMonthToNumber(month, &time_exploded.month)) | 164 if (!AbbreviatedMonthToNumber(month, &time_exploded.month)) |
| 160 return false; | 165 return false; |
| 161 | 166 |
| 162 if (!base::StringToInt(day, &time_exploded.day_of_month)) | 167 if (!base::StringToInt(day, &time_exploded.day_of_month)) |
| 163 return false; | 168 return false; |
| 169 if (time_exploded.day_of_month > 31) |
| 170 return false; |
| 164 | 171 |
| 165 if (!base::StringToInt(rest, &time_exploded.year)) { | 172 if (!base::StringToInt(rest, &time_exploded.year)) { |
| 166 // Maybe it's time. Does it look like time (HH:MM)? | 173 // Maybe it's time. Does it look like time (HH:MM)? |
| 167 if (rest.length() == 5 && rest[2] == ':') { | 174 if (rest.length() == 5 && rest[2] == ':') { |
| 168 if (!base::StringToInt(rest.begin(), | 175 if (!base::StringToInt(rest.begin(), |
| 169 rest.begin() + 2, | 176 rest.begin() + 2, |
| 170 &time_exploded.hour)) | 177 &time_exploded.hour)) |
| 171 return false; | 178 return false; |
| 172 | 179 |
| 173 if (!base::StringToInt(rest.begin() + 3, | 180 if (!base::StringToInt(rest.begin() + 3, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 while (!iter.end() && !u_isspace(iter.get())) | 230 while (!iter.end() && !u_isspace(iter.get())) |
| 224 iter.Advance(); | 231 iter.Advance(); |
| 225 } | 232 } |
| 226 | 233 |
| 227 string16 result(text.substr(iter.array_pos())); | 234 string16 result(text.substr(iter.array_pos())); |
| 228 TrimWhitespace(result, TRIM_ALL, &result); | 235 TrimWhitespace(result, TRIM_ALL, &result); |
| 229 return result; | 236 return result; |
| 230 } | 237 } |
| 231 | 238 |
| 232 } // namespace | 239 } // namespace |
| OLD | NEW |