0e63ec89c8f8613f5bcc56d69a487a301eceb2a6.svn-base 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. if (!dojo._hasResource["dojox.encoding.easy64"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojox.encoding.easy64"] = true;
  6. dojo.provide("dojox.encoding.easy64");
  7. (function() {
  8. var c = function(input, length, result) {
  9. for (var i = 0; i < length; i += 3) {
  10. result.push(String.fromCharCode((input[i] >>> 2) + 33), String
  11. .fromCharCode(((input[i] & 3) << 4)
  12. + (input[i + 1] >>> 4) + 33), String
  13. .fromCharCode(((input[i + 1] & 15) << 2)
  14. + (input[i + 2] >>> 6) + 33), String
  15. .fromCharCode((input[i + 2] & 63) + 33));
  16. }
  17. };
  18. dojox.encoding.easy64.encode = function(input) {
  19. // summary: encodes input data in easy64 string
  20. // input: Array: an array of numbers (0-255) to encode
  21. var result = [], reminder = input.length % 3, length = input.length
  22. - reminder;
  23. c(input, length, result);
  24. if (reminder) {
  25. var t = input.slice(length);
  26. while (t.length < 3) {
  27. t.push(0);
  28. }
  29. c(t, 3, result);
  30. for (var i = 3; i > reminder; result.pop(), --i);
  31. }
  32. return result.join(""); // String
  33. };
  34. dojox.encoding.easy64.decode = function(input) {
  35. // summary: decodes the input string back to array of numbers
  36. // input: String: the input string to decode
  37. var n = input.length, r = [], b = [0, 0, 0, 0], i, j, d;
  38. for (i = 0; i < n; i += 4) {
  39. for (j = 0; j < 4; ++j) {
  40. b[j] = input.charCodeAt(i + j) - 33;
  41. }
  42. d = n - i;
  43. for (j = d; j < 4; b[++j] = 0);
  44. r.push((b[0] << 2) + (b[1] >>> 4), ((b[1] & 15) << 4)
  45. + (b[2] >>> 2), ((b[2] & 3) << 6) + b[3]);
  46. for (j = d; j < 4; ++j, r.pop());
  47. }
  48. return r;
  49. };
  50. })();
  51. }