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

Side by Side Diff: net/ftp/ftp_util.cc

Issue 6718043: FTP: Multiple fixes for localized directory listings: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trying to make things more clear Created 9 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 | Annotate | Revision Log
OLDNEW
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
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 // Note: ICU may also return strings shorter than three characters,
144 // and those also should be accepted.
145 if (months[month].caseCompare(0, 3, unicode_text, 0) == 0) {
141 *number = month + 1; 146 *number = month + 1;
142 return true; 147 return true;
143 } 148 }
144 } 149 }
145 } 150 }
146 151
147 return false; 152 return false;
148 } 153 }
149 154
150 // static 155 // static
151 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, 156 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day,
152 const string16& rest, 157 const string16& rest,
153 const base::Time& current_time, 158 const base::Time& current_time,
154 base::Time* result) { 159 base::Time* result) {
155 base::Time::Exploded time_exploded = { 0 }; 160 base::Time::Exploded time_exploded = { 0 };
156 161
157 if (!AbbreviatedMonthToNumber(month, &time_exploded.month)) 162 if (!AbbreviatedMonthToNumber(month, &time_exploded.month))
158 return false; 163 return false;
159 164
160 if (!base::StringToInt(day, &time_exploded.day_of_month)) 165 if (!base::StringToInt(day, &time_exploded.day_of_month))
161 return false; 166 return false;
167 if (time_exploded.day_of_month > 31)
168 return false;
162 169
163 if (!base::StringToInt(rest, &time_exploded.year)) { 170 if (!base::StringToInt(rest, &time_exploded.year)) {
164 // Maybe it's time. Does it look like time (HH:MM)? 171 // Maybe it's time. Does it look like time (HH:MM)?
165 if (rest.length() == 5 && rest[2] == ':') { 172 if (rest.length() == 5 && rest[2] == ':') {
166 if (!base::StringToInt(rest.begin(), 173 if (!base::StringToInt(rest.begin(),
167 rest.begin() + 2, 174 rest.begin() + 2,
168 &time_exploded.hour)) 175 &time_exploded.hour))
169 return false; 176 return false;
170 177
171 if (!base::StringToInt(rest.begin() + 3, 178 if (!base::StringToInt(rest.begin() + 3,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 while (pos < text.length() && !isspace(text[pos])) 227 while (pos < text.length() && !isspace(text[pos]))
221 pos++; 228 pos++;
222 } 229 }
223 230
224 string16 result(text.substr(pos)); 231 string16 result(text.substr(pos));
225 TrimWhitespace(result, TRIM_ALL, &result); 232 TrimWhitespace(result, TRIM_ALL, &result);
226 return result; 233 return result;
227 } 234 }
228 235
229 } // namespace 236 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698