-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriangles.cpp
75 lines (67 loc) · 1.47 KB
/
Triangles.cpp
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
#include "defines.h"
// class header
#include "Triangles.h"
std::string upCase(std::string str)
{
std::transform(str.begin(),str.end(),str.begin(),::toupper);
return str;
}
std::string trimLeft(std::string str, std::string chars)
{
str.erase(0,str.find_first_not_of(chars));
return str;
};
std::string trimRight(std::string str, std::string chars)
{
str.erase(str.find_last_not_of(chars)+1);
return str;
};
std::string trim(std::string str, std::string chars)
{
return trimRight(trimLeft(str,chars),chars);
};
int parseWords(std::string str, char divider, int pos1[], int pos2[], int maxcount)
{
int numwords = 0;
int len = static_cast<int>(str.length());
if (len > 0)
{
int curpos1 = NOT_DEFINED;
if (str[0] != divider) curpos1 = 0;
for (int i = 0; i < len; i++)
{
if (str[i] == divider)
{
if (curpos1 != NOT_DEFINED)
{
if (numwords < maxcount)
{
pos1[numwords] = curpos1;
pos2[numwords] = i - 1;
curpos1 = NOT_DEFINED;
numwords++;
} else
{
break;
};
};
} else
{
if (curpos1 == NOT_DEFINED)
{
curpos1 = i;
}
}
}
if (curpos1 != NOT_DEFINED)
{
if (numwords < maxcount)
{
pos1[numwords] = curpos1;
pos2[numwords] = len;
numwords++;
}
}
}
return numwords;
}