shadowm

Untitled

Jan 15th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. class strstr_function : public function_expression {
  2. public:
  3.         explicit strstr_function(const args_list& args)
  4.         : function_expression("strstr", args, 2, 2)
  5.         {}
  6. private:
  7.         variant execute(const formula_callable& variables) const {
  8.             const std::string& haystack = args()[0]->evaluate(variables).as_string();
  9.             const std::string& needle = args()[1]->evaluate(variables).as_string();
  10.  
  11.             const size_t pos = haystack.find(needle);
  12.  
  13.             if(pos == std::string::npos) {
  14.                 return variant(0);
  15.             } else {
  16.                 return variant(pos + 1);
  17.             }
  18.         }
  19. };
Advertisement
Add Comment
Please, Sign In to add comment