Skip to content

Added new methods for Strings util#1337

Closed
Serwios wants to merge 1 commit intoapache:masterfrom
Serwios:new_strings_methods
Closed

Added new methods for Strings util#1337
Serwios wants to merge 1 commit intoapache:masterfrom
Serwios:new_strings_methods

Conversation

@Serwios
Copy link

@Serwios Serwios commented Dec 13, 2024

Added the following new useful utility methods to Strings:

removeAccents: Removes accents (diacritical marks) from a string.
maskString: Masks a part of a string with a given character.
containsOnly: Checks if a string contains only characters from a specified set.
reverseWords: Reverses the order of words in a string, preserving spaces.
truncateWithEllipsis: Truncates a string and appends ellipsis if truncated.

  • Read the contribution guidelines for this project.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge.

@garydgregory
Copy link
Member

garydgregory commented Dec 14, 2024

Hello @Serwios

-1:

  • You checked the box "Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself." but you obviously didn't do it since the build fails for me locally:
[ERROR] Failures:
[ERROR]   StringsTest.testRemoveAccents:141 expected: <Cafe> but was: <Caf?>

Checkstyle also fails:

[ERROR] src\main\java\org\apache\commons\lang3\Strings.java:[25,1] (imports) ImportOrder: Wrong order for 'java.text.Normalizer' import.
[ERROR] src\main\java\org\apache\commons\lang3\Strings.java:[28,8] (imports) UnusedImports: Unused import - java.util.stream.Collectors.
[ERROR] src\test\java\org\apache\commons\lang3\StringsTest.java:[26,1] (imports) ImportOrder: Wrong order for 'org.junit.jupiter.api.Assertions.*' import.
[ERROR] src\test\java\org\apache\commons\lang3\StringsTest.java:[26,47] (imports) AvoidStarImport: Using the '.*' form of import should be avoided - org.junit.jupiter.api.Assertions.*.

We've deprecated text processing functionality from Lang and moved it to Commons Text. For example, the whole org.apache.commons.lang3.text package is deprecated.

  • Good find on the typos (fixed in git master)
  • truncateWithEllipsis(): See the general note on text processing above. I'm not sure the function is useful as is anyway. Unicode supports the horizontal ellipsis character but this function doesn't use it? Why three periods instead? Should it be configurable, and so on.
  • reverseWords: See the general note on text processing above.
  • containsOnly: How is this different from StringUtils.indexOfAnyBut()?
  • maskString: See the general note on text processing above. In general, there are probably too many variations or use cases. Masking is usually much more complex, like "Replace phone numbers, credit cards, and so on, with X"
  • removeAccents: See the general note on text processing above.

@Serwios Serwios closed this Dec 14, 2024
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