You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by achristianson <gi...@git.apache.org> on 2018/01/17 19:46:08 UTC
[GitHub] nifi-minifi-cpp pull request #243: MINIFICPP-367 Implement expression langua...
GitHub user achristianson opened a pull request:
https://github.com/apache/nifi-minifi-cpp/pull/243
MINIFICPP-367 Implement expression language arithmetic operations
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [x] Does your PR title start with MINIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
- [x] Is your initial contribution a single, squashed commit?
### For code changes:
- [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [x] If applicable, have you updated the LICENSE file?
- [x] If applicable, have you updated the NOTICE file?
### For documentation related changes:
- [x] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/achristianson/nifi-minifi-cpp MINIFICPP-367
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi-minifi-cpp/pull/243.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #243
----
commit 1c4c0005f61a4672ff3c5892f06009e179d20289
Author: Andy I. Christianson <an...@...>
Date: 2018-01-16T21:05:47Z
MINIFICPP-367 Implement expression language arithmetic operations
----
---
[GitHub] nifi-minifi-cpp pull request #243: MINIFICPP-367 Implement expression langua...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/nifi-minifi-cpp/pull/243
---
[GitHub] nifi-minifi-cpp issue #243: MINIFICPP-367 Implement expression language arit...
Posted by phrocker <gi...@git.apache.org>.
Github user phrocker commented on the issue:
https://github.com/apache/nifi-minifi-cpp/pull/243
merging now
---
[GitHub] nifi-minifi-cpp pull request #243: MINIFICPP-367 Implement expression langua...
Posted by phrocker <gi...@git.apache.org>.
Github user phrocker commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/243#discussion_r162199080
--- Diff: extensions/expression-language/Expression.cpp ---
@@ -146,6 +149,124 @@ std::string expr_replaceEmpty(const std::vector<std::string> &args) {
#endif // EXPRESSION_LANGUAGE_USE_REGEX
+std::string expr_binaryOp(const std::vector<std::string> &args,
+ long double (*ldop)(long double, long double),
+ int (*iop)(int, int),
+ bool long_only = false) {
+ try {
+ if (!long_only &&
+ args[0].find('.') == args[0].npos &&
+ args[1].find('.') == args[1].npos &&
+ args[1].find('e') == args[1].npos &&
+ args[0].find('e') == args[0].npos &&
+ args[0].find('E') == args[0].npos &&
+ args[1].find('E') == args[1].npos) {
+ return std::to_string(iop(std::stoi(args[0]), std::stoi(args[1])));
+ } else {
+ std::stringstream ss;
+ ss << std::fixed << std::setprecision(std::numeric_limits<double>::digits10)
+ << ldop(std::stold(args[0]), std::stold(args[1]));
+ auto result = ss.str();
+ result.erase(result.find_last_not_of('0') + 1, std::string::npos);
+
+ if (result.find('.') == result.length() - 1) {
+ result.erase(result.length() - 1, std::string::npos);
+ }
+
+ return result;
+ }
+ } catch (const std::exception &e) {
+ return "";
+ }
+}
+
+std::string expr_plus(const std::vector<std::string> &args) {
+ return expr_binaryOp(args,
+ [](long double a, long double b) { return a + b; },
--- End diff --
does it make sense to define these lambda's statically?
---