forked from HaarigerHarald/VHDLFormatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptiveCounter.js
66 lines (66 loc) · 2.16 KB
/
descriptiveCounter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.descriptiveCounter = void 0;
function counterDecode(inputId, outputId) {
var custom_indent = document.getElementById(inputId).value;
var result = descriptiveCounter(custom_indent);
document.getElementById(outputId).innerHTML = result;
}
function descriptiveCounter(input) {
input = input.replace(/\\t/g, " ");
input = input.replace(/\\r/g, "\r");
input = input.replace(/\\n/g, "\n");
var tokens = input.split("");
var result = "";
var repeatedCharCount = 0;
for (var i = 0; i < tokens.length; i++) {
var char = input.substr(i, 1);
if (char == input.substr(i + 1, 1)) {
repeatedCharCount++;
}
else {
switch (char) {
case " ":
char = "blankspace";
break;
case "\t":
char = "tab";
break;
case "\n":
char = "\\n";
break;
case "\r":
char = "\\r";
break;
default:
char = "'" + char + "'";
}
repeatedCharCount = repeatedCharCount > 8 ? 8 : repeatedCharCount;
if (repeatedCharCount > 0) {
char += "s";
}
result += getCountText(repeatedCharCount, char);
repeatedCharCount = 0;
}
}
if (result.length < 0) {
switch (char) {
case " ":
char = "blankspace";
break;
case "\t":
char = "tab";
}
repeatedCharCount = repeatedCharCount > 8 ? 8 : repeatedCharCount;
result = getCountText(repeatedCharCount, char);
}
result = result.replace(/^ & /, "");
return result;
}
exports.descriptiveCounter = descriptiveCounter;
function getCountText(count, char) {
const dict = ["one", "two", "three", "four", "five", "six", "seven", "eight", "many"];
const ampersand = " & ";
return ampersand + dict[count] + " " + char;
}
//# sourceMappingURL=descriptiveCounter.js.map