27 inline static size_t adjust(
const std::string &s, 
size_t width) {
 
   28   for (
unsigned char c : s) {
 
   31     } 
else if (c >= 0xF8) {
 
   33     } 
else if (c >= 0xF0) {
 
   35     } 
else if (c >= 0xE0) {
 
   37     } 
else if (c == 0xCC || c == 0xCD) {
 
   40     } 
else if (c >= 0xC0) {
 
   47 std::string 
fill_left(
const std::string &s, 
size_t width, 
char fill) {
 
   48   width = 
adjust(s, width - s.size());
 
   50     return std::string(width, fill) + s;
 
   55 std::string 
fill_right(
const std::string &s, 
size_t width, 
char fill) {
 
   56   width = 
adjust(s, width - s.size());
 
   58     return s + std::string(width, fill);
 
   63 std::string 
fill_both(
const std::string &s, 
size_t width, 
char fill) {
 
   64   width = 
adjust(s, width - s.size());
 
   66     const int l = width / 2;
 
   67     const int r = width - l;
 
   68     return std::string(l, fill) + s + std::string(r, fill);
 
   75 std::string 
trim(
const std::string &s) {
 
   76   const auto begin = s.find_first_not_of(
" \t\n\r");
 
   77   if (begin == std::string::npos) {
 
   80   const auto end = s.find_last_not_of(
" \t\n\r");
 
   81   return s.substr(begin, end - begin + 1);
 
   85   using str = std::string;
 
   86   str::size_type 
n = 
p.length();
 
   87   for (str::size_type i = s.find(
p); i != str::npos; i = s.find(
p)) {
 
  107 template <
typename Out>
 
  108 void split(
const std::string &s, 
char delim, Out result);
 
  110 template <
typename Out>
 
  111 void split(
const std::string &s, 
char delim, Out result) {
 
  112   std::stringstream ss;
 
  115   while (std::getline(ss, item, delim)) {
 
  120 std::vector<std::string> 
split(
const std::string &s, 
char delim) {
 
  121   std::vector<std::string> elems;
 
  122   split(s, delim, std::back_inserter(elems));
 
std::string fill_right(const std::string &s, size_t width, char fill=' ')
Fill string with characters to the right until the given width is reached.
 
static size_t adjust(const std::string &s, size_t width)
Adjust filling width by taking the size of unicode characters into account.
 
std::string fill_both(const std::string &s, size_t width, char fill=' ')
Fill string with characters at both sides until the given width is reached.
 
std::string fill_left(const std::string &s, size_t width, char fill=' ')
Fill string with characters to the left until the given width is reached.
 
std::vector< std::string > split(const std::string &s, char delim)
Split string by delimiter.
 
std::string trim(const std::string &s)
Strip leading and trailing whitespaces.
 
void isoclean(std::string &s)
Remove ⁺, ⁻, ⁰ from string.
 
void remove_substr(std::string &s, const std::string &p)
Remove all instances of a substring p in a string s.