OR.mjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation.mjs";
  7. import Utils from "../Utils.mjs";
  8. import { bitOp, or, BITWISE_OP_DELIMS } from "../lib/BitwiseOp.mjs";
  9. /**
  10. * OR operation
  11. */
  12. class OR extends Operation {
  13. /**
  14. * OR constructor
  15. */
  16. constructor() {
  17. super();
  18. this.name = "OR";
  19. this.module = "Default";
  20. this.description = "OR the input with the given key.<br>e.g. <code>fe023da5</code>";
  21. this.infoURL = "https://wikipedia.org/wiki/Bitwise_operation#OR";
  22. this.inputType = "ArrayBuffer";
  23. this.outputType = "byteArray";
  24. this.args = [
  25. {
  26. "name": "Key",
  27. "type": "toggleString",
  28. "value": "",
  29. "toggleValues": BITWISE_OP_DELIMS
  30. }
  31. ];
  32. }
  33. /**
  34. * @param {ArrayBuffer} input
  35. * @param {Object[]} args
  36. * @returns {byteArray}
  37. */
  38. run(input, args) {
  39. const key = Utils.convertToByteArray(args[0].string || "", args[0].option);
  40. input = new Uint8Array(input);
  41. return bitOp(input, key, or);
  42. }
  43. /**
  44. * Highlight OR
  45. *
  46. * @param {Object[]} pos
  47. * @param {number} pos[].start
  48. * @param {number} pos[].end
  49. * @param {Object[]} args
  50. * @returns {Object[]} pos
  51. */
  52. highlight(pos, args) {
  53. return pos;
  54. }
  55. /**
  56. * Highlight OR in reverse
  57. *
  58. * @param {Object[]} pos
  59. * @param {number} pos[].start
  60. * @param {number} pos[].end
  61. * @param {Object[]} args
  62. * @returns {Object[]} pos
  63. */
  64. highlightReverse(pos, args) {
  65. return pos;
  66. }
  67. }
  68. export default OR;