2018-05-06 14:18:41 +02:00
|
|
|
|
/**
|
|
|
|
|
* @author Matt C [matt@artemisbot.uk]
|
|
|
|
|
* @copyright Crown Copyright 2017
|
|
|
|
|
* @license Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2019-07-09 13:23:59 +02:00
|
|
|
|
import Operation from "../Operation.mjs";
|
|
|
|
|
import Utils from "../Utils.mjs";
|
|
|
|
|
import {DELIM_OPTIONS} from "../lib/Delim.mjs";
|
2018-05-06 14:18:41 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* From Octal operation
|
|
|
|
|
*/
|
|
|
|
|
class FromOctal extends Operation {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* FromOctal constructor
|
|
|
|
|
*/
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
this.name = "From Octal";
|
|
|
|
|
this.module = "Default";
|
|
|
|
|
this.description = "Converts an octal byte string back into its raw value.<br><br>e.g. <code>316 223 316 265 316 271 316 254 40 317 203 316 277 317 205</code> becomes the UTF-8 encoded string <code>Γειά σου</code>";
|
2018-08-21 20:07:13 +02:00
|
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Octal";
|
2018-05-06 14:18:41 +02:00
|
|
|
|
this.inputType = "string";
|
|
|
|
|
this.outputType = "byteArray";
|
|
|
|
|
this.args = [
|
|
|
|
|
{
|
|
|
|
|
"name": "Delimiter",
|
|
|
|
|
"type": "option",
|
|
|
|
|
"value": DELIM_OPTIONS
|
|
|
|
|
}
|
|
|
|
|
];
|
2020-02-25 12:27:03 +01:00
|
|
|
|
this.checks = {
|
|
|
|
|
input: {
|
|
|
|
|
regex: [
|
|
|
|
|
{
|
|
|
|
|
match: "^(?:[0-7]{1,2}|[123][0-7]{2})(?: (?:[0-7]{1,2}|[123][0-7]{2}))*$",
|
|
|
|
|
flags: "",
|
|
|
|
|
args: ["Space"]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
match: "^(?:[0-7]{1,2}|[123][0-7]{2})(?:,(?:[0-7]{1,2}|[123][0-7]{2}))*$",
|
|
|
|
|
flags: "",
|
|
|
|
|
args: ["Comma"]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
match: "^(?:[0-7]{1,2}|[123][0-7]{2})(?:;(?:[0-7]{1,2}|[123][0-7]{2}))*$",
|
|
|
|
|
flags: "",
|
|
|
|
|
args: ["Semi-colon"]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
match: "^(?:[0-7]{1,2}|[123][0-7]{2})(?::(?:[0-7]{1,2}|[123][0-7]{2}))*$",
|
|
|
|
|
flags: "",
|
|
|
|
|
args: ["Colon"]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
match: "^(?:[0-7]{1,2}|[123][0-7]{2})(?:\\n(?:[0-7]{1,2}|[123][0-7]{2}))*$",
|
|
|
|
|
flags: "",
|
|
|
|
|
args: ["Line feed"]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
match: "^(?:[0-7]{1,2}|[123][0-7]{2})(?:\\r\\n(?:[0-7]{1,2}|[123][0-7]{2}))*$",
|
|
|
|
|
flags: "",
|
|
|
|
|
args: ["CRLF"]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-05-06 14:18:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {string} input
|
|
|
|
|
* @param {Object[]} args
|
|
|
|
|
* @returns {byteArray}
|
|
|
|
|
*/
|
|
|
|
|
run(input, args) {
|
|
|
|
|
const delim = Utils.charRep(args[0] || "Space");
|
|
|
|
|
if (input.length === 0) return [];
|
|
|
|
|
return input.split(delim).map(val => parseInt(val, 8));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default FromOctal;
|