-
Notifications
You must be signed in to change notification settings - Fork 11
/
state.cc
85 lines (71 loc) · 2.29 KB
/
state.cc
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//---------------------------------------------------------------------------
#include "state.h"
#include "str.h"
//---------------------------------------------------------------------------
const StenoCaseMode StenoState::NEXT_WORD_CASE_MODE[] = {
StenoCaseMode::NORMAL, //
StenoCaseMode::LOWER, //
StenoCaseMode::UPPER, //
StenoCaseMode::TITLE, //
StenoCaseMode::NORMAL, //
StenoCaseMode::NORMAL, //
StenoCaseMode::NORMAL, //
StenoCaseMode::UNSPECIFIED, //
};
const StenoCaseMode StenoState::NEXT_LETTER_CASE_MODE[] = {
StenoCaseMode::NORMAL, //
StenoCaseMode::LOWER, //
StenoCaseMode::UPPER, //
StenoCaseMode::NORMAL, //
StenoCaseMode::LOWER_ONCE, //
StenoCaseMode::UPPER_ONCE, //
StenoCaseMode::NORMAL, //
StenoCaseMode::UNSPECIFIED, //
};
//---------------------------------------------------------------------------
StenoState::SpaceBuffer StenoState::SpaceBuffer::instance = {
.count = 1,
.data = {' '},
};
//---------------------------------------------------------------------------
void StenoState::Reset() {
*this = StenoState{
.caseMode = StenoCaseMode::NORMAL,
.overrideCaseMode = StenoCaseMode::NORMAL,
.lookupType = SegmentLookupType::UNKNOWN,
.joinNext = false,
.isGlue = false,
.isManualStateChange = false,
.shouldCombineUndo = false,
.spaceLength = 1,
.spaceOffset = 0,
};
}
void StenoState::SetSpace(const char *space) {
const size_t length = Str::Length(space);
if (length >= 16) {
spaceOffset = 0;
spaceLength = 0;
return;
}
// See if it already exists in the buffer.
SpaceBuffer &buffer = SpaceBuffer::instance;
for (size_t i = 0; i + length <= buffer.count; ++i) {
if (Mem::Eq(buffer.data + i, space, length)) {
spaceLength = (uint32_t)length;
spaceOffset = (uint32_t)i;
return;
}
}
// Add it if possible otherwise.
if (buffer.count + length >= sizeof(buffer.data)) {
spaceOffset = 0;
spaceLength = 0;
return;
}
spaceOffset = buffer.count;
spaceLength = (uint32_t)length;
memcpy(buffer.data + buffer.count, space, length);
buffer.count += length;
}
//---------------------------------------------------------------------------