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

Side by Side Diff: remoting/signaling/jid_util.cc

Issue 1123153002: Added class to subscribe to GCD notifications over XMPP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-xmpp-connect2a
Patch Set: for review Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/signaling/jid_util.h" 5 #include "remoting/signaling/jid_util.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 8
9 namespace remoting { 9 namespace remoting {
10 10
11 std::string NormalizeJid(const std::string& jid) { 11 std::string NormalizeJid(const std::string& jid) {
12 size_t slash_pos = jid.find('/'); 12 std::string bare_jid;
13 std::string resource;
14 if (SplitJidResource(jid, &bare_jid, &resource)) {
15 return base::StringToLowerASCII(bare_jid) + "/" + resource;
16 }
17 return base::StringToLowerASCII(bare_jid);
18 }
13 19
14 // In case there the jid doesn't have resource id covert the whole value to 20 bool SplitJidResource(const std::string& full_jid,
15 // lower-case. 21 std::string* bare_jid,
16 if (slash_pos == std::string::npos) 22 std::string* resource) {
17 return base::StringToLowerASCII(jid); 23 size_t slash_index = full_jid.find('/');
24 if (slash_index == std::string::npos) {
25 if (bare_jid) {
26 *bare_jid = full_jid;
27 }
28 if (resource) {
29 resource->clear();
30 }
31 return false;
32 }
18 33
19 return base::StringToLowerASCII(jid.substr(0, slash_pos)) + 34 if (bare_jid != nullptr) {
Sergey Ulanov 2015/05/16 00:56:07 don't need != nullptr
John Williams 2015/05/16 02:10:06 Done.
20 jid.substr(slash_pos); 35 *bare_jid = std::string(full_jid, 0, slash_index);
Sergey Ulanov 2015/05/16 00:56:07 use substr() here and to extract resource?
John Williams 2015/05/16 02:10:06 Done.
36 }
37 if (resource) {
38 *resource = std::string(full_jid, slash_index + 1);
39 }
40 return true;
21 } 41 }
22 42
23 } // namespace remoting 43 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698