[ 
https://issues.apache.org/jira/browse/NIFI-6500?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16914776#comment-16914776
 ] 

ASF subversion and git services commented on NIFI-6500:
-------------------------------------------------------

Commit bb9758be2cc2f1dd3d58166025d55f37d770823d in nifi's branch 
refs/heads/master from Alessandro D'Armiento
[ https://gitbox.apache.org/repos/asf?p=nifi.git;h=bb9758b ]

NIFI-6500 (Original commit messages left to preserve authorship credit for 
multiple contributors)

Expression Language now supports padding functions:
- padLeft:
  -  attr:padLeft(Int n, Char c) will prepend to the `attr` attributes the `c` 
character until the size `n` is reached
  -  attr:padLeft(Int n) will prepend to the `attr` attributes the `'_'` 
character until the size `n` is reached
- padRight:
  -  attr:padRight(Int n, Char c) will append to the `attr` attributes the `c` 
character until the size `n` is reached
  -  attr:padRight(Int n) will append to the `attr` attributes the `'_'` 
character until the size `n` is reached

- In both cases, the padding function returns the `attr` `String` as is if its 
length is already equal of higher than the desired size `n`
- Returns null if `attr` does not exist or in case desiredLenght is higher than 
Integer.MAX_INT

Further test cases:
- Returns null if the input string is null
- Returns a string full of padding if the input string is empty
Supports PaddingString instead of PaddingCharacter
Apply suggestions from code review
Applying style suggestions
Co-Authored-By: Marco Gaido <[email protected]>
style fixes
style fixes
Padding returns input string instead of null in case desired length is missing, 
is negative, or is overflowing
Better tests
doc update
less verbose parser notation
Doc and style fixes
Fixed `StringEvaluator.evaluate()` after rebase
Applying nitpicking suggestion
Co-Authored-By: Marco Gaido <[email protected]>
Fixed `PaddingEvaluator` constructor issue
Removed unused import

This closes #3615

Signed-off-by: Mike Thomsen <[email protected]>


> Add padLeft() and padRight() functions to expression language
> -------------------------------------------------------------
>
>                 Key: NIFI-6500
>                 URL: https://issues.apache.org/jira/browse/NIFI-6500
>             Project: Apache NiFi
>          Issue Type: New Feature
>          Components: Core Framework
>    Affects Versions: 1.9.2
>            Reporter: Alessandro D'Armiento
>            Priority: Minor
>          Time Spent: 7h 20m
>  Remaining Estimate: 0h
>
> h2. Current Situation
> - [Expression Language string 
> manipulation|https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#strings]
>  doesn't have anything to perform string padding
> - Existing solutions to achieve left or right padding are unintuitive
> -- Es: 
> ${prop:prepend('0000'):substring(${prop:length()},${prop:length():plus(4)})}
> h1. Improvement Proposal
> - Support two new expression language methods
> -- padLeft:
> --- padLeft(int n) will prepend a default character to of the input string 
> until it reaches the length n
> --- padLeft(int n, char c) will prepend the c characters to the input string 
> until it reaches the length n
> -- padRight:
> --- padRight(int n) will append a default character to the input string until 
> it reaches the length n
> --- padRight(int n, char c) will append the c character to the input string 
> until it reaches the length n
> -- Default character should be a renderable character such as underscore
> -- If the input string is already longer than the padding length, no 
> operation should be performed 
> h3. Examples
> ----
> input = "myString"
> ----
> - ${input:padLeft(10, '#')} => "##myString"
> - ${input:padRight(10, '#')} => "myString##"
> - ${input:padLeft(10)} => "__myString"
> - ${input:padRight(10)} => "myString__"



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to