-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF53Decoder.cpp
63 lines (37 loc) · 939 Bytes
/
F53Decoder.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "F53Encoder.h"
#include "F53Decoder.h"
using namespace std;
char F53Decoder::decodeChar(uint6_t c) {
for (int i = 0; i < encoderTableLength; i++) {
if (F53Encoder::makeDense(c) == i) {
return encoderTable[i];
}
}
return -1;
}
char F53Decoder::decodeSpecial(uint6_t c) {
c = F53Encoder::condense(F53Encoder::makeDense(c)+54);
return decodeChar(c);
}
char *F53Decoder::decodeStatement(uint6_t *c, int length) {
uint6_t *adigits = c;
char *result = (char *)malloc(length*sizeof(char));
adigits = c;
int where = 0;
for (int i = 0; i < length; i++) {
char tmp = decodeChar(c[i]);
if (tmp == (char)-128) {
result = (char *)realloc(result, length - 1*sizeof(char));
result[where] = decodeSpecial(c[++i]);
} else {
result[where] = tmp;
}
where++;
}
result[where] = '\0';
return result;
}