mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
Cleanup & new unwrapped function
This commit is contained in:
@@ -107,22 +107,26 @@ std::string BaseToolkit::transliterate(const std::string &input)
|
||||
std::string BaseToolkit::unspace(const std::string &input)
|
||||
{
|
||||
std::string output = input;
|
||||
for(std::size_t i = 0; i < output.length(); ++i) {
|
||||
if( isspace(output[i]) )
|
||||
output[i] = '_';
|
||||
}
|
||||
std::replace( output.begin(), output.end(), ' ', '_');
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string BaseToolkit::wrapped(const std::string &input, unsigned per_line)
|
||||
std::string BaseToolkit::unwrapped(const std::string &input)
|
||||
{
|
||||
std::string output = input;
|
||||
std::replace( output.begin(), output.end(), '\n', ' ');
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string BaseToolkit::wrapped(const std::string &input, size_t per_line)
|
||||
{
|
||||
std::string text(input);
|
||||
unsigned line_begin = 0;
|
||||
size_t line_begin = 0;
|
||||
|
||||
while (line_begin < text.size())
|
||||
{
|
||||
const unsigned ideal_end = line_begin + per_line ;
|
||||
unsigned line_end = ideal_end <= text.size() ? ideal_end : text.size()-1;
|
||||
const size_t ideal_end = line_begin + per_line ;
|
||||
size_t line_end = ideal_end <= text.size() ? ideal_end : text.size()-1;
|
||||
|
||||
if (line_end == text.size() - 1)
|
||||
++line_end;
|
||||
@@ -133,7 +137,7 @@ std::string BaseToolkit::wrapped(const std::string &input, unsigned per_line)
|
||||
}
|
||||
else // backtrack
|
||||
{
|
||||
unsigned end = line_end;
|
||||
size_t end = line_end;
|
||||
while ( end > line_begin && !std::isspace(text[end]))
|
||||
--end;
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ std::string transliterate(const std::string &input);
|
||||
std::string unspace(const std::string &input);
|
||||
|
||||
// get a wrapped version of the input
|
||||
std::string wrapped(const std::string &input, unsigned per_line);
|
||||
std::string wrapped(const std::string &input, size_t per_line);
|
||||
std::string unwrapped(const std::string &input);
|
||||
|
||||
// get a string to display memory size with unit KB, MB, GB, TB
|
||||
std::string byte_to_string(long b);
|
||||
|
||||
Reference in New Issue
Block a user