OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
import_export::anonymous_namespace{ExpressionParser.cpp}::Function_split_part Class Reference
+ Inheritance diagram for import_export::anonymous_namespace{ExpressionParser.cpp}::Function_split_part:
+ Collaboration diagram for import_export::anonymous_namespace{ExpressionParser.cpp}::Function_split_part:

Public Member Functions

 Function_split_part ()
 
const mup::char_type * GetDesc () const final
 
mup::IToken * Clone () const final
 
void Eval (mup::ptr_val_type &ret, const mup::ptr_val_type *args, int argc) final
 

Detailed Description

Definition at line 150 of file ExpressionParser.cpp.

Constructor & Destructor Documentation

import_export::anonymous_namespace{ExpressionParser.cpp}::Function_split_part::Function_split_part ( )
inline

Definition at line 152 of file ExpressionParser.cpp.

152 : mup::ICallback(mup::cmFUNC, _T("split_part"), 3) {}

Member Function Documentation

mup::IToken* import_export::anonymous_namespace{ExpressionParser.cpp}::Function_split_part::Clone ( ) const
inlinefinal
void import_export::anonymous_namespace{ExpressionParser.cpp}::Function_split_part::Eval ( mup::ptr_val_type &  ret,
const mup::ptr_val_type *  args,
int  argc 
)
inlinefinal

Definition at line 157 of file ExpressionParser.cpp.

References run_benchmark_import::args, CHECK_EQ, import_export::anonymous_namespace{ExpressionParser.cpp}::ms_to_ss(), anonymous_namespace{Utm.h}::n, import_export::anonymous_namespace{ExpressionParser.cpp}::ss_to_ms(), THROW_INVALID_PARAMETER, and VALIDATE_ARG_TYPE.

157  {
158  CHECK_EQ(argc, 3);
159  VALIDATE_ARG_TYPE(0, 's');
160  VALIDATE_ARG_TYPE(1, 's');
161  VALIDATE_ARG_TYPE(2, 'i');
162  auto const text = ms_to_ss(args[0]->GetString());
163  auto const delimiter = ms_to_ss(args[1]->GetString());
164  auto n = args[2]->GetInteger();
165  try {
166  std::vector<std::string> tokens;
167  // split on exact delimiter (cannot use boost::split)
168  size_t start{0u}, end{0u};
169  while (end != std::string::npos) {
170  end = text.find(delimiter, start);
171  tokens.push_back(text.substr(start, end - start));
172  start = end + delimiter.length();
173  }
174  if (tokens.size() == 0u) {
175  throw std::runtime_error("failed to split");
176  }
177  int index{0};
178  if (n < 0) {
179  // reverse index (-1 = last token)
180  index = static_cast<int>(tokens.size()) + n;
181  } else {
182  // forward index (1 = first token)
183  index = n - 1;
184  }
185  if (index < 0 || index >= static_cast<int>(tokens.size())) {
186  throw std::runtime_error("bad token index");
187  }
188  *ret = ss_to_ms(tokens[index]);
189  } catch (std::runtime_error& e) {
190  THROW_INVALID_PARAMETER(1, e.what());
191  }
192  }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define VALIDATE_ARG_TYPE(arg, t2)
#define THROW_INVALID_PARAMETER(arg, what)
constexpr double n
Definition: Utm.h:38

+ Here is the call graph for this function:

const mup::char_type* import_export::anonymous_namespace{ExpressionParser.cpp}::Function_split_part::GetDesc ( ) const
inlinefinal

Definition at line 153 of file ExpressionParser.cpp.

153  {
154  return _T("split a string by a given separator, then return the nth token");
155  };

The documentation for this class was generated from the following file: