Git Product home page Git Product logo

Comments (6)

peteruithoven avatar peteruithoven commented on August 15, 2024

Looks like we replace the "x" with "*":
https://github.com/elementary/applications-menu/blob/master/src/synapse-plugins/calculator-plugin/calculator-plugin-backend.vala#L60

Afterwards "ne*t" matches the following regexp:
https://github.com/elementary/applications-menu/blob/master/src/synapse-plugins/calculator-plugin/calculator-plugin-backend.vala#L44
Example: https://regex101.com/r/URh3rG

from applications-menu.

peteruithoven avatar peteruithoven commented on August 15, 2024

For reference, current reg exp: ^.*(\w+[\/\+\-\*\^\%\!\&\|]{1,2}\.?\w+|\(-?\d+.*\))+.*$.
What if we go with something like: ^([-\d.]+[\/\+\-\*\^\%\!\&\|]{1,2}[-\d.]+)+$

  • Uses more specific \d instead of \w. Also supporting "-" and ".".
  • Removed .* at start and end, because it's not clear for me why they are there?
  • Removed the \.? before the \w+. Why only allow an optional . before the \w here?
  • Removed |\(-?\d+.*\) because it's not in line with the description of ""

Example: https://regex101.com/r/aSz5MI

Would be really great to have some unit tests on this part, because I'm probably forgetting about many usecases.
Update: I should try this with the existing unit tests.
Update 2: My reg exp fails 50% of the calculator tests 😅

from applications-menu.

peteruithoven avatar peteruithoven commented on August 15, 2024

Looking for "Firefox beta" also returns the 0.

from applications-menu.

jeremypw avatar jeremypw commented on August 15, 2024

Looks like the "x" is interpreted as "multiply" even though the other parts are non-numeric and presumably parse to "0". Should be easy enough to check the non-operator parts are actually numbers?

from applications-menu.

jeremypw avatar jeremypw commented on August 15, 2024

Firefo^ Beta = 1 (interpreted as 0 ^ 0).

from applications-menu.

jeremypw avatar jeremypw commented on August 15, 2024

As bc can handle multiple expressions it is possible for next to be a valid expression: e.g. ne=3;t=4;next gives the expected result 12. The code in this app is too simplistic to handle this kind of thing. It just passes a string that might be a valid mathematical expression(s) to bc and returns the result if bc gives no error. Unfortunately bc does not give an error for undefined variables - just assigns them the value 0. Whether it is worth us trying to check for undefined variables here is questionable. It would be simpler to disallow variables altogether.

from applications-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.