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"
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/time/time.h"
13 #include "net/ftp/ftp_directory_listing_parser.h"
14 #include "net/ftp/ftp_util.h"
18 bool ParseFtpDirectoryListingWindows(
19 const std::vector<base::string16>& lines,
20 std::vector<FtpDirectoryListingEntry>* entries) {
21 for (size_t i = 0; i < lines.size(); i++) {
25 std::vector<base::string16> columns;
26 base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns);
28 // Every line of the listing consists of the following:
32 // 3. size in bytes (or "<DIR>" for directories)
33 // 4. filename (may be empty or contain spaces)
35 // For now, make sure we have 1-3, and handle 4 later.
36 if (columns.size() < 3)
39 FtpDirectoryListingEntry entry;
40 if (EqualsASCII(columns[2], "<DIR>")) {
41 entry.type = FtpDirectoryListingEntry::DIRECTORY;
44 entry.type = FtpDirectoryListingEntry::FILE;
45 if (!base::StringToInt64(columns[2], &entry.size))
51 if (!FtpUtil::WindowsDateListingToTime(columns[0],
53 &entry.last_modified)) {
57 entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], 3);
58 if (entry.name.empty()) {
59 // Some FTP servers send listing entries with empty names.
60 // It's not obvious how to display such an entry, so ignore them.
61 // We don't want to make the parsing fail at this point though.
62 // Other entries can still be useful.
66 entries->push_back(entry);