change base 26 to bijective base 26

This commit is contained in:
rolux 2011-12-17 04:33:43 +05:30
parent d78b31bef9
commit 6374f6de6d
4 changed files with 24 additions and 13 deletions

View file

@ -23,6 +23,11 @@ Ox.ObjectInput = function(options, self) {
labelWidth: self.options.labelWidth, labelWidth: self.options.labelWidth,
width: self.options.width width: self.options.width
}) })
.bindEvent({
change: function(data) {
// ...
}
})
.appendTo(that); .appendTo(that);
}); });

View file

@ -1,4 +1,4 @@
'use strict' 'use strict';
Ox.SelectInput = function(options, self) { Ox.SelectInput = function(options, self) {

View file

@ -52,7 +52,7 @@ Ox.documentReady = (function() {
callbacks.push(callback); callbacks.push(callback);
return false; return false;
} }
} };
}()); }());
/*@ /*@

View file

@ -42,26 +42,32 @@
} }
/*@ /*@
Ox.encodeBase26 <b> Encode a number as base26 Ox.encodeBase26 <b> Encode a number as bijective base26
> Ox.encodeBase26(3758) See <a href="http://en.wikipedia.org/wiki/Bijective_numeration">
Bijective numeration</a>.
> Ox.encodeBase26(4461)
'FOO' 'FOO'
@*/ @*/
Ox.encodeBase26 = function(num) { Ox.encodeBase26 = function(num) {
return Ox.map(num.toString(26), function(char) { var ret = '';
return Ox.char(65 + parseInt(char, 26)); while (num) {
}).join(''); ret = String.fromCharCode(64 + num % 26) + ret;
num = parseInt(num / 26);
}
return ret;
}; };
/*@ /*@
Ox.decodeBase26 <f> Decodes a base26-encoded number Ox.decodeBase26 <f> Decodes a bijective base26-encoded number
See <a href="http://www.crockford.com/wrmg/base32.html">Base 32</a>. See <a href="http://en.wikipedia.org/wiki/Bijective_numeration">
Bijective numeration</a>.
> Ox.decodeBase26('foo') > Ox.decodeBase26('foo')
3758 4461
@*/ @*/
Ox.decodeBase26 = function(str) { Ox.decodeBase26 = function(str) {
return parseInt(Ox.map(str.toUpperCase(), function(char) { return str.toUpperCase().split('').reverse().reduce(function(p, v, i) {
return (char.charCodeAt(0) - 65).toString(26); return p + (v.charCodeAt(0) - 64) * Math.pow(26, i);
}).join(''), 26); }, 0);
}; };
/*@ /*@