Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: net/base/net_util_icu.cc

Issue 1548503002: net: extract GetDirectoryListingXXX functions into directory_listing.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "net/base/net_util.h"
6
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 "base/time/time.h"
12 #include "net/base/escape.h"
13
14 namespace net {
15
16 std::string GetDirectoryListingEntry(const base::string16& name,
17 const std::string& raw_bytes,
18 bool is_dir,
19 int64_t size,
20 base::Time modified) {
21 std::string result;
22 result.append("<script>addRow(");
23 base::EscapeJSONString(name, true, &result);
24 result.append(",");
25 if (raw_bytes.empty()) {
26 base::EscapeJSONString(EscapePath(base::UTF16ToUTF8(name)), true, &result);
27 } else {
28 base::EscapeJSONString(EscapePath(raw_bytes), true, &result);
29 }
30
31 if (is_dir) {
32 result.append(",1,");
33 } else {
34 result.append(",0,");
35 }
36
37 // Negative size means unknown or not applicable (e.g. directory).
38 base::string16 size_string;
39 if (size >= 0)
40 size_string = base::FormatBytesUnlocalized(size);
41 base::EscapeJSONString(size_string, true, &result);
42
43 result.append(",");
44
45 base::string16 modified_str;
46 // |modified| can be NULL in FTP listings.
47 if (!modified.is_null())
48 modified_str = base::TimeFormatShortDateAndTime(modified);
49 base::EscapeJSONString(modified_str, true, &result);
50
51 result.append(");</script>\n");
52
53 return result;
54 }
55
56 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698