1 // Copyright (c) 2012 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/base/net_util.h"
7 #include "base/i18n/time_formatting.h"
8 #include "base/json/string_escape.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "net/base/escape.h"
15 std::string
GetDirectoryListingEntry(const base::string16
& name
,
16 const std::string
& raw_bytes
,
19 base::Time modified
) {
21 result
.append("<script>addRow(");
22 base::EscapeJSONString(name
, true, &result
);
24 if (raw_bytes
.empty()) {
25 base::EscapeJSONString(EscapePath(base::UTF16ToUTF8(name
)), true, &result
);
27 base::EscapeJSONString(EscapePath(raw_bytes
), true, &result
);
36 // Negative size means unknown or not applicable (e.g. directory).
37 base::string16 size_string
;
39 size_string
= base::FormatBytesUnlocalized(size
);
40 base::EscapeJSONString(size_string
, true, &result
);
44 base::string16 modified_str
;
45 // |modified| can be NULL in FTP listings.
46 if (!modified
.is_null())
47 modified_str
= base::TimeFormatShortDateAndTime(modified
);
48 base::EscapeJSONString(modified_str
, true, &result
);
50 result
.append(");</script>\n");