OLD | NEW |
(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 |
OLD | NEW |