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

Unified Diff: mojo/shell/public/cpp/lib/names.cc

Issue 1743473002: Change Mojo URLs to structured names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@18collapse
Patch Set: . Created 4 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 side-by-side diff with in-line comments
Download patch
Index: mojo/shell/public/cpp/lib/names.cc
diff --git a/mojo/shell/public/cpp/lib/names.cc b/mojo/shell/public/cpp/lib/names.cc
new file mode 100644
index 0000000000000000000000000000000000000000..59fee826918334a3bf5d1d53a01cba77ede2556f
--- /dev/null
+++ b/mojo/shell/public/cpp/lib/names.cc
@@ -0,0 +1,34 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/shell/public/cpp/names.h"
+
+#include "base/strings/string_split.h"
+
+namespace mojo {
+
+bool IsValidName(const std::string& name) {
+ std::vector<std::string> parts =
+ base::SplitString(name, ":", base::KEEP_WHITESPACE,
+ base::SPLIT_WANT_ALL);
+ return parts.size() == 2 && !parts.front().empty() && !parts.back().empty();
sky 2016/02/26 18:37:27 Is it worth making sure parts.back() doesn't start
+}
+
+std::string GetNameType(const std::string& name) {
+ std::vector<std::string> parts =
+ base::SplitString(name, ":", base::KEEP_WHITESPACE,
+ base::SPLIT_WANT_ALL);
+ DCHECK_EQ(2, parts.size());
+ return parts.front();
+}
+
+std::string GetNamePath(const std::string& name) {
+ std::vector<std::string> parts =
+ base::SplitString(name, ":", base::KEEP_WHITESPACE,
+ base::SPLIT_WANT_ALL);
+ DCHECK_EQ(2, parts.size());
+ return parts.back();
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698