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

Unified 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698