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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 return true; | 289 return true; |
290 } | 290 } |
291 | 291 |
292 // static | 292 // static |
293 bool FtpUtil::WindowsDateListingToTime(const base::string16& date, | 293 bool FtpUtil::WindowsDateListingToTime(const base::string16& date, |
294 const base::string16& time, | 294 const base::string16& time, |
295 base::Time* result) { | 295 base::Time* result) { |
296 base::Time::Exploded time_exploded = { 0 }; | 296 base::Time::Exploded time_exploded = { 0 }; |
297 | 297 |
298 // Date should be in format MM-DD-YY[YY]. | 298 // Date should be in format MM-DD-YY[YY]. |
299 std::vector<base::string16> date_parts; | 299 std::vector<base::StringPiece16> date_parts = |
300 base::SplitString(date, '-', &date_parts); | 300 base::SplitStringPiece(date, base::ASCIIToUTF16("-"), |
| 301 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
301 if (date_parts.size() != 3) | 302 if (date_parts.size() != 3) |
302 return false; | 303 return false; |
303 if (!base::StringToInt(date_parts[0], &time_exploded.month)) | 304 if (!base::StringToInt(date_parts[0], &time_exploded.month)) |
304 return false; | 305 return false; |
305 if (!base::StringToInt(date_parts[1], &time_exploded.day_of_month)) | 306 if (!base::StringToInt(date_parts[1], &time_exploded.day_of_month)) |
306 return false; | 307 return false; |
307 if (!base::StringToInt(date_parts[2], &time_exploded.year)) | 308 if (!base::StringToInt(date_parts[2], &time_exploded.year)) |
308 return false; | 309 return false; |
309 if (time_exploded.year < 0) | 310 if (time_exploded.year < 0) |
310 return false; | 311 return false; |
311 // If year has only two digits then assume that 00-79 is 2000-2079, | 312 // If year has only two digits then assume that 00-79 is 2000-2079, |
312 // and 80-99 is 1980-1999. | 313 // and 80-99 is 1980-1999. |
313 if (time_exploded.year < 80) | 314 if (time_exploded.year < 80) |
314 time_exploded.year += 2000; | 315 time_exploded.year += 2000; |
315 else if (time_exploded.year < 100) | 316 else if (time_exploded.year < 100) |
316 time_exploded.year += 1900; | 317 time_exploded.year += 1900; |
317 | 318 |
318 // Time should be in format HH:MM[(AM|PM)] | 319 // Time should be in format HH:MM[(AM|PM)] |
319 if (time.length() < 5) | 320 if (time.length() < 5) |
320 return false; | 321 return false; |
321 | 322 |
322 std::vector<base::string16> time_parts; | 323 std::vector<base::StringPiece16> time_parts = base::SplitStringPiece( |
323 base::SplitString(time.substr(0, 5), ':', &time_parts); | 324 base::StringPiece16(time).substr(0, 5), base::ASCIIToUTF16(":"), |
| 325 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
324 if (time_parts.size() != 2) | 326 if (time_parts.size() != 2) |
325 return false; | 327 return false; |
326 if (!base::StringToInt(time_parts[0], &time_exploded.hour)) | 328 if (!base::StringToInt(time_parts[0], &time_exploded.hour)) |
327 return false; | 329 return false; |
328 if (!base::StringToInt(time_parts[1], &time_exploded.minute)) | 330 if (!base::StringToInt(time_parts[1], &time_exploded.minute)) |
329 return false; | 331 return false; |
330 if (!time_exploded.HasValidValues()) | 332 if (!time_exploded.HasValidValues()) |
331 return false; | 333 return false; |
332 | 334 |
333 if (time.length() > 5) { | 335 if (time.length() > 5) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 while (!iter.end() && !u_isspace(iter.get())) | 367 while (!iter.end() && !u_isspace(iter.get())) |
366 iter.Advance(); | 368 iter.Advance(); |
367 } | 369 } |
368 | 370 |
369 base::string16 result(text.substr(iter.array_pos())); | 371 base::string16 result(text.substr(iter.array_pos())); |
370 base::TrimWhitespace(result, base::TRIM_ALL, &result); | 372 base::TrimWhitespace(result, base::TRIM_ALL, &result); |
371 return result; | 373 return result; |
372 } | 374 } |
373 | 375 |
374 } // namespace | 376 } // namespace |
OLD | NEW |