Index: net/ftp/ftp_directory_listing_parser_windows.cc |
diff --git a/net/ftp/ftp_directory_listing_parser_windows.cc b/net/ftp/ftp_directory_listing_parser_windows.cc |
index ef733d5e019231d5828c82cea7fdf0910eef6d82..2317fa3a6ccd228db29e7ab4029f83c805025717 100644 |
--- a/net/ftp/ftp_directory_listing_parser_windows.cc |
+++ b/net/ftp/ftp_directory_listing_parser_windows.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -9,6 +9,8 @@ |
#include "base/string_number_conversions.h" |
#include "base/string_split.h" |
#include "base/string_util.h" |
+#include "base/time.h" |
+#include "net/ftp/ftp_directory_listing_parser.h" |
#include "net/ftp/ftp_util.h" |
namespace { |
@@ -72,68 +74,55 @@ bool WindowsDateListingToTime(const std::vector<string16>& columns, |
namespace net { |
-FtpDirectoryListingParserWindows::FtpDirectoryListingParserWindows() {} |
- |
-FtpDirectoryListingParserWindows::~FtpDirectoryListingParserWindows() {} |
- |
-FtpServerType FtpDirectoryListingParserWindows::GetServerType() const { |
- return SERVER_WINDOWS; |
-} |
- |
-bool FtpDirectoryListingParserWindows::ConsumeLine(const string16& line) { |
- std::vector<string16> columns; |
- base::SplitString(CollapseWhitespace(line, false), ' ', &columns); |
- |
- // Every line of the listing consists of the following: |
- // |
- // 1. date |
- // 2. time |
- // 3. size in bytes (or "<DIR>" for directories) |
- // 4. filename (may be empty or contain spaces) |
- // |
- // For now, make sure we have 1-3, and handle 4 later. |
- if (columns.size() < 3) |
- return false; |
- |
- FtpDirectoryListingEntry entry; |
- if (EqualsASCII(columns[2], "<DIR>")) { |
- entry.type = FtpDirectoryListingEntry::DIRECTORY; |
- entry.size = -1; |
- } else { |
- entry.type = FtpDirectoryListingEntry::FILE; |
- if (!base::StringToInt64(columns[2], &entry.size)) |
+bool ParseFtpDirectoryListingWindows( |
+ const std::vector<string16>& lines, |
+ std::vector<FtpDirectoryListingEntry>* entries) { |
+ for (size_t i = 0; i < lines.size(); i++) { |
+ if (lines[i].empty()) |
+ continue; |
+ |
+ std::vector<string16> columns; |
+ base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns); |
+ |
+ // Every line of the listing consists of the following: |
+ // |
+ // 1. date |
+ // 2. time |
+ // 3. size in bytes (or "<DIR>" for directories) |
+ // 4. filename (may be empty or contain spaces) |
+ // |
+ // For now, make sure we have 1-3, and handle 4 later. |
+ if (columns.size() < 3) |
return false; |
- if (entry.size < 0) |
+ |
+ FtpDirectoryListingEntry entry; |
+ if (EqualsASCII(columns[2], "<DIR>")) { |
+ entry.type = FtpDirectoryListingEntry::DIRECTORY; |
+ entry.size = -1; |
+ } else { |
+ entry.type = FtpDirectoryListingEntry::FILE; |
+ if (!base::StringToInt64(columns[2], &entry.size)) |
+ return false; |
+ if (entry.size < 0) |
+ return false; |
+ } |
+ |
+ if (!WindowsDateListingToTime(columns, &entry.last_modified)) |
return false; |
- } |
- if (!WindowsDateListingToTime(columns, &entry.last_modified)) |
- return false; |
+ entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], 3); |
+ if (entry.name.empty()) { |
+ // Some FTP servers send listing entries with empty names. |
+ // It's not obvious how to display such an entry, so ignore them. |
+ // We don't want to make the parsing fail at this point though. |
+ // Other entries can still be useful. |
+ continue; |
+ } |
- entry.name = FtpUtil::GetStringPartAfterColumns(line, 3); |
- if (entry.name.empty()) { |
- // Some FTP servers send listing entries with empty names. It's not obvious |
- // how to display such an entry, so we ignore them. We don't want to make |
- // the parsing fail at this point though. Other entries can still be useful. |
- return true; |
+ entries->push_back(entry); |
} |
- entries_.push(entry); |
- return true; |
-} |
- |
-bool FtpDirectoryListingParserWindows::OnEndOfInput() { |
return true; |
} |
-bool FtpDirectoryListingParserWindows::EntryAvailable() const { |
- return !entries_.empty(); |
-} |
- |
-FtpDirectoryListingEntry FtpDirectoryListingParserWindows::PopEntry() { |
- FtpDirectoryListingEntry entry = entries_.front(); |
- entries_.pop(); |
- return entry; |
-} |
- |
} // namespace net |