This commit is contained in:
mrbesen 2020-09-29 14:04:19 +02:00
parent ef8470b861
commit 7b561f6683
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
7 changed files with 51 additions and 6 deletions

2
.vscode/launch.json vendored
View File

@ -12,7 +12,7 @@
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"environment": [{"name": "LD_LIBRARY_PATH", "value": "./"}],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [

View File

@ -8,4 +8,6 @@ unsigned int count(const std::string& str, char c); //count occurances of c in s
bool equalsIgnoreCase(const std::string& a, const std::string& b, size_t max = std::string::npos);
void toLower(const std::string& in, std::string& out);
}

View File

@ -23,12 +23,16 @@ void mrbesen::Files::file(const std::string& path, std::string& out) {
}
void mrbesen::Files::extention(const std::string& path, std::string& ext) {
size_t pos = path.rfind('.');
if(pos == std::string::npos || pos+1 == path.size()) {
std::string filestr;
file(path, filestr);
size_t pos = filestr.rfind('.');
if(pos == std::string::npos || pos+1 == filestr.size()) {
ext = "";
return;
}
ext = path.substr(pos+1);
ext = filestr.substr(pos+1);
//TODO:
//was ist mit dotfiles?? -> prüfen auf '/' for '.'? oder auf string position (damit der punkt icht ganz links sei kann)?

View File

@ -1,5 +1,7 @@
#include "util.h"
#include <algorithm>
unsigned int mrbesen::Util::count(const std::string& str, char c) {
size_t pos = 0;
long count = -1;
@ -31,3 +33,11 @@ bool mrbesen::Util::equalsIgnoreCase(const std::string& a, const std::string& b,
return std::equal(b.begin(), b.begin()+max, a.begin(), icompare_pred);
}
}
void mrbesen::Util::toLower(const std::string& in, std::string& out) {
out = "";
out.reserve(in.size());
for(char c : in) {
out += std::tolower(c);
}
}

View File

@ -91,5 +91,11 @@ int testFiles_extention() {
Files::extention("/a.b", a);
ASSERT(a == "b", "");
Files::extention("/sad.asd/ab", a);
ASSERT(a == "", "");
Files::extention("sad.asd/ab", a);
ASSERT(a == "", "");
return TESTGOOD;
}

View File

@ -8,8 +8,9 @@ int testFiles_extention();
int testUtil_Count();
int testUtil_equalsIgnoreCase();
int testUtil_toLower();
test_t tests[] = {testFiles_parent, testFiles_file, testFiles_extention, testUtil_Count, testUtil_equalsIgnoreCase, NULL};
test_t tests[] = {testFiles_parent, testFiles_file, testFiles_extention, testUtil_Count, testUtil_equalsIgnoreCase, testUtil_toLower, NULL};
int main(int argc, char** argv) {

View File

@ -37,4 +37,26 @@ int testUtil_equalsIgnoreCase() {
ASSERT(equalsIgnoreCase(a, c, 5), "");
return TESTGOOD;
}
}
int testUtil_toLower() {
std::string a = "abc";
std::string out;
toLower(a, out);
ASSERT(out == a, "");
toLower("", out);
ASSERT(out == "", "");
toLower("ABC", out);
ASSERT(out == a, "");
toLower("123", out);
ASSERT(out == "123", "");
toLower("._:DAd-", out);
ASSERT(out == "._:dad-", "");
return TESTGOOD;
}