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 bool IsValidName(const std::string& name) { |
| 13 std::vector<std::string> parts = |
| 14 base::SplitString(name, ":", base::KEEP_WHITESPACE, |
| 15 base::SPLIT_WANT_ALL); |
| 16 if (parts.size() != 2) |
| 17 return false; |
| 18 |
| 19 if (parts.front().empty()) |
| 20 return false; |
| 21 |
| 22 const std::string& path = parts.back(); |
| 23 return !path.empty() && |
| 24 !base::StartsWith(path, "//", base::CompareCase::INSENSITIVE_ASCII); |
| 25 } |
| 26 |
| 27 std::string GetNameType(const std::string& name) { |
| 28 std::vector<std::string> parts = |
| 29 base::SplitString(name, ":", base::KEEP_WHITESPACE, |
| 30 base::SPLIT_WANT_ALL); |
| 31 DCHECK(2 == parts.size()); |
| 32 return parts.front(); |
| 33 } |
| 34 |
| 35 std::string GetNamePath(const std::string& name) { |
| 36 std::vector<std::string> parts = |
| 37 base::SplitString(name, ":", base::KEEP_WHITESPACE, |
| 38 base::SPLIT_WANT_ALL); |
| 39 DCHECK(2 == parts.size()); |
| 40 return parts.back(); |
| 41 } |
| 42 |
| 43 } // namespace mojo |
OLD | NEW |