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

Side by Side Diff: chrome/browser/local_discovery/storage/path_util.cc

Issue 141703022: Support for file listing in privet local filesystem (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 "chrome/browser/local_discovery/storage/path_util.h"
6
7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h"
9
10 namespace local_discovery {
11
12 namespace {
13
14 std::string UnescapeSlashes(const std::string& str) {
15 std::string output = "";
16 for (size_t i = 0; i < str.length(); i++) {
17 if (str[i] == '$') {
18 i++;
19 switch (str[i]) {
20 case 's':
21 output += '/';
22 break;
23 case 'b':
24 output += '\\';
25 break;
26 case '$':
27 output += '$';
28 break;
29 default:
30 NOTREACHED();
31 }
32 } else {
33 output += str[i];
34 }
35 }
36
37 return output;
38 }
39
40 const size_t kNumComponentsInBasePrivetPath = 4;
41 const int kIndexOfServiceNameInComponentList = 2;
42
43 std::string PathStringToString(const base::FilePath::StringType& string) {
44 #if defined(OS_WIN)
45 return base::UTF16ToUTF8(string);
46 #else
47 return string;
48 #endif
49 }
50
51 } // namespace
52
53 ParsedPrivetPath::ParsedPrivetPath(const base::FilePath& file_path) {
54 std::vector<base::FilePath::StringType> components;
55 file_path.GetComponents(&components);
56 DCHECK(components.size() >= kNumComponentsInBasePrivetPath);
57 service_name = UnescapeSlashes(PathStringToString(
58 components[kIndexOfServiceNameInComponentList]));
59
60
61 for (size_t i = kNumComponentsInBasePrivetPath; i < components.size(); i++) {
62 path += '/' + PathStringToString(components[i]);
63 }
64
65 if (path.empty()) path = "/";
66 }
67
68 ParsedPrivetPath::~ParsedPrivetPath() {
69 }
70
71 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/storage/path_util.h ('k') | chrome/browser/local_discovery/storage/path_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698