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.
5 #include "chrome/browser/local_discovery/storage/path_util.h"
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
12 namespace local_discovery
{
16 std::string
UnescapeSlashes(const std::string
& str
) {
17 std::string output
= "";
18 for (size_t i
= 0; i
< str
.length(); i
++) {
42 const size_t kNumComponentsInBasePrivetPath
= 4;
43 const int kIndexOfServiceNameInComponentList
= 2;
45 std::string
PathStringToString(const base::FilePath::StringType
& string
) {
47 return base::UTF16ToUTF8(string
);
55 base::FilePath
NormalizeFilePath(const base::FilePath
& path
) {
57 base::FilePath::StringType path_updated_string
= path
.value();
59 std::replace(path_updated_string
.begin(),
60 path_updated_string
.end(),
61 static_cast<base::FilePath::CharType
>('\\'),
62 static_cast<base::FilePath::CharType
>('/'));
63 return base::FilePath(path_updated_string
);
69 ParsedPrivetPath::ParsedPrivetPath(const base::FilePath
& file_path
) {
70 std::vector
<base::FilePath::StringType
> components
;
71 file_path
.GetComponents(&components
);
72 DCHECK(components
.size() >= kNumComponentsInBasePrivetPath
);
73 service_name
= UnescapeSlashes(PathStringToString(
74 components
[kIndexOfServiceNameInComponentList
]));
77 for (size_t i
= kNumComponentsInBasePrivetPath
; i
< components
.size(); i
++) {
78 path
+= '/' + PathStringToString(components
[i
]);
81 if (path
.empty()) path
= "/";
84 ParsedPrivetPath::~ParsedPrivetPath() {
87 } // namespace local_discovery