Delete unused downloads page asset.
[chromium-blink-merge.git] / net / ftp / ftp_directory_listing_parser_windows.cc
blob25ceaf7060616f9d43357a7fa3dc5e7e2bbb2974
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
3 // found in the LICENSE file.
5 #include "net/ftp/ftp_directory_listing_parser_windows.h"
7 #include <vector>
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h"
14 #include "net/ftp/ftp_directory_listing_parser.h"
15 #include "net/ftp/ftp_util.h"
17 namespace net {
19 bool ParseFtpDirectoryListingWindows(
20 const std::vector<base::string16>& lines,
21 std::vector<FtpDirectoryListingEntry>* entries) {
22 for (size_t i = 0; i < lines.size(); i++) {
23 if (lines[i].empty())
24 continue;
26 std::vector<base::string16> columns = base::SplitString(
27 base::CollapseWhitespace(lines[i], false), base::ASCIIToUTF16(" "),
28 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
30 // Every line of the listing consists of the following:
32 // 1. date
33 // 2. time
34 // 3. size in bytes (or "<DIR>" for directories)
35 // 4. filename (may be empty or contain spaces)
37 // For now, make sure we have 1-3, and handle 4 later.
38 if (columns.size() < 3)
39 return false;
41 FtpDirectoryListingEntry entry;
42 if (base::EqualsASCII(columns[2], "<DIR>")) {
43 entry.type = FtpDirectoryListingEntry::DIRECTORY;
44 entry.size = -1;
45 } else {
46 entry.type = FtpDirectoryListingEntry::FILE;
47 if (!base::StringToInt64(columns[2], &entry.size))
48 return false;
49 if (entry.size < 0)
50 return false;
53 if (!FtpUtil::WindowsDateListingToTime(columns[0],
54 columns[1],
55 &entry.last_modified)) {
56 return false;
59 entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], 3);
60 if (entry.name.empty()) {
61 // Some FTP servers send listing entries with empty names.
62 // It's not obvious how to display such an entry, so ignore them.
63 // We don't want to make the parsing fail at this point though.
64 // Other entries can still be useful.
65 continue;
68 entries->push_back(entry);
71 return true;
74 } // namespace net