-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.cpp
More file actions
77 lines (60 loc) · 1.33 KB
/
helpers.cpp
File metadata and controls
77 lines (60 loc) · 1.33 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "helpers.h"
bool isUpperLetter(char letter)
{
return letter >= 'A' && letter <= 'Z';
}
bool isLowerLetter(char letter)
{
return letter >= 'a' && letter <= 'z';
}
bool isCharDigit(char symbol)
{
return symbol >= '0' && symbol <= '9';
}
bool contains(const MyString& str, bool(*criteria)(char))
{
for (size_t i = 0; i < str.length(); i++)
{
if (criteria(str[i]))
return true;
}
return false;
}
bool isInputValidIndex(const MyString& string)
{
if (string.isEmpty()) { return false; }
for (size_t i = 0; i < string.length(); i++)
{
if (!isCharDigit(string[i])) { return false; }
}
return true;
}
MyVector<MyString> splitInputInCommandAndValue(const MyString& input)
{
MyVector<MyString> result;
if (input.length() <= 2)
{
result.push_back(MyString("Invalid!"));
return result;
}
int endInput = input.find(' ');
if (endInput == -1)
{
result.push_back(input);
return result;
}
MyString command = input.substr(0, endInput);
result.push_back(command);
size_t lengthOfValue = input.length() - command.length() - 1;
MyString value = input.substr((endInput + 1), lengthOfValue);
result.push_back(value);
return result;
}
void print(const char* str)
{
std::cout << str;
}
void print(const MyString& str)
{
std::cout << str;
}