Chromium Code Reviews| Index: remoting/signaling/jid_util.cc |
| diff --git a/remoting/signaling/jid_util.cc b/remoting/signaling/jid_util.cc |
| index 8e8e12bb8788da5d03eb93f8046d190907c03caf..ab9e549f7219cc678189a1778fe8e81dddb1dab6 100644 |
| --- a/remoting/signaling/jid_util.cc |
| +++ b/remoting/signaling/jid_util.cc |
| @@ -9,15 +9,35 @@ |
| namespace remoting { |
| std::string NormalizeJid(const std::string& jid) { |
| - size_t slash_pos = jid.find('/'); |
| + std::string bare_jid; |
| + std::string resource; |
| + if (SplitJidResource(jid, &bare_jid, &resource)) { |
| + return base::StringToLowerASCII(bare_jid) + "/" + resource; |
| + } |
| + return base::StringToLowerASCII(bare_jid); |
| +} |
| - // In case there the jid doesn't have resource id covert the whole value to |
| - // lower-case. |
| - if (slash_pos == std::string::npos) |
| - return base::StringToLowerASCII(jid); |
| +bool SplitJidResource(const std::string& full_jid, |
| + std::string* bare_jid, |
| + std::string* resource) { |
| + size_t slash_index = full_jid.find('/'); |
| + if (slash_index == std::string::npos) { |
| + if (bare_jid) { |
| + *bare_jid = full_jid; |
| + } |
| + if (resource) { |
| + resource->clear(); |
| + } |
| + return false; |
| + } |
| - return base::StringToLowerASCII(jid.substr(0, slash_pos)) + |
| - jid.substr(slash_pos); |
| + 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.
|
| + *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.
|
| + } |
| + if (resource) { |
| + *resource = std::string(full_jid, slash_index + 1); |
| + } |
| + return true; |
| } |
| } // namespace remoting |