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/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 ParseFtpDirectoryListingWindows(
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:
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)
41 FtpDirectoryListingEntry entry
;
42 if (base::EqualsASCII(columns
[2], "<DIR>")) {
43 entry
.type
= FtpDirectoryListingEntry::DIRECTORY
;
46 entry
.type
= FtpDirectoryListingEntry::FILE;
47 if (!base::StringToInt64(columns
[2], &entry
.size
))
53 if (!FtpUtil::WindowsDateListingToTime(columns
[0],
55 &entry
.last_modified
)) {
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.
68 entries
->push_back(entry
);