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/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"
19 bool ParseFtpDirectoryListingOS2(
20 const std::vector
<base::string16
>& lines
,
21 std::vector
<FtpDirectoryListingEntry
>* entries
) {
22 for (size_t i
= 0; i
< lines
.size(); i
++) {
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. size in bytes (0 for directories)
33 // 2. type (A for files, DIR for directories)
36 // 5. filename (may be empty or contain spaces)
38 // For now, make sure we have 1-4, and handle 5 later.
39 if (columns
.size() < 4)
42 FtpDirectoryListingEntry entry
;
43 if (!base::StringToInt64(columns
[0], &entry
.size
))
45 if (base::EqualsASCII(columns
[1], "DIR")) {
48 entry
.type
= FtpDirectoryListingEntry::DIRECTORY
;
50 } else if (base::EqualsASCII(columns
[1], "A")) {
51 entry
.type
= FtpDirectoryListingEntry::FILE;
58 if (!FtpUtil::WindowsDateListingToTime(columns
[2],
60 &entry
.last_modified
)) {
64 entry
.name
= FtpUtil::GetStringPartAfterColumns(lines
[i
], 4);
65 if (entry
.name
.empty()) {
66 // Some FTP servers send listing entries with empty names.
67 // It's not obvious how to display such an entry, so ignore them.
68 // We don't want to make the parsing fail at this point though.
69 // Other entries can still be useful.
73 entries
->push_back(entry
);