Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new initialization function - NewFromFormattedString #184

Merged
merged 2 commits into from Sep 14, 2020

Conversation

mwoss
Copy link
Member

@mwoss mwoss commented Sep 7, 2020

Motivation:

This new init function was requested more than 3 times (#98 #145 #183), so I thought it's the time we should implement such functionality. Also, personally I think it would be a great addition to the library too.

Implementation:

Implementation is pretty straight-forward. NewFromFormattedString is a wrapper around NewFromString, but before passing the value to mentioned before the init function we replace all characters matched by replRegexp with empty string "". I found this approach the most flexible and appealing for the user of the decimal library. I gathered opinions from my friends and they also agree with me.
I may be wrong, but I think it's a much better approach than creating a init function with any other additional arguments such as: thousandsSeparator and/or prefixToRemove, etc. replRegex gives a lot of freedom and flexibility to the users of this library without adding dozens of arguments to the function signature that they probably don't need.

@mwoss mwoss requested a review from njason September 7, 2020 16:27
@mwoss
Copy link
Member Author

mwoss commented Sep 14, 2020

I'm merging this PR to master. I feel that Jason would approve this PR :D

@mwoss mwoss merged commit ebbf8bb into master Sep 14, 2020
@mwoss mwoss deleted the new-from-formatted-string branch September 14, 2020 17:29
@njason
Copy link
Member

njason commented Sep 15, 2020

LGTM! Sorry for the late response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants