Add trim(), split_unit() and split_string() Lua helper functions#1318
Merged
lonvia merged 2 commits intoosm2pgsql-dev:masterfrom Nov 13, 2020
Merged
Add trim(), split_unit() and split_string() Lua helper functions#1318lonvia merged 2 commits intoosm2pgsql-dev:masterfrom
lonvia merged 2 commits intoosm2pgsql-dev:masterfrom
Conversation
lonvia
reviewed
Nov 11, 2020
| end | ||
|
|
||
| function osm2pgsql.split_unit(str, default_unit) | ||
| local val, unit = string.match(str, "^([0-9.]+) ?(%a*)$") |
Collaborator
There was a problem hiding this comment.
Do we want to allow negative values?
Collaborator
Author
There was a problem hiding this comment.
I had thought about that and don't see where this would be useful. width, maxspeed can only be positive. Maybe for ele?
Collaborator
Author
There was a problem hiding this comment.
Its a low-level function that shoulde decide what the correct range of values is, so I have changed it to allow negative values.
The Lua helper functions clamp(), has_prefix(), has_suffix(), trim(), and split_string() now all return nil if they are called with nil as (first) argument. This makes them more robust, for instance when called on non-existent tags and so simplifies user code.
Collaborator
Author
|
PR has now an additional commit adding checks for nil on several Lua functions. |
Collaborator
|
What is the value to adding these as helper functions? |
Collaborator
Author
|
See discussion in #1079 . These are just some pretty generic and useful functions and you got to start somewhere. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.