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

Unified Diff: remoting/webapp/base.js

Issue 514343002: XMPP implementation in JavaScript. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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/webapp/base.js
diff --git a/remoting/webapp/base.js b/remoting/webapp/base.js
index c2bf1a2b54b28a67c9f7422f10887a5dae5bd2e9..3041616642271e38d5d3578561aa65c3c7d488f8 100644
--- a/remoting/webapp/base.js
+++ b/remoting/webapp/base.js
@@ -385,3 +385,26 @@ base.EventSource.prototype = {
});
}
};
+
+/**
+ * Converts UTF-8 string to ArrayBuffer.
kelvinp 2014/08/29 01:37:09 Nit: blank line between JSDocs and params annotati
Sergey Ulanov 2014/08/29 23:40:29 Done.
+ * @param {string} string
+ * @return {ArrayBuffer}
+ */
+base.encodeUtf8 = function(string) {
+ var utf8String = unescape(encodeURIComponent(string));
+ var result = new Uint8Array(utf8String.length);
+ for (var i = 0; i < utf8String.length; i++)
+ result[i] = utf8String.charCodeAt(i);
+ return result.buffer;
+}
+
+/**
+ * Decodes UTF-8 string from ArrayBuffer.
kelvinp 2014/08/29 01:37:09 same here
Sergey Ulanov 2014/08/29 23:40:29 Done.
+ * @param {ArrayBuffer} buffer
+ * @return {string}
+ */
+base.decodeUtf8 = function(buffer) {
+ return decodeURIComponent(
+ escape(String.fromCharCode.apply(null, new Uint8Array(buffer))));
+}

Powered by Google App Engine
This is Rietveld 408576698