Logo Search packages:      
Sourcecode: pcmanx-gtk2 version File versions  Download package

botutil.h

#ifndef __INCLUDE_BOTUTIL_H__
#define __INCLUDE_BOTUTIL_H__

#include <cstring>
using namespace std;

inline int
replaceString (string & modify_me, string & find_me, string & replace_with_me)
{
      int search_here = 0;
      int num_replaced = 0;
      if (find_me == replace_with_me)
            return 0;
      while (1) {
            search_here = modify_me.find (find_me, search_here);
            if (search_here != string::npos && search_here < modify_me.length ())   // found
            {
                  modify_me.replace (search_here, find_me.length (),
                                 replace_with_me);
                  num_replaced++;
                  search_here++;
            }
            else
                  break;
      }
      return num_replaced;
}

inline string
trim (const string & str)
{
      if (str.length () == 0)
            return str;
      int first = str.find_first_not_of (" \t");
      int end = str.find_last_not_of (" \t");
      if (first == -1)
            return "";
      return std::string (str, first, end - first + 1);
}

#endif // #define __INCLUDE_BOTUTIL_H__

Generated by  Doxygen 1.6.0   Back to index