Hi.

Le sam. 2 août 2025 à 14:53, Kunal Bhangale
<bhangalekunal2631...@gmail.com> a écrit :
>
> Hi  Gilles,
>
> Thanks for the earlier suggestion to consider Apache Commons Text for these
> utility methods.
>
> After reviewing the project, I noticed that Commons Text doesn’t currently
> have a general-purpose utility class like `StringUtils` in Commons Lang.

Probably rightly so, because "...Utils" classes are better avoided.[1]

>
> I’d like to ask:
> Would it be appropriate to introduce a new class such as `TextUtils` under
> the `org.apache.commons.text` package to house general-purpose text-related
> utility methods (like smart truncation, word counting, title casing, etc.)?

Each of the examples inside the parentheses should be discussed separately
in order to determine whether they are "general-purpose".  Indeed, each of
 * smart truncation
 * word counting
 * title casing
has specific features and potential variants that
 * either warrant a class of its own (e.g. "truncation"),
 * or may be too ill-defined (e.g. capitalization of a title depends on the
   language) to belong in a general-purpose library.

Also, we should beware of implementing functionality that already exists
(such as "countWords"[2])

Regards,
Gilles

[1] https://stackoverflow.com/questions/3340032/are-utility-classes-evil
[2] https://stackoverflow.com/questions/5864159/count-words-in-a-string-method

>
> Alternatively, is there an existing class where such methods would be more
> appropriate?
>
> Looking forward to your suggestions and guidance on this.
>
> Best regards,
> Kunal Bhangale
>
> On Sat, Aug 2, 2025 at 2:41 PM Gilles Sadowski <gillese...@gmail.com> wrote:
>
> > Hi.
> >
> > Le sam. 2 août 2025 à 10:55, Kunal Bhangale
> > <bhangalekunal2631...@gmail.com> a écrit :
> > >
> > > Hi Commons Lang Developers,
> > >
> > > I would like to propose the addition of some new utility methods to
> > > `StringUtils` in Apache Commons Lang. These methods are commonly needed
> > in
> > > real-world projects but currently not available in the library.
> > >
> > > Here are some initial ideas:
> > >
> > >
> > > 1. *findAllOccurrences(String str, String subStr)*
> > >    - Description: Returns a list of all indexes where a substring occurs
> > in
> > > the main string.
> > >    - Example: findAllOccurrences("abcabc", "a") → [0, 3]
> > >
> > > 2. *toTitleCase(String str)*
> > >    - Description: Converts each word's first character to uppercase and
> > the
> > > rest to lowercase.
> > >    - Example: toTitleCase("hello world") → "Hello World"
> > >
> > > 3. *smartTruncate(String str, int maxLength)*
> > >    - Description: Truncates the string to the nearest full word under the
> > > limit and appends "..." if needed.
> > >    - Example: smartTruncate("This is a long sentence", 10) → "This is..."
> > >
> > > 4. *removeRepeatedCharacters(String str)*
> > >    - Description: Removes consecutive duplicate characters.
> > >    - Example: removeRepeatedCharacters("aaabbbcccaaa") → "abca"
> > >
> > > 5. *isTitleCase(String str)*
> > >    - Description: Checks if the input is in title case format.
> > >    - Example: isTitleCase("Hello World") → true
> > >
> > > 6. *countWords(String str)*
> > >    - Description: Returns the number of words in the input string.
> > >    - Example: countWords("Apache Commons Lang") → 3
> > >
> > >
> > > I’d be happy to implement these methods and write appropriate JUnit
> > tests.
> > > If the community finds these valuable, I can create a JIRA issue and
> > start
> > > working on the patch.
> >
> > Thanks for your interest in contributing to "Commons".
> >
> > > Looking forward to your feedback!
> >
> > Your proposed utilities seem better suited to [Text] than [Lang].
> > Did you have a look there:
> >   https://commons.apache.org/text
> > ?
> >
> > Regards,
> > Gilles
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> > For additional commands, e-mail: dev-h...@commons.apache.org
> >
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to