-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_funcs.cpp
More file actions
84 lines (71 loc) · 2.18 KB
/
shared_funcs.cpp
File metadata and controls
84 lines (71 loc) · 2.18 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
78
79
80
81
82
83
84
#include "shared_funcs.h"
using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;
namespace fs = std::filesystem;
bool replace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
if (start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
return true;
}
void replaceAll(std::string& str, const std::string& from, const std::string& to) { //from stoverflow
if (from.empty())
return;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
std::string bigprint(std::string s)
{
std::string lotsofequals = "=============================================================================";
return "\n" + lotsofequals + "\n" + lotsofequals + "\n" + s + "\n" + lotsofequals + "\n" + lotsofequals + "\n";
};
std::string semibigprint(std::string s)
{
std::string lotsofequals = "=============================================================================";
return "\n" + lotsofequals + "\n" + s + "\n" + lotsofequals + "\n" ;
};
std::string asstring(const std::string v)
{
return v;
};
std::vector<std::string> splitstr(std::string s, std::string token)
{
//from StackOverflow:
std::vector<std::string> vstrings;
size_t pos = 0;
while ((pos = s.find(token)) != std::string::npos) {
vstrings.push_back(s.substr(0, pos));
s.erase(0, pos + token.length());
}
if (s != "")
vstrings.push_back(s);
return vstrings;
}
std::string clearupst(std::string s)
{
std::vector<std::string> vstrings;
std::string mystring = s;
char* removethese = "[:!@#$.()/-]";
char changethis = ' ', forthis = '_';
for (char * removethis = removethese; *removethis != '\0'; removethis++)
{
vstrings = splitstr(mystring, std::string(1, *removethis));
mystring = "";
for (auto astring : vstrings)
{
mystring += astring;
}
}
vstrings = splitstr(mystring, std::string(1, changethis));
mystring = "";
for (auto astring : vstrings)
{
mystring += astring + forthis;
}
return mystring.substr(0, mystring.size() - 1);
}