--- menu-2.1.14/install-menu/install-menu.cc~ 2004-06-18 19:22:01 +0400 +++ menu-2.1.14/install-menu/install-menu.cc 2004-06-18 19:22:11 +0400 @@ -185,6 +185,7 @@ void add_functions() store_func(new functions::translate); store_func(new functions::encode_translate); store_func(new functions::encode); + store_func(new functions::substr); } cat_str *get_eq_cat_str(parsestream &i) --- menu-2.1.14/install-menu/functions.h~ 2004-06-18 19:23:19 +0400 +++ menu-2.1.14/install-menu/functions.h 2004-06-18 19:23:01 +0400 @@ -307,6 +307,12 @@ namespace functions { const char * getName() const {return "encode";} }; + struct substr:public funcN<3>{ + std::ostream &output(std::ostream &o, std::vector &, + std::map &); + const char * getName() const {return "substr";} + }; + } #endif --- menu-2.1.41/install-menu/functions.cc~ 2008-11-10 17:48:15 +0300 +++ menu-2.1.41/install-menu/functions.cc 2008-11-10 17:48:51 +0300 @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include using std::ostream; @@ -570,4 +571,32 @@ ostream &encode::output(ostream &o, vect return o << buf; } +/* + * this method get substring from string + */ +ostream &substr::output(ostream &o, vector &args, + map &menuentry){ + int ps, sz; + string s=args[0]->soutput(menuentry); + string sps=args[1]->soutput(menuentry); + string ssz=args[2]->soutput(menuentry); + + if ( !s.length() ) + return o << s; + + ps = atoi( sps.c_str() ); + if ( ps < 0 ) + ps = 0; + if ( ps >= s.length() ) + ps = s.length() - 1; + + sz = atoi( ssz.c_str() ); + if ( sz < 0 ) + sz = 0; + if ( ps + sz > s.length() ) + sz = s.length() - ps; + + return o << s.substr( ps, sz ); +} + }