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..04406a104cf5263cfcdd6c4132a23a07aa091bf7 100644 |
| --- a/remoting/signaling/jid_util.cc |
| +++ b/remoting/signaling/jid_util.cc |
| @@ -9,15 +9,33 @@ |
| namespace remoting { |
| std::string NormalizeJid(const std::string& jid) { |
| - size_t slash_pos = jid.find('/'); |
| - |
| - // 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); |
| + std::string bare_jid; |
| + std::string resource_suffix; |
| + SplitJidResource(jid, &bare_jid, &resource_suffix); |
| + return base::StringToLowerASCII(bare_jid) + resource_suffix; |
| +} |
| - return base::StringToLowerASCII(jid.substr(0, slash_pos)) + |
| - jid.substr(slash_pos); |
| +bool SplitJidResource(const std::string& full_jid, |
| + std::string* bare_jid, |
| + std::string* resource_suffix) { |
| + size_t slash_index = full_jid.find('/'); |
| + if (slash_index == std::string::npos) { |
| + if (bare_jid != nullptr) { |
|
Sergey Ulanov
2015/05/15 18:22:37
nit: don't need "!=nullptr" part
John Williams
2015/05/15 21:59:43
Done.
|
| + *bare_jid = full_jid; |
| + } |
| + if (resource_suffix != nullptr) { |
| + resource_suffix->clear(); |
| + } |
| + return false; |
| + } else { |
|
Sergey Ulanov
2015/05/15 18:22:37
don't need else because the if above always return
John Williams
2015/05/15 21:59:43
Done.
|
| + if (bare_jid != nullptr) { |
| + *bare_jid = std::string(full_jid, 0, slash_index); |
| + } |
| + if (resource_suffix != nullptr) { |
| + *resource_suffix = std::string(full_jid, slash_index); |
| + } |
| + return true; |
| + } |
| } |
| } // namespace remoting |