Github user phrocker commented on a diff in the pull request: https://github.com/apache/nifi-minifi-cpp/pull/219#discussion_r156815480 --- Diff: extensions/expression-language/Expression.cpp --- @@ -64,12 +64,44 @@ std::string expr_toUpper(const std::vector<std::string> &args) { return result; } +std::string expr_substring(const std::vector<std::string> &args) { + if (args.size() < 3) { + return args[0].substr(std::stoul(args[1])); + } else { + return args[0].substr(std::stoul(args[1]), std::stoul(args[2])); + } +} + +std::string expr_substringBefore(const std::vector<std::string> &args) { + return args[0].substr(0, args[0].find(args[1])); +} + +std::string expr_substringBeforeLast(const std::vector<std::string> &args) { + size_t last_pos = 0; + while (args[0].find(args[1], last_pos + 1) != std::string::npos) { + last_pos = args[0].find(args[1], last_pos + 1); + } + return args[0].substr(0, last_pos); +} + +std::string expr_substringAfter(const std::vector<std::string> &args) { + return args[0].substr(args[0].find(args[1]) + args[1].length()); +} + +std::string expr_substringAfterLast(const std::vector<std::string> &args) { + size_t last_pos = 0; + while (args[0].find(args[1], last_pos + 1) != std::string::npos) { + last_pos = args[0].find(args[1], last_pos + 1); + } + return args[0].substr(last_pos + args[1].length()); +} + template<std::string T(const std::vector<std::string> &)> Expression make_dynamic_function_incomplete(const std::string &function_name, const std::vector<Expression> &args, std::size_t num_args) { - if (args.size() == num_args) { --- End diff -- Based on my comment below, it seems like we'll simply throw "Attempted to call incomplete function" Is this a correct interpretation?
---