OLD | NEW |
---|---|
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 |
OLD | NEW |