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

New leftpad and rightpad DSL functions #1205

Merged
merged 4 commits into from
Feb 26, 2023
Merged

New leftpad and rightpad DSL functions #1205

merged 4 commits into from
Feb 26, 2023

Conversation

johnkerl
Copy link
Owner

@johnkerl johnkerl commented Feb 26, 2023

Context: #1153 and #1166

Examples:

$ echo x=1234567 | mlr put '$x=leftpad($x, 10, "*")'
x=***1234567
$ echo x=1234567 | mlr put '$x=rightpad($x, 10, "*")'
x=1234567***
$ mlr help function leftpad
leftpad  (class=string #args=3) Left-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
Examples:
leftpad("abcdefg", 10 , "*") gives "***abcdefg".
leftpad("abcdefg", 10 , "XY") gives "XYabcdefg".
leftpad("1234567", 10 , "0") gives "0001234567".
$ mlr help function rightpad
rightpad  (class=string #args=3) Right-pads first argument to at most the specified length (second, integer argument) using specified pad value (third, string argument). If the first argument is not a string, it will be stringified first.
Examples:
rightpad("abcdefg", 10 , "*") gives "abcdefg***".
rightpad("abcdefg", 10 , "XY") gives "abcdefgXY".
rightpad("1234567", 10 , "0") gives "1234567000".

Unit-test cases to be uploaded next.

@derekmahar
Copy link
Contributor

Are the results in these examples from above correct? I think you may have swapped the results.

leftpad("1234567", 10 , "0") gives "1234567000".
rightpad("1234567", 10 , "0") gives "0001234567".

@johnkerl
Copy link
Owner Author

@derekmahar typo indeed, thanks!

@johnkerl johnkerl marked this pull request as ready for review February 26, 2023 18:02
@johnkerl johnkerl merged commit ee0ac3d into main Feb 26, 2023
@johnkerl johnkerl deleted the kerl/pad-funcs branch February 26, 2023 22:14
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.

2 participants