trungpnt-byte commented on PR #1398:
URL: https://github.com/apache/commons-lang/pull/1398#issuecomment-3015735037

   Dear @ppkarwasz, thank you for the detailed reply and I really appreciate 
them !
   For the ```repeatChars()``` method, it's a generalized version of 
```ensureOneCharacterBetweenWords()```, which then generalizes 
```ensureOneWhitespaceBetweenCharacters()``` - that's why in my draft PR, the 
```ensureOneWhitespaceBetweenCharacters()``` calls the ```repeatChars()``` 
method.
   These are the malformed values I've encountered while working on my company 
products - which allow free-text inputs:
   1. ```"This is       a delivery    comment"```
   2. ```"Please   call  Mr.  John  on arrival"```
   3. ```"{prev_     loan} + 10 *      2"```
   4. 
   5.  ``` " ```
   
   <img width="1272" alt="image" 
src="https://github.com/user-attachments/assets/f148390b-d1f0-498b-863c-ec02336ebeb4";
 />
   
   <img width="1301" alt="image" 
src="https://github.com/user-attachments/assets/7aa4efe6-0c17-46bf-a380-e92f2f44ac00";
 />
   
   Supposed we need to check if those values exist or just sanitize them before 
persisting, from my own experience, I could hardly find an optimal way to 
sanitize these free-text strings to be nicely separated, think the ```trim()``` 
method would only discard spaces from both ends, not those between each word, 
so a combination of ```repeatChars()``` or ```ensureOneWSpace()``` and 
```trim()``` or even internally trimming both-ended chars inside 
```ensureOneWSpace()``` / ```repeatChars()``` would be nice. 
   For this, if there is an existing optimal solution, then I'd love to be all 
ears.
   
   In those malformed values, the whitespaces appear consecutive ( at least 2 ) 
to be resized down to 1, so my mind kind of went to Mars to generalize 
everything into the ```repeatChars()``` - it means it will rebuild a new string 
that includes the appointed characters to be repeated [x] times if they are 
consecutive ( configurable ).
   
   Also, as I've extensively used some ```apache-commons'``` ```StringUtils``` 
method for production code, I think that the ```repeatChar()``` method may be 
useful elsewhere.
   
   I think perhaps the ```repeatChars()``` method seems too generalized for the 
above, so if you think this will be helpful, I'll just include the 
```ensureOneCharacterBetweenWords()``` or  ```ensureOneWhitespace()```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to