flx_strutil.hpp

00001 #line 3465 "./lpsrc/flx_rtl.pak"
00002 #include <string>
00003 #include <sstream>
00004 #include <stdarg.h>
00005 
00006 #include "flx_rtl_config.hpp"
00007 
00008 //RF: was only to commented out to fix macosx problem,
00009 //but lets see what happens to all the other builds.
00010 //#ifndef MACOSX
00011 //template class RTL_EXTERN std::basic_string<char>;
00012 //#endif
00013 
00014 namespace flx { namespace rtl { namespace strutil {
00015   using namespace std;
00016   template<class T>
00017   basic_string<T> mul(basic_string<T> s, int n) {
00018     basic_string<T> r = "";
00019     while(n--) r+=s;
00020     return r;
00021   }
00022 
00023   // normalise string positions Python style
00024   // note substr requires 0<=b<=size, 0<=n,
00025   // however n>size is OK
00026   template<class T>
00027   basic_string<T> substr(basic_string<T> const &s, int b, int e)
00028   {
00029     int n = s.size();
00030     if(b<0)  b=b+n;
00031     if(b<0)  b=0;
00032     if(b>=n) b=n;
00033     if(e<0)  e=e+n;
00034     if(e<0)  e=0;
00035     if(e>=n) e=n;
00036     int m =  e-b;
00037     if(m<0)  m=0;
00038     return s.substr(b,m);
00039   }
00040 
00041   template<class T>
00042   T subscript(basic_string<T> const &s, int i)
00043   {
00044     int n = s.size();
00045     if(i<0)  i=i+n;
00046     return i<0 || i >= n ? T(0) : s[i];
00047   }
00048 
00049   template<class T>
00050   string str(T const &t) {
00051     std::ostringstream x;
00052     x << t;
00053     return x.str();
00054   }
00055 
00056   RTL_EXTERN string atostr(char const *a);
00057   RTL_EXTERN string flx_asprintf(char *fmt,...);
00058 
00059 }}}

Generated on Sun Nov 25 12:27:24 2007 for Felix by  doxygen 1.5.3-20071008