-
Notifications
You must be signed in to change notification settings - Fork 5
/
StringList.h
113 lines (87 loc) · 2.24 KB
/
StringList.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef STRINGLIST_H
#define STRINGLIST_H
#include <WProgram.h>
#include "Core.h"
#define charactorSeperator '\r'
class StringList {
public:
StringList() {}
StringList(const String &string)
{
list = string;
listSize = 0;
}
const void operator <<(const String &rhs)
{
if(list.length() > 0) {
list += charactorSeperator;
}
list += rhs;
listSize++;
}
us8 size()
{
return listSize;
}
String at(us8 index)
{
us8 count = 0;
s16 tail = 0;
s16 head = 0;
do {
tail = head;
head = list.indexOf(charactorSeperator, tail);
if(index == count++) {
break;
}
}
while(head++ != -1);
if(head == -1) {
head = list.length();
}
return list.substring(tail, head);
}
String join(const String &seperator)
{
String joinedString;
s16 tail = 0;
s16 head = 0;
do {
tail = head;
head = list.indexOf(charactorSeperator, tail);
if(joinedString.length() > 0) {
joinedString += seperator;
}
joinedString += list.substring(tail, head);
}
while(head++ != -1);
return joinedString;
}
String augment(const String &message)
{
String augmentedString;
s16 tail = 0;
s16 head = 0;
do {
tail = head;
head = message.indexOf('%', tail);
s16 temp = head;
augmentedString += message.substring(tail, temp);
// find digit width
if(head != -1) {
us8 charactor;
do {
charactor = message.charAt(++head);
}
while('0' <= charactor && charactor <= '9');
augmentedString += at(message.substring(temp + 1, head).toInt() - 1);
}
}
while(head != -1);
return augmentedString;
}
private:
String list;
us8 listSize;
};
#endif // STRINGLIST_H