Structureddata stuff. Not the best implementation, but better than our old one :P

This commit is contained in:
momo5502
2016-02-06 13:37:23 +01:00
parent b4be34c8a8
commit c1ef716e5c
20 changed files with 220 additions and 42 deletions

View File

@ -2,9 +2,9 @@
namespace Utils
{
CSV::CSV(std::string file, bool isFile)
CSV::CSV(std::string file, bool isFile, bool allowComments)
{
CSV::Parse(file, isFile);
CSV::Parse(file, isFile, allowComments);
}
CSV::~CSV()
@ -64,7 +64,7 @@ namespace Utils
return "";
}
void CSV::Parse(std::string file, bool isFile)
void CSV::Parse(std::string file, bool isFile, bool allowComments)
{
std::string buffer;
@ -84,12 +84,12 @@ namespace Utils
for (auto row : rows)
{
CSV::ParseRow(row);
CSV::ParseRow(row, allowComments);
}
}
}
void CSV::ParseRow(std::string row)
void CSV::ParseRow(std::string row, bool allowComments)
{
bool isString = false;
std::string element;
@ -119,7 +119,7 @@ namespace Utils
//++i;
continue;
}
else if (!isString && row[i] == '#') // Skip comments. I know CSVs usually don't have comments, but in this case it's useful
else if (!isString && row[i] == '#' && allowComments) // Skip comments. I know CSVs usually don't have comments, but in this case it's useful
{
return;
}

View File

@ -3,7 +3,7 @@ namespace Utils
class CSV
{
public:
CSV(std::string file, bool isFile = true);
CSV(std::string file, bool isFile = true, bool allowComments = true);
~CSV();
int GetRows();
@ -14,8 +14,8 @@ namespace Utils
private:
void Parse(std::string file, bool isFile = true);
void ParseRow(std::string row);
void Parse(std::string file, bool isFile = true, bool allowComments = true);
void ParseRow(std::string row, bool allowComments = true);
std::vector<std::vector<std::string>> DataMap;
};
}

View File

@ -25,9 +25,9 @@ namespace Utils
return input;
}
bool EndsWith(const char* haystack, const char* needle)
bool EndsWith(std::string haystack, std::string needle)
{
return (strstr(haystack, needle) == (haystack + strlen(haystack) - strlen(needle)));
return (strstr(haystack.data(), needle.data()) == (haystack.data() + haystack.size() - needle.size()));
}
std::vector<std::string> Explode(const std::string& str, char delim)

View File

@ -4,7 +4,7 @@ namespace Utils
{
const char *VA(const char *fmt, ...);
std::string StrToLower(std::string input);
bool EndsWith(const char* haystack, const char* needle);
bool EndsWith(std::string haystack, std::string needle);
std::vector<std::string> Explode(const std::string& str, char delim);
void Replace(std::string &string, std::string find, std::string replace);
bool StartsWith(std::string haystack, std::string needle);