char() operation now supports multiple values inside bracket. i.e. CHAR(45,120,49,45,81,45)

This commit is contained in:
windhamwong@nva-hk.com 2017-07-13 08:42:38 +01:00
parent 1e60054fe3
commit 93d47630b8

View file

@ -53,8 +53,8 @@ const ByteRepr = {
const delim = args[0] || "Space"; const delim = args[0] || "Space";
return Utils.fromHex(input, delim, 2); return Utils.fromHex(input, delim, 2);
}, },
/** /**
* From 0xHex operation. * From 0xHex operation.
* *
@ -63,7 +63,7 @@ const ByteRepr = {
* @returns {byteArray} * @returns {byteArray}
*/ */
runFrom0xHex: function(input, args) { runFrom0xHex: function(input, args) {
var data = input.replace(/0x([0-9a-f]{2,})/ig, var data = input.replace(/0x([0-9a-f]{2,})/ig,
function(match, p1) { function(match, p1) {
if (p1) { if (p1) {
return Utils.byteArrayToChars(Utils.fromHex(p1)); return Utils.byteArrayToChars(Utils.fromHex(p1));
@ -71,8 +71,8 @@ const ByteRepr = {
}); });
return data; return data;
}, },
/** /**
* From char(hex) operation. * From char(hex) operation.
* *
@ -81,13 +81,16 @@ const ByteRepr = {
* @returns {byteArray} * @returns {byteArray}
*/ */
runFromCharHex: function(input, args) { runFromCharHex: function(input, args) {
var data = input.replace(/cha?r\((\d{1,3})\)/ig, var re = /cha?r\((((\d{1,3})(,\s?)?)+)\)/ig;
function(match, p1) { var inner_re = /(\d{1,3}),?/g;
if (p1) { var match, inner_match;
return Utils.byteArrayToChars([parseInt(p1)]); var result = "";
}; while ((match = re.exec(input)) != null) {
}); while ((inner_match = inner_re.exec(match[1])) != null) {
return data; result += Utils.byteArrayToChars([parseInt(inner_match[1])]);
}
}
return input.replace(re, result);
}, },