feat(fs): New filesystem module

Module that displays details about
mounted filesystems, #84

Closes #153
This commit is contained in:
Michael Carlberg
2016-11-13 06:09:51 +01:00
parent ed5b7a508a
commit 9a0df75a91
9 changed files with 343 additions and 3 deletions

View File

@ -157,12 +157,48 @@ namespace string_util {
return find_nth(haystack, found_pos + 1, needle, nth - 1);
}
/**
* Create a float value string
*/
string floatval(float value, int decimals, bool fixed, string locale) {
stringstream ss;
ss.precision(decimals);
if (!locale.empty())
ss.imbue(std::locale(locale.c_str()));
if (fixed)
ss << std::fixed;
ss << value;
return ss.str();
}
/**
* Format a filesize string
*/
string filesize(unsigned long long bytes, int decimals, bool fixed, string locale) {
vector<string> suffixes{"TB", "GB", "MB"};
string suffix{"KB"};
while ((bytes /= 1000) > 999) {
suffix = suffixes.back();
suffixes.pop_back();
}
stringstream ss;
ss.precision(decimals);
if (!locale.empty())
ss.imbue(std::locale(locale.c_str()));
if (fixed)
ss << std::fixed;
ss << bytes << " " << suffix;
return ss.str();
}
/**
* Get the resulting string from a ostream/
*
* Example usage:
* @code cpp
* string_util::from_stream(std::stringstream() << ...);
* string_util::from_stream(stringstream() << ...);
* @endcode
*/
string from_stream(const std::basic_ostream<char>& os) {