Roll src/third_party/WebKit 3aa9dd9:183b2b0 (svn 201777:201778)
[chromium-blink-merge.git] / net / base / net_util_icu.cc
blobc174c92087b0e7fd61af4e821f4bcb1bf621d0fc
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"
13 namespace net {
15 std::string GetDirectoryListingEntry(const base::string16& name,
16 const std::string& raw_bytes,
17 bool is_dir,
18 int64_t size,
19 base::Time modified) {
20 std::string result;
21 result.append("<script>addRow(");
22 base::EscapeJSONString(name, true, &result);
23 result.append(",");
24 if (raw_bytes.empty()) {
25 base::EscapeJSONString(EscapePath(base::UTF16ToUTF8(name)), true, &result);
26 } else {
27 base::EscapeJSONString(EscapePath(raw_bytes), true, &result);
30 if (is_dir) {
31 result.append(",1,");
32 } else {
33 result.append(",0,");
36 // Negative size means unknown or not applicable (e.g. directory).
37 base::string16 size_string;
38 if (size >= 0)
39 size_string = base::FormatBytesUnlocalized(size);
40 base::EscapeJSONString(size_string, true, &result);
42 result.append(",");
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");
52 return result;
55 } // namespace net