Beispiel #1
0
 bool endswith(types::str const& s, types::str const& suffix, long start, long end)
 {
     if(end == -1)
         end = s.size();
     long rstart = end - suffix.size();
     return rstart >= start and s.compare(rstart, suffix.size(), suffix) == 0;
 }
Beispiel #2
0
 bool startswith(types::str const &s, types::str const &prefix, long start,
                 long end)
 {
   if (end < 0)
     end = s.size();
   return (end - start) >= prefix.size() and
          s.compare(start, prefix.size(), prefix) == 0;
 }
Beispiel #3
0
 void file::write(types::str const &str)
 {
   if (not is_open)
     throw ValueError("I/O operation on closed file");
   if (mode.find_first_of("wa+") == -1)
     throw IOError("file.write() :  File not opened for writing.");
   fwrite(str.c_str(), sizeof(char), str.size(), **data);
 }
Beispiel #4
0
long find(types::str const &s, types::str const &value, long start,
          long end)
{
    if (end < 0)
        end += s.size();
    long a = s.find(value, start);
    return (a > end) ? -1 : a;
}
Beispiel #5
0
 long str::count(types::str const &sub) const
 {
   long counter = 0;
   for (long z = find(sub);            // begin by looking for sub
        z != -1;                       // as long as we don't reach the end
        z = find(sub, z + sub.size())) // look for another one
   {
     ++counter;
   }
   return counter;
 }
Beispiel #6
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)};
      }
Beispiel #7
0
 bool startswith(types::str const& s, types::str const& prefix, long start=0, size_t end=std::string::npos) {
     if(end == std::string::npos)
         end = s.size();
     return (end - start) >= prefix.size() and s.compare(start, prefix.size(), prefix) == 0;
 }
Beispiel #8
0
long find(types::str const &s, types::str const &value)
{
    return find(s, value, 0, s.size());
}
Beispiel #9
0
long find(types::str const &s, types::str const &value, long start)
{
    return find(s, value, start, s.size());
}