forked from MrBesen/libmrbesen
toLower
This commit is contained in:
parent
ef8470b861
commit
7b561f6683
|
@ -12,7 +12,7 @@
|
||||||
"args": [],
|
"args": [],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"environment": [],
|
"environment": [{"name": "LD_LIBRARY_PATH", "value": "./"}],
|
||||||
"externalConsole": false,
|
"externalConsole": false,
|
||||||
"MIMode": "gdb",
|
"MIMode": "gdb",
|
||||||
"setupCommands": [
|
"setupCommands": [
|
||||||
|
|
|
@ -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);
|
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);
|
||||||
|
|
||||||
}
|
}
|
|
@ -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) {
|
void mrbesen::Files::extention(const std::string& path, std::string& ext) {
|
||||||
size_t pos = path.rfind('.');
|
std::string filestr;
|
||||||
if(pos == std::string::npos || pos+1 == path.size()) {
|
file(path, filestr);
|
||||||
|
size_t pos = filestr.rfind('.');
|
||||||
|
|
||||||
|
if(pos == std::string::npos || pos+1 == filestr.size()) {
|
||||||
ext = "";
|
ext = "";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ext = path.substr(pos+1);
|
|
||||||
|
ext = filestr.substr(pos+1);
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
//was ist mit dotfiles?? -> prüfen auf '/' for '.'? oder auf string position (damit der punkt icht ganz links sei kann)?
|
//was ist mit dotfiles?? -> prüfen auf '/' for '.'? oder auf string position (damit der punkt icht ganz links sei kann)?
|
||||||
|
|
10
src/Util.cpp
10
src/Util.cpp
|
@ -1,5 +1,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
unsigned int mrbesen::Util::count(const std::string& str, char c) {
|
unsigned int mrbesen::Util::count(const std::string& str, char c) {
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
long count = -1;
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -91,5 +91,11 @@ int testFiles_extention() {
|
||||||
Files::extention("/a.b", a);
|
Files::extention("/a.b", a);
|
||||||
ASSERT(a == "b", "");
|
ASSERT(a == "b", "");
|
||||||
|
|
||||||
|
Files::extention("/sad.asd/ab", a);
|
||||||
|
ASSERT(a == "", "");
|
||||||
|
|
||||||
|
Files::extention("sad.asd/ab", a);
|
||||||
|
ASSERT(a == "", "");
|
||||||
|
|
||||||
return TESTGOOD;
|
return TESTGOOD;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,9 @@ int testFiles_extention();
|
||||||
|
|
||||||
int testUtil_Count();
|
int testUtil_Count();
|
||||||
int testUtil_equalsIgnoreCase();
|
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) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
|
|
@ -38,3 +38,25 @@ int testUtil_equalsIgnoreCase() {
|
||||||
|
|
||||||
return TESTGOOD;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue