Esempio n. 1
0
 types::str capitalize(types::str const &s)
 {
   if (s.empty())
     return s;
   else {
     types::str copy = s;
     copy[0] = ::toupper(s[0]);
     std::transform(s.begin() + 1, s.end(), copy.begin() + 1, ::tolower);
     return copy;
   }
 }
Esempio n. 2
0
      types::str join(S const &s, types::str const &iterable)
      {
        long ssize = std::distance(std::begin(s), std::end(s)) -
                     (std::is_same<S, types::str>::value ? 0 : 1);
        /* first iterate over iterable to gather sizes */
        size_t n = ssize * (iterable.size() - 1) + iterable.size();

        std::string out(n, 0);

        auto iter = iterable.begin();
        auto oter = out.begin();
        if (iter != iterable.end()) {
          *oter++ = *iter++;
          if (ssize)
            for (; iter != iterable.end(); ++iter) {
              oter = std::copy(std::begin(s), std::begin(s) + ssize, oter);
              *oter++ = *iter;
            }
          else
            std::copy(iter, iterable.end(), oter);
        }
        return {std::move(out)};
      }
Esempio n. 3
0
 types::str upper(types::str const &s)
 {
   types::str copy = s;
   std::transform(s.begin(), s.end(), copy.begin(), ::toupper);
   return copy;
 }
Esempio n. 4
0
 types::str lstrip(types::str const& self, types::str const& to_del = " ")
 {
     return types::str(self.begin() + self.find_first_not_of(to_del), self.end());
 }