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

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

Issue 7590011: FTP: add directory listing parser for OS/2 format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 9 years, 4 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
« no previous file with comments | « net/ftp/ftp_util.h ('k') | net/ftp/ftp_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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"
11 #include "base/i18n/char_iterator.h" 11 #include "base/i18n/char_iterator.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_split.h"
15 #include "base/string_tokenizer.h" 16 #include "base/string_tokenizer.h"
16 #include "base/string_util.h" 17 #include "base/string_util.h"
17 #include "base/time.h" 18 #include "base/time.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "unicode/datefmt.h" 20 #include "unicode/datefmt.h"
20 #include "unicode/dtfmtsym.h" 21 #include "unicode/dtfmtsym.h"
21 #include "unicode/uchar.h" 22 #include "unicode/uchar.h"
22 23
23 // For examples of Unix<->VMS path conversions, see the unit test file. On VMS 24 // For examples of Unix<->VMS path conversions, see the unit test file. On VMS
24 // a path looks differently depending on whether it's a file or directory. 25 // a path looks differently depending on whether it's a file or directory.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 time_exploded.year = current_exploded.year; 249 time_exploded.year = current_exploded.year;
249 } 250 }
250 } 251 }
251 252
252 // We don't know the time zone of the listing, so just use local time. 253 // We don't know the time zone of the listing, so just use local time.
253 *result = base::Time::FromLocalExploded(time_exploded); 254 *result = base::Time::FromLocalExploded(time_exploded);
254 return true; 255 return true;
255 } 256 }
256 257
257 // static 258 // static
259 bool FtpUtil::WindowsDateListingToTime(const string16& date,
260 const string16& time,
261 base::Time* result) {
262 base::Time::Exploded time_exploded = { 0 };
263
264 // Date should be in format MM-DD-YY[YY].
265 std::vector<string16> date_parts;
266 base::SplitString(date, '-', &date_parts);
267 if (date_parts.size() != 3)
268 return false;
269 if (!base::StringToInt(date_parts[0], &time_exploded.month))
270 return false;
271 if (!base::StringToInt(date_parts[1], &time_exploded.day_of_month))
272 return false;
273 if (!base::StringToInt(date_parts[2], &time_exploded.year))
274 return false;
275 if (time_exploded.year < 0)
276 return false;
277 // If year has only two digits then assume that 00-79 is 2000-2079,
278 // and 80-99 is 1980-1999.
279 if (time_exploded.year < 80)
280 time_exploded.year += 2000;
281 else if (time_exploded.year < 100)
282 time_exploded.year += 1900;
283
284 // Time should be in format HH:MM[(AM|PM)]
285 if (time.length() < 5)
286 return false;
287
288 std::vector<string16> time_parts;
289 base::SplitString(time.substr(0, 5), ':', &time_parts);
290 if (time_parts.size() != 2)
291 return false;
292 if (!base::StringToInt(time_parts[0], &time_exploded.hour))
293 return false;
294 if (!base::StringToInt(time_parts[1], &time_exploded.minute))
295 return false;
296 if (!time_exploded.HasValidValues())
297 return false;
298
299 if (time.length() > 5) {
300 if (time.length() != 7)
301 return false;
302 string16 am_or_pm(time.substr(5, 2));
303 if (EqualsASCII(am_or_pm, "PM")) {
304 if (time_exploded.hour < 12)
305 time_exploded.hour += 12;
306 } else if (EqualsASCII(am_or_pm, "AM")) {
307 if (time_exploded.hour == 12)
308 time_exploded.hour = 0;
309 } else {
310 return false;
311 }
312 }
313
314 // We don't know the time zone of the server, so just use local time.
315 *result = base::Time::FromLocalExploded(time_exploded);
316 return true;
317 }
318
319 // static
258 string16 FtpUtil::GetStringPartAfterColumns(const string16& text, int columns) { 320 string16 FtpUtil::GetStringPartAfterColumns(const string16& text, int columns) {
259 base::i18n::UTF16CharIterator iter(&text); 321 base::i18n::UTF16CharIterator iter(&text);
260 322
261 // TODO(jshin): Is u_isspace the right function to use here? 323 // TODO(jshin): Is u_isspace the right function to use here?
262 for (int i = 0; i < columns; i++) { 324 for (int i = 0; i < columns; i++) {
263 // Skip the leading whitespace. 325 // Skip the leading whitespace.
264 while (!iter.end() && u_isspace(iter.get())) 326 while (!iter.end() && u_isspace(iter.get()))
265 iter.Advance(); 327 iter.Advance();
266 328
267 // Skip the actual text of i-th column. 329 // Skip the actual text of i-th column.
268 while (!iter.end() && !u_isspace(iter.get())) 330 while (!iter.end() && !u_isspace(iter.get()))
269 iter.Advance(); 331 iter.Advance();
270 } 332 }
271 333
272 string16 result(text.substr(iter.array_pos())); 334 string16 result(text.substr(iter.array_pos()));
273 TrimWhitespace(result, TRIM_ALL, &result); 335 TrimWhitespace(result, TRIM_ALL, &result);
274 return result; 336 return result;
275 } 337 }
276 338
277 } // namespace 339 } // namespace
OLDNEW
« no previous file with comments | « net/ftp/ftp_util.h ('k') | net/ftp/ftp_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698