Skip to content

Commit

Permalink
Quote Unicode Characters en-route to the Companion.
Browse files Browse the repository at this point in the history
Change-Id: I81cd877dc08b858b8d22b95d1e05be72dd2e1718
  • Loading branch information
jisqyv committed Sep 15, 2013
1 parent e6a1084 commit eb3ee6e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion appinventor/blocklyeditor/src/replmgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Blockly.ReplMgr.putYail = (function() {
rs.phoneState.phoneQueue = [];
}
rs.phoneState.phoneQueue.push({
'code' : code,
'code' : Blockly.ReplMgr.quoteUnicode(code), // Deal with unicode characters and kawa
'success' : success,
'failure' : failure,
'block' : block
Expand Down Expand Up @@ -592,6 +592,26 @@ Blockly.ReplMgr.startAdbDevice = function(rs, usb) {
}, 1000); // We poll once per second
};

// Convert non-ASCII Characters to kawa unicode escape
Blockly.ReplMgr.quoteUnicode = function(input) {
if (!input)
return null;
var sb = [];
var len = input.length;
for (var i = 0; i < len; i++) {
var u = input.charCodeAt(i); // Unicode of the character
if (u < ' '.charCodeAt(0) || u > '~'.charCodeAt(0)) {
// Replace any special chars with \u1234 unicode
var hex = "000" + u.toString(16);
hex = hex.substring(hex.length - 4);
sb.push("\\u" + hex);
} else {
sb.push(input.charAt(i));
}
}
return sb.join("");
};

Blockly.ReplMgr.startRepl = function(already, emulator, usb) {
var refreshAssets = window.parent.AssetManager_refreshAssets;
var rs = window.parent.ReplState;
Expand Down

0 comments on commit eb3ee6e

Please sign in to comment.