Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / signaling / jid_util.cc
blob08e525d750a6984670f823e9e0db4dd62c67924e
1 // Copyright 2015 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 "remoting/signaling/jid_util.h"
7 #include "base/strings/string_util.h"
9 namespace remoting {
11 std::string NormalizeJid(const std::string& jid) {
12 std::string bare_jid;
13 std::string resource;
14 if (SplitJidResource(jid, &bare_jid, &resource)) {
15 return base::ToLowerASCII(bare_jid) + "/" + resource;
17 return base::ToLowerASCII(bare_jid);
20 bool SplitJidResource(const std::string& full_jid,
21 std::string* bare_jid,
22 std::string* resource) {
23 size_t slash_index = full_jid.find('/');
24 if (slash_index == std::string::npos) {
25 if (bare_jid) {
26 *bare_jid = full_jid;
28 if (resource) {
29 resource->clear();
31 return false;
34 if (bare_jid) {
35 *bare_jid = full_jid.substr(0, slash_index);
37 if (resource) {
38 *resource = full_jid.substr(slash_index + 1);
40 return true;
43 } // namespace remoting