MCPcopy Create free account
hub / github.com/TailsmanDesign/PocketMage_PDA / parseLexQuery

Function parseLexQuery

Code/PocketMage_V3/src/OS_APPS/LEXICON.cpp:17–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15};
16
17LexQuery parseLexQuery(const String& input) {
18 LexQuery q;
19 q.word = input;
20 q.requestedIndex = -1;
21
22 String trimmed = input;
23 trimmed.trim();
24 if (trimmed.length() == 0)
25 return q;
26
27 int lastSpace = trimmed.lastIndexOf(' ');
28 if (lastSpace == -1) {
29 q.word = trimmed;
30 return q;
31 }
32
33 String maybeNumber = trimmed.substring(lastSpace + 1);
34 bool isNumber = true;
35 for (size_t i = 0; i < maybeNumber.length(); i++) {
36 if (!isDigit(maybeNumber[i])) {
37 isNumber = false;
38 break;
39 }
40 }
41
42 if (isNumber) {
43 q.word = trimmed.substring(0, lastSpace);
44 q.word.trim();
45 int n = maybeNumber.toInt();
46 if (n > 0)
47 q.requestedIndex = n - 1; // convert to 0-based
48 } else {
49 q.word = trimmed;
50 }
51
52 return q;
53}
54
55int clampDefinitionIndex(int idx, int total) {
56 if (total <= 0)

Callers 1

loadDefinitionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected