more compact versions of decodeBase128 and decodeBase256

This commit is contained in:
rolux 2011-12-17 04:42:18 +05:30
parent 6374f6de6d
commit d2d92c1ae9

View file

@ -130,7 +130,7 @@
str = Ox.char(num & 127) + str; str = Ox.char(num & 127) + str;
num >>= 7; num >>= 7;
} }
return str || '0'; return str;
}; };
/*@ /*@
@ -139,11 +139,9 @@
1685487 1685487
@*/ @*/
Ox.decodeBase128 = function(str) { Ox.decodeBase128 = function(str) {
var num = 0, len = str.length; return str.split('').reverse().reduce(function(p, v, i) {
Ox.forEach(str, function(char, i) { return p + (v.charCodeAt(0) << i * 7);
num += char.charCodeAt(0) << (len - i - 1) * 7; }, 0);
});
return num;
}; };
/*@ /*@
@ -166,11 +164,9 @@
6713199 6713199
@*/ @*/
Ox.decodeBase256 = function(str) { Ox.decodeBase256 = function(str) {
var num = 0, len = str.length; return str.split('').reverse().reduce(function(p, v, i) {
Ox.forEach(str, function(char, i) { return p + (v.charCodeAt(0) << i * 8);
num += char.charCodeAt(0) << (len - i - 1) * 8; }, 0);
});
return num;
}; };
/*@ /*@