-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.h
55 lines (48 loc) · 1.45 KB
/
utils.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
// implementation of printf for use in Arduino sketch
void Serial_printf(char* fmt, ...) {
char buf[512]; // resulting string limited to 256 chars
va_list args;
va_start (args, fmt );
vsnprintf(buf, 512, fmt, args);
va_end (args);
Serial.print(buf);
}
// simple URL encoder
String urlEncode(const char* msg)
{
static const char hex[] = "0123456789abcdef";
String encodedMsg = "";
while (*msg!='\0'){
if( ('a' <= *msg && *msg <= 'z')
|| ('A' <= *msg && *msg <= 'Z')
|| ('0' <= *msg && *msg <= '9') ) {
encodedMsg += *msg;
} else {
encodedMsg += '%';
encodedMsg += hex[*msg >> 4];
encodedMsg += hex[*msg & 15];
}
msg++;
}
return encodedMsg;
}
// int32_t indexOf(const char* buffer, size_t length, const char* look_for, size_t look_for_length, int32_t start_index) {
// if (look_for_length > length) {
// return -1;
// }
// for (size_t pos = start_index; pos < length; pos++) {
// if (length - pos < look_for_length) {
// return -1;
// }
// if (buffer[pos] == *look_for) {
// size_t sub = 1;
// for (; sub < look_for_length; sub++) {
// if (buffer[pos + sub] != look_for[sub]) break;
// }
// if (sub == look_for_length) {
// return pos;
// }
// }
// }
// return -1;
// }