2014-12-03 02:02:48 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2015-01-25 22:44:07 +00:00
|
|
|
function hex(value) {
|
|
|
|
var str = value.toString(16).toUpperCase();
|
|
|
|
|
|
|
|
if (str.length < 2) {
|
|
|
|
str = '0' + str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `(0x${str})`;
|
|
|
|
}
|
|
|
|
|
2014-12-17 16:53:04 +00:00
|
|
|
export default {
|
2014-12-07 20:26:45 +00:00
|
|
|
type: 'escape',
|
|
|
|
|
2014-12-11 00:01:57 +00:00
|
|
|
_render() {
|
2014-12-20 02:49:11 +00:00
|
|
|
return this.renderLabel(this.label)
|
2015-03-14 21:11:14 +00:00
|
|
|
.then(label => {
|
2014-12-13 18:42:55 +00:00
|
|
|
label.select('rect').attr({
|
|
|
|
rx: 3,
|
|
|
|
ry: 3
|
|
|
|
});
|
2015-03-14 21:11:14 +00:00
|
|
|
return label;
|
2014-12-11 00:23:14 +00:00
|
|
|
});
|
2014-12-09 22:43:05 +00:00
|
|
|
},
|
|
|
|
|
2014-12-17 19:44:48 +00:00
|
|
|
setup() {
|
2015-01-25 22:44:07 +00:00
|
|
|
var addHex;
|
|
|
|
|
2014-12-17 19:44:48 +00:00
|
|
|
this.code = this.properties.esc.properties.code.textValue;
|
|
|
|
this.arg = this.properties.esc.properties.arg.textValue;
|
2015-01-25 22:44:07 +00:00
|
|
|
[this.label, this.ordinal, addHex] = _.result(this, this.code);
|
|
|
|
|
|
|
|
if (addHex) {
|
|
|
|
this.label = `${this.label} ${hex(this.ordinal)}`;
|
|
|
|
}
|
2014-12-17 19:44:48 +00:00
|
|
|
},
|
|
|
|
|
2014-12-09 22:43:05 +00:00
|
|
|
// Escape code mappings
|
2015-01-25 22:44:07 +00:00
|
|
|
b: ['word boundary', -1, false],
|
|
|
|
B: ['non-word boundary', -1, false],
|
|
|
|
d: ['digit', -1, false],
|
|
|
|
D: ['non-digit', -1, false],
|
|
|
|
f: ['form feed', 0x0c, true],
|
|
|
|
n: ['line feed', 0x0a, true],
|
|
|
|
r: ['carriage return', 0x0d, true],
|
|
|
|
s: ['white space', -1, false],
|
|
|
|
S: ['non-white space', -1, false],
|
|
|
|
t: ['tab', 0x09, true],
|
|
|
|
v: ['vertical tab', 0x0b, true],
|
|
|
|
w: ['word', -1, false],
|
|
|
|
W: ['non-word', -1, false],
|
|
|
|
1: ['Back reference (group = 1)', -1, false],
|
|
|
|
2: ['Back reference (group = 2)', -1, false],
|
|
|
|
3: ['Back reference (group = 3)', -1, false],
|
|
|
|
4: ['Back reference (group = 4)', -1, false],
|
|
|
|
5: ['Back reference (group = 5)', -1, false],
|
|
|
|
6: ['Back reference (group = 6)', -1, false],
|
|
|
|
7: ['Back reference (group = 7)', -1, false],
|
|
|
|
8: ['Back reference (group = 8)', -1, false],
|
|
|
|
9: ['Back reference (group = 9)', -1, false],
|
2014-12-09 22:43:05 +00:00
|
|
|
0() {
|
2014-12-17 19:44:48 +00:00
|
|
|
if (this.arg) {
|
2015-01-25 22:44:07 +00:00
|
|
|
return [`octal: ${this.arg}`, parseInt(this.arg, 8), true];
|
2014-12-09 22:43:05 +00:00
|
|
|
} else {
|
2015-01-25 22:44:07 +00:00
|
|
|
return ['null', 0, true];
|
2014-12-09 22:43:05 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
c() {
|
2015-01-25 22:44:07 +00:00
|
|
|
return [`ctrl-${this.arg.toUpperCase()}`, this.arg.toUpperCase().charCodeAt(0) - 64, true];
|
2014-12-09 22:43:05 +00:00
|
|
|
},
|
|
|
|
x() {
|
2015-01-25 22:44:07 +00:00
|
|
|
return [`0x${this.arg.toUpperCase()}`, parseInt(this.arg, 16), false];
|
2014-12-09 22:43:05 +00:00
|
|
|
},
|
|
|
|
u() {
|
2015-01-25 22:44:07 +00:00
|
|
|
return [`U+${this.arg.toUpperCase()}`, parseInt(this.arg, 16), false];
|
2014-12-07 20:26:45 +00:00
|
|
|
}
|
2014-12-17 16:53:04 +00:00
|
|
|
};
|