OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 "mojo/shell/public/cpp/names.h" | |
6 | |
7 #include "base/strings/string_split.h" | |
8 #include "base/strings/string_util.h" | |
9 | |
10 namespace mojo { | |
11 | |
12 const char kNameType_Mojo[] = "mojo"; | |
13 const char kNameType_Exe[] = "exe"; | |
14 | |
15 bool IsValidName(const std::string& name) { | |
16 std::vector<std::string> parts = | |
17 base::SplitString(name, ":", base::KEEP_WHITESPACE, | |
18 base::SPLIT_WANT_ALL); | |
19 if (parts.size() != 2) | |
20 return false; | |
21 | |
22 if (parts.front().empty()) | |
23 return false; | |
24 | |
25 const std::string& path = parts.back(); | |
26 return !path.empty() && | |
27 !base::StartsWith(path, "//", base::CompareCase::INSENSITIVE_ASCII); | |
28 } | |
29 | |
30 std::string GetNameType(const std::string& name) { | |
31 std::vector<std::string> parts = | |
32 base::SplitString(name, ":", base::KEEP_WHITESPACE, | |
33 base::SPLIT_WANT_ALL); | |
34 DCHECK(2 == parts.size()); | |
35 return parts.front(); | |
36 } | |
37 | |
38 std::string GetNamePath(const std::string& name) { | |
39 std::vector<std::string> parts = | |
40 base::SplitString(name, ":", base::KEEP_WHITESPACE, | |
41 base::SPLIT_WANT_ALL); | |
42 DCHECK(2 == parts.size()); | |
43 return parts.back(); | |
44 } | |
45 | |
46 } // namespace mojo | |
OLD | NEW |