siddhi-io / siddhi-execution-string

Extension that provides basic string handling capabilities
https://wso2-extensions.github.io/siddhi-execution-string/
Apache License 2.0
4 stars 37 forks source link

Adding new extensions for map and evaluate strings #61

Closed BuddhiWathsala closed 5 years ago

BuddhiWathsala commented 5 years ago

Description:

Problem

Currently, Siddhi execution string does not support string manipulation for the following scenarios.

  1. Let say I have a stringS=" {{prize}} > 100 " and the value of the prize coming from a different stream. Assume that, now the prize is 300. Then I need to get the string S'= "300 > 100"
  2. The next scenario is get the string S' = "300 > 100" and evaluate it. The evaluation of that mathematical expression should return true.

Suggestion

  1. Implement an extension called str: map(STRING, STRING...) and this will return a STRING.
  2. Implement an extension called str: eval(STRING, STRING...) and this will return an Object.

Suggested Labels: Feature improvement

BuddhiWathsala commented 5 years ago

According to the discussion of this siddhi-dev mail thread, we are going to implement two functions to cater above requirements.

  1. Update previous str:fillTemplate receive a string and a key-value map. Then replace all key entries with a corresponding value. For example it will receive,

    str:fillTemplate("{{prize}} > 100 && {{salary}} < 10000",  map:create('prize', 300, 'salary', 10000)))

    and return string 300 > 100 && 10000 < 10000

  2. Then we will add another function js:eval( "56 > 76", 'bool') to evaluate expressions in https://github.com/siddhi-io/siddhi-script-js