-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotutil.cpp
More file actions
53 lines (44 loc) · 1.36 KB
/
Copy pathbotutil.cpp
File metadata and controls
53 lines (44 loc) · 1.36 KB
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
// botutil.cpp 🧰 Реализация строковых утилит
#include "botutil.h"
// 🔢 Проверка строки на числовое значение (целое или с точкой)
bool isNumeric(String str) {
unsigned int stringLength = str.length();
if (stringLength == 0) {
return false;
}
boolean seenDecimal = false;
for (unsigned int i = 0; i < stringLength; ++i) {
if (isDigit(str.charAt(i))) {
continue;
}
if (str.charAt(i) == '.') {
if (seenDecimal) {
return false;
}
seenDecimal = true;
continue;
}
return false;
}
return true;
}
// ✂️ Извлечение подстроки по разделителю (CSV-парсер)
String getValue(String data, char separator, int index) {
int found = 0;
int strIndex[] = { 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
// 📝 Форматирование числа с ведущим нулём (для дат)
String IntWith2Zero(int data) {
String s = String(data);
if (data < 10) { s = String("0") + s; }
return s;
}