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_os2.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 ParseFtpDirectoryListingOS2(
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:
30 // 1. size in bytes (0 for directories)
31 // 2. type (A for files, DIR for directories)
34 // 5. filename (may be empty or contain spaces)
36 // For now, make sure we have 1-4, and handle 5 later.
37 if (columns.size() < 4)
40 FtpDirectoryListingEntry entry;
41 if (!base::StringToInt64(columns[0], &entry.size))
43 if (EqualsASCII(columns[1], "DIR")) {
46 entry.type = FtpDirectoryListingEntry::DIRECTORY;
48 } else if (EqualsASCII(columns[1], "A")) {
49 entry.type = FtpDirectoryListingEntry::FILE;
56 if (!FtpUtil::WindowsDateListingToTime(columns[2],
58 &entry.last_modified)) {
62 entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], 4);
63 if (entry.name.empty()) {
64 // Some FTP servers send listing entries with empty names.
65 // It's not obvious how to display such an entry, so ignore them.
66 // We don't want to make the parsing fail at this point though.
67 // Other entries can still be useful.
71 entries->push_back(entry);