added str_to_upper and str_to_lower

This commit is contained in:
aristocratos
2021-06-22 19:19:14 +02:00
parent c222805383
commit f3628a96eb
5 changed files with 37 additions and 16 deletions

View File

@@ -400,6 +400,13 @@ int main(int argc, char **argv){
exit(0);
}
if (false) {
string first = "Test number 1 OF 45, or?";
cout << str_to_lower(first) << endl;
cout << str_to_upper(first) << endl;
exit(0);
}
if (false) {
Draw::Meter kmeter;
@@ -420,7 +427,7 @@ int main(int argc, char **argv){
exit(0);
}
if (true) {
if (false) {
vector<long long> mydata;
for (long long i = 0; i <= 100; i++) mydata.push_back(i);

View File

@@ -168,9 +168,9 @@ namespace Proc {
//* Iterate over all pids in /proc
for (auto& d: fs::directory_iterator(proc_path)){
if (pread.is_open()) pread.close();
if (stop.load()) {
collecting.store(false);
stop.store(false);
if (stop) {
collecting = false;
stop = false;
return current_procs;
}
@@ -377,7 +377,7 @@ namespace Proc {
old_cputimes = cputimes;
current_procs.swap(procs);
numpids = npids;
collecting.store(false);
collecting = false;
return current_procs;
}

BIN
src/btop_shared Normal file

Binary file not shown.

View File

@@ -168,12 +168,6 @@ namespace Term {
namespace Tools {
namespace {
//? Units for floating_humanizer function
const array<string, 11> Units_bit = {"bit", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib", "Bib", "GEb"};
const array<string, 11> Units_byte = {"Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "BiB", "GEB"};
}
size_t ulen(string str, const bool escape){
if (escape) str = std::regex_replace(str, Fx::escape_regex, "");
return rng::count_if(str, [](char c) { return (static_cast<unsigned char>(c) & 0xC0) != 0x80; } );
@@ -193,6 +187,18 @@ namespace Tools {
return str;
}
string str_to_upper(const string& str){
string out = str;
rng::for_each(out, [](auto& c){ c = ::toupper(c); } );
return out;
}
string str_to_lower(const string& str){
string out = str;
rng::for_each(out, [](char& c){ c = ::tolower(c); } );
return out;
}
uint64_t time_s(){
return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
@@ -306,6 +312,8 @@ namespace Tools {
string floating_humanizer(uint64_t value, bool shorten, uint start, bool bit, bool per_second){
string out;
uint mult = (bit) ? 8 : 1;
static const array<string, 11> Units_bit = {"bit", "Kib", "Mib", "Gib", "Tib", "Pib", "Eib", "Zib", "Yib", "Bib", "GEb"};
static const array<string, 11> Units_byte = {"Byte", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "BiB", "GEB"};
auto& units = (bit) ? Units_bit : Units_byte;
value *= 100 * mult;
@@ -338,7 +346,7 @@ namespace Tools {
std::string operator*(string str, size_t n){
string out;
out.reserve(str.size() * n);
while (n-- > 0) out += str;
while (n-- > 0) out.append(str);
return out;
}
@@ -360,13 +368,13 @@ namespace Tools {
#else
//* Crude implementation of atomic wait for GCC 10
void atomic_wait(atomic<bool>& atom, bool val){
while (atom.load() == val) sleep_ms(1);
while (atom == val) std::this_thread::sleep_for(std::chrono::microseconds(1));
}
#endif
void atomic_wait_set(atomic<bool>& atom, bool val){
atomic_wait(atom, val);
atom.store(val);
atom = val;
}
}
@@ -411,7 +419,7 @@ namespace Logger {
lwrite.close();
}
else logfile.clear();
busy.store(false);
busy = false;
}
void error(string msg){

View File

@@ -149,6 +149,12 @@ namespace Tools {
//* Resize a string consisting of UTF8 characters (only reduces size)
string uresize(string str, const size_t len);
//* Return <str> with only uppercase characters
string str_to_upper(const string& str);
//* Return <str> with only lowercase characters
string str_to_lower(const string& str);
//* Check if vector <vec> contains value <find_val>
template <typename T>
bool v_contains(const vector<T>& vec, const T find_val) {
@@ -223,7 +229,7 @@ namespace Tools {
//* Waits for <atom> to not be <val> and then sets it to <val> again
void atomic_wait_set(std::atomic<bool>& atom, bool val=true);
}
//* Simple logging implementation