-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpFun.cpp
More file actions
49 lines (44 loc) · 1.21 KB
/
Copy pathHelpFun.cpp
File metadata and controls
49 lines (44 loc) · 1.21 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
#include "Header.h"
/*
Вспомогательные функции
*/
//Поиск элемента в строке
int FoundIndex(std::string s, char c) {
int i = 0;
while (s[i] != c) { i++; }
return (i);
}
//Срез строки
std::string sr(std::string s, int fs, int ls) {
std::string res;
if (fs + 1 == ls) { res += s[fs]; }
else {
for (int i = fs; i < ls; i++) { res += s[i]; }
}
return (res);
}
//Проверяем на то, допустимы ли индексы указанные в какой-то введеной пользоваетелем команде
bool Error_range(int len, int i, int j) {
if (i > len || i < 0 || j > len || j < 0) {
std::cout << "Error range:" << std::endl;
std::cout << "\t Change fail or change command" << std::endl;
return (false);
}
return (true);
}
//Переводит строку в число
void make_int(std::string s, int *num, int *ind) {
std::string l;
int i = *ind;
while (s[i] != ';') { l += s[(i++)]; }
*ind = i + 1;
*num = stoi(l);
return;
}
//Переводит число в строку
void make_str(std::string s, std::string *data, int *ind, int size) {
int i = 0;
while (i < size) { *data += s[*ind + i++]; }
*ind += i + 1;
return;
}