Skip to content

Add trim(), split_unit() and split_string() Lua helper functions#1318

Merged
lonvia merged 2 commits intoosm2pgsql-dev:masterfrom
joto:lua-helper
Nov 13, 2020
Merged

Add trim(), split_unit() and split_string() Lua helper functions#1318
lonvia merged 2 commits intoosm2pgsql-dev:masterfrom
joto:lua-helper

Conversation

@joto
Copy link
Copy Markdown
Collaborator

@joto joto commented Nov 10, 2020

No description provided.

Comment thread src/init.lua Outdated
end

function osm2pgsql.split_unit(str, default_unit)
local val, unit = string.match(str, "^([0-9.]+) ?(%a*)$")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to allow negative values?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought about that and don't see where this would be useful. width, maxspeed can only be positive. Maybe for ele?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a low-level function that shoulde decide what the correct range of values is, so I have changed it to allow negative values.

joto added 2 commits November 11, 2020 14:48
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.
@joto
Copy link
Copy Markdown
Collaborator Author

joto commented Nov 11, 2020

PR has now an additional commit adding checks for nil on several Lua functions.

@pnorman
Copy link
Copy Markdown
Collaborator

pnorman commented Nov 11, 2020

What is the value to adding these as helper functions?

@joto
Copy link
Copy Markdown
Collaborator Author

joto commented Nov 11, 2020

See discussion in #1079 . These are just some pretty generic and useful functions and you got to start somewhere.

@lonvia lonvia merged commit fcd30e0 into osm2pgsql-dev:master Nov 13, 2020
@joto joto deleted the lua-helper branch November 13, 2020 08:40
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.

3 participants