Skip to content

Commit dbd476b

Browse files
WIP
1 parent 325b2da commit dbd476b

File tree

7 files changed

+257
-40
lines changed

7 files changed

+257
-40
lines changed

Include/runcpp2/ParseUtil.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ namespace Internal
2525
bool CheckNodeRequirements(YAML::Node& node, const std::vector<NodeRequirement>& requirements);
2626

2727
bool GetParsableInfo(const std::string& contentToParse, std::string& outParsableInfo);
28-
29-
30-
3128
}
3229

3330
}

Include/runcpp2/StringUtil.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
#define RUNCPP2_STRING_UTIL_HPP
33

44
#include <string>
5+
#include <vector>
56

67
namespace runcpp2
78
{
8-
void TrimLeft(std::string& str);
9-
void TrimRight(std::string& str);
10-
void Trim(std::string& str);
9+
namespace Internal
10+
{
11+
12+
void TrimLeft(std::string& str);
13+
void TrimRight(std::string& str);
14+
void Trim(std::string& str);
15+
16+
void SplitString( const std::string& stringToSplit,
17+
const std::string& splitter,
18+
std::vector<std::string>& outStrings);
19+
}
20+
1121
}
1222

1323
#endif

Include/runcpp2/runcpp2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace runcpp2
7070

7171
bool CompileAndLinkScript( const std::string& scriptPath,
7272
const ScriptInfo& scriptInfo,
73-
const std::vector<CompilerProfile>& profiles);
73+
const CompilerProfile& profile);
7474

7575
//--------------------------------------------
7676
//Profile check

Src/runcpp2/ParseUtil.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@
66
namespace runcpp2
77
{
88

9-
namespace Internal
10-
{
11-
NodeRequirement::NodeRequirement() : Name(""),
12-
NodeType(YAML::NodeType::Null),
13-
Required(false),
14-
Nullable(true)
9+
Internal::NodeRequirement::NodeRequirement() : Name(""),
10+
NodeType(YAML::NodeType::Null),
11+
Required(false),
12+
Nullable(true)
1513
{
1614
}
1715

18-
NodeRequirement::NodeRequirement( const std::string& name,
19-
YAML::NodeType::value nodeType,
20-
bool required,
21-
bool nullable) : Name(name),
22-
NodeType(nodeType),
23-
Required(required),
24-
Nullable(nullable)
16+
Internal::NodeRequirement::NodeRequirement( const std::string& name,
17+
YAML::NodeType::value nodeType,
18+
bool required,
19+
bool nullable) : Name(name),
20+
NodeType(nodeType),
21+
Required(required),
22+
Nullable(nullable)
2523
{}
2624

27-
bool CheckNodeRequirements(YAML::Node& node, const std::vector<NodeRequirement>& requirements)
25+
bool Internal::CheckNodeRequirements( YAML::Node& node,
26+
const std::vector<NodeRequirement>& requirements)
2827
{
2928
for(int i = 0; i < requirements.size(); ++i)
3029
{
@@ -55,7 +54,7 @@ namespace Internal
5554
return true;
5655
}
5756

58-
bool GetParsableInfo(const std::string& contentToParse, std::string& outParsableInfo)
57+
bool Internal::GetParsableInfo(const std::string& contentToParse, std::string& outParsableInfo)
5958
{
6059
std::string source = contentToParse;
6160

@@ -219,6 +218,4 @@ namespace Internal
219218

220219
return true;
221220
}
222-
}
223-
224221
}

Src/runcpp2/StringUtil.cpp

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace runcpp2
44
{
5-
void TrimLeft(std::string& str)
5+
void Internal::TrimLeft(std::string& str)
66
{
77
//Remove spaces from left
88
while(!str.empty() && str.at(0) == ' ')
@@ -13,7 +13,7 @@ namespace runcpp2
1313
str.erase(0, 1);
1414
}
1515

16-
void TrimRight(std::string& str)
16+
void Internal::TrimRight(std::string& str)
1717
{
1818
//Remove spaces from right
1919
while(!str.empty() && str.at(str.size() - 1) == ' ')
@@ -25,12 +25,80 @@ namespace runcpp2
2525
}
2626

2727
//Trim string from both sides
28-
void Trim(std::string& str)
28+
void Internal::Trim(std::string& str)
2929
{
3030
//Remove spaces from left
3131
TrimLeft(str);
3232

3333
//Remove spaces from right
3434
TrimRight(str);
3535
}
36+
37+
void Internal::SplitString( const std::string& stringToSplit,
38+
const std::string& splitter,
39+
std::vector<std::string>& outStrings)
40+
{
41+
if(splitter.empty())
42+
{
43+
outStrings.push_back(stringToSplit);
44+
return;
45+
}
46+
47+
std::string curOutString;
48+
std::vector<std::string> tempStringsToCheckForSplit;
49+
50+
for(int i = 0; i < stringToSplit.size(); ++i)
51+
{
52+
curOutString += stringToSplit.at(i);
53+
54+
//Check existing string matches
55+
for(int j = 0; j < tempStringsToCheckForSplit.size(); ++j)
56+
{
57+
if( tempStringsToCheckForSplit.at(j).size() >= splitter.size() - 1 ||
58+
stringToSplit.at(i) != splitter.at(tempStringsToCheckForSplit.at(j).size()))
59+
{
60+
tempStringsToCheckForSplit.erase(tempStringsToCheckForSplit.begin() + j);
61+
--j;
62+
continue;
63+
}
64+
else
65+
{
66+
tempStringsToCheckForSplit.at(j) += stringToSplit.at(i);
67+
68+
//If there's a match, clear record
69+
if(tempStringsToCheckForSplit.size() == splitter.size())
70+
{
71+
curOutString.erase(curOutString.size() - splitter.size());
72+
outStrings.push_back(curOutString);
73+
curOutString.clear();
74+
tempStringsToCheckForSplit.clear();
75+
break;
76+
}
77+
}
78+
}
79+
80+
//If the current character fits the first character of splitter, add it to the record
81+
if(stringToSplit.at(i) == splitter.front())
82+
{
83+
//Check special case if the splitter is only 1 character
84+
if(splitter.size() == 1)
85+
{
86+
curOutString.erase(curOutString.size() - splitter.size());
87+
outStrings.push_back(curOutString);
88+
curOutString.clear();
89+
}
90+
//Otherwise push to string matches
91+
else
92+
{
93+
tempStringsToCheckForSplit.push_back(std::string());
94+
tempStringsToCheckForSplit.back() += stringToSplit.at(i);
95+
96+
}
97+
}
98+
}
99+
100+
//Push the remaining string
101+
if(!curOutString.empty())
102+
outStrings.push_back(curOutString);
103+
}
36104
}

Src/runcpp2/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
#include "runcpp2/StringUtil.hpp"
12
#include "runcpp2/runcpp2.hpp"
3+
4+
5+
6+
27
#include "ssLogger/ssLog.hpp"
38

9+
10+
411
int main(int argc, char* argv[])
512
{
613
#if 0
@@ -49,6 +56,22 @@ int main(int argc, char* argv[])
4956
}
5057

5158
return 0;
59+
#elif 1
60+
//TODO(NOW): Test string split
61+
62+
std::string testString = "This is a test string to split.";
63+
64+
std::vector<std::string> splittedStrings;
65+
66+
runcpp2::Internal::SplitString( testString,
67+
" ",
68+
splittedStrings);
69+
70+
for(int i = 0; i < splittedStrings.size(); ++i)
71+
{
72+
ssLOG_LINE("splittedStrings[" << i << "]: " << splittedStrings[i]);
73+
}
74+
5275
#endif
5376

5477
std::vector<runcpp2::CompilerProfile> compilerProfiles;

0 commit comments

Comments
 (0)