Chromium Code Reviews| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 continue; | 130 continue; |
| 131 | 131 |
| 132 int32_t months_count; | 132 int32_t months_count; |
| 133 const icu::UnicodeString* months = | 133 const icu::UnicodeString* months = |
| 134 format_symbols.getShortMonths(months_count); | 134 format_symbols.getShortMonths(months_count); |
| 135 | 135 |
| 136 // Loop over all abbreviated month names in given locale. | 136 // Loop over all abbreviated month names in given locale. |
| 137 // An alternative solution (to parse |text| in given locale) is more | 137 // An alternative solution (to parse |text| in given locale) is more |
| 138 // lenient, and may accept more than we want even with setLenient(false). | 138 // lenient, and may accept more than we want even with setLenient(false). |
| 139 for (int32_t month = 0; month < months_count; month++) { | 139 for (int32_t month = 0; month < months_count; month++) { |
| 140 if (months[month].caseCompare(unicode_text, 0) == 0) { | 140 // Compare (case-insensitive), but just first three characters. Sometimes |
| 141 // ICU returns longer strings (for example for Russian locale), and in FTP | |
| 142 // listings they are abbreviated to just three characters. | |
| 143 if (months[month].caseCompare(0, 3, unicode_text, 0) == 0) { | |
|
gavinp
2011/03/30 17:14:23
NIT: maybe worth noting that caseCompare works whe
Paweł Hajdan Jr.
2011/04/01 15:55:27
Done.
| |
| 141 *number = month + 1; | 144 *number = month + 1; |
| 142 return true; | 145 return true; |
| 143 } | 146 } |
| 144 } | 147 } |
| 145 } | 148 } |
| 146 | 149 |
| 147 return false; | 150 return false; |
| 148 } | 151 } |
| 149 | 152 |
| 150 // static | 153 // static |
| 151 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, | 154 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, |
| 152 const string16& rest, | 155 const string16& rest, |
| 153 const base::Time& current_time, | 156 const base::Time& current_time, |
| 154 base::Time* result) { | 157 base::Time* result) { |
| 155 base::Time::Exploded time_exploded = { 0 }; | 158 base::Time::Exploded time_exploded = { 0 }; |
| 156 | 159 |
| 157 if (!AbbreviatedMonthToNumber(month, &time_exploded.month)) | 160 if (!AbbreviatedMonthToNumber(month, &time_exploded.month)) |
| 158 return false; | 161 return false; |
| 159 | 162 |
| 160 if (!base::StringToInt(day, &time_exploded.day_of_month)) | 163 if (!base::StringToInt(day, &time_exploded.day_of_month)) |
| 161 return false; | 164 return false; |
| 165 if (time_exploded.day_of_month > 31) | |
| 166 return false; | |
| 162 | 167 |
| 163 if (!base::StringToInt(rest, &time_exploded.year)) { | 168 if (!base::StringToInt(rest, &time_exploded.year)) { |
| 164 // Maybe it's time. Does it look like time (HH:MM)? | 169 // Maybe it's time. Does it look like time (HH:MM)? |
| 165 if (rest.length() == 5 && rest[2] == ':') { | 170 if (rest.length() == 5 && rest[2] == ':') { |
| 166 if (!base::StringToInt(rest.begin(), | 171 if (!base::StringToInt(rest.begin(), |
| 167 rest.begin() + 2, | 172 rest.begin() + 2, |
| 168 &time_exploded.hour)) | 173 &time_exploded.hour)) |
| 169 return false; | 174 return false; |
| 170 | 175 |
| 171 if (!base::StringToInt(rest.begin() + 3, | 176 if (!base::StringToInt(rest.begin() + 3, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 while (pos < text.length() && !isspace(text[pos])) | 225 while (pos < text.length() && !isspace(text[pos])) |
| 221 pos++; | 226 pos++; |
| 222 } | 227 } |
| 223 | 228 |
| 224 string16 result(text.substr(pos)); | 229 string16 result(text.substr(pos)); |
| 225 TrimWhitespace(result, TRIM_ALL, &result); | 230 TrimWhitespace(result, TRIM_ALL, &result); |
| 226 return result; | 231 return result; |
| 227 } | 232 } |
| 228 | 233 |
| 229 } // namespace | 234 } // namespace |
| OLD | NEW |