You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephan Peters <st...@csuglobal.edu.INVALID> on 2024/04/09 20:37:00 UTC
commons.text.CaseUtils
I added several methods to the org.apache.commons.CaseUtils class I think
would be very useful, for example to use for normalized naming conventions
for file paths, file names, URLs, etc.
I'm planning on initiating a pull request.
I would like to discuss it here.
I've posted it in a fork here:
https://github.com/speters33w/commons-text/blob/master/src/main/java/org/apache/commons/text/CaseUtils.java
and written new tests for all the methods that pass here:
https://github.com/speters33w/commons-text/blob/master/src/test/java/org/apache/commons/text/CaseUtilsTest.java
There is an example of the method return values at the top of the revised
CaseUtils.java.
The methods have a little different behavior than the existing
toCamelCase(String, boolean, char[]) (which I left intact) in that they
normalize the input first before processing, so toCamelSnakeCase("The
café’s piñata gave me déjà vu.") will return
"the_Cafes_Pinata_Gave_Me_Deja_Vu"
The main driver engine is in the toTitleCase() method and the rest of the
methods piggyback on that engine and perform minor changes to the return
value.
If anyone feels like taking a look, I'd appreciate any feedback.
Thank you.
Stephan Peters
Re: commons.text.CaseUtils
Posted by Stephan Peters <st...@csuglobal.edu.INVALID>.
Daniel,
I just cloned what's done on PR 450. I haven't been able to do much on mine
(or yours) yet, I will devote some time Sunday to revising my PR 528 and
looking at your PR 450 with more detail.
I am thinking the existing toCamelCase(String, boolean, char[]) might be
better depreciated and its functionality moved to WordUtils with
CapitalizeFully(), just stripping the space.
I would expect camelCase, etc to be normalized, but the functionality of
changing characters to Title Case (Unicode definition, which includes
accented characters) should not be taken away from Apache Commons.
You may have addressed this already, All I have done is skimmed the
conversation in PR 450 and cloned the PR. I haven't looked at it in any
detail yet.
I'm sure we will be talking about this later,
-Stephan
On Thu, Apr 11, 2024 at 7:52 AM Daniel Watson <dc...@gmail.com> wrote:
> Stephan,
>
> On that note, I worked on the initial implementation for PR 450, and had to
> pause for work but am planning to resume soon, but definitely contribute
> and/or provide any thoughts as it's definitely a big change from the
> current CaseUtils.
>
> Regards,
> Dan
>
> On Wed, Apr 10, 2024, 9:20 PM Stephan Peters
> <st...@csuglobal.edu.invalid> wrote:
>
> > Gary, thank you for your response.
> >
> > I initiated the pull request (#528) and already received some very
> > constructive feedback from user mbenson.
> > I am modifying the code to contain fewer methods that may be externally
> > modified by a user, if something as simple as .toLowerCase() is required.
> >
> > I also noticed some recent discussion of this which you commented on in
> > pull 450 Cases API + 4 implementations (Pascal, Camel, Kebab, Snake)
> #450
> >
> > When I am done with the edits and new tests and pushed them to my fork, I
> > may join this conversation #450.
> >
> > My Jira account has been approved (after an initial disapproval.) I
> haven't
> > looked at it yet, I will look for similar topics there.
> >
> > I also uncovered an issue with my code when I devised some tests I
> > specifically designed to break it if possible, and I need to fix this.
> >
> > assertThat(CaseUtils.toTitleCase(" ' \u2019 Titl'e Case \u2019 '
> > ")).isEqualTo("Title_Case"); // todo fix this failure.
> >
> > org.opentest4j.AssertionFailedError:
> > expected: "Title_Case"
> > but was: "Title_Case_’_'"
> > Expected :"Title_Case"
> > Actual :"Title_Case_’_'"
> >
> > This is because of the way I handle apostrophes so "That's good!" will
> > return "Thats_Good"
> >
> > Again, thank you for your response.
> >
> > Stephan Peters
> >
> >
> > On Tue, Apr 9, 2024 at 5:56 PM Stephan Peters <
> > stephan.peters@csuglobal.edu>
> > wrote:
> >
> > > OK, I will initiate a PR.
> > > Some of the added methods will be more useful than others.
> > > The PR will come from speters33w.
> > >
> > > Thank you,
> > > Stephan Peters
> > >
> > > On Tue, Apr 9, 2024 at 5:31 PM Gary Gregory <ga...@gmail.com>
> > > wrote:
> > >
> > >> Hello Stephan,
> > >>
> > >> The best way to see what you are proposing is a PR, it's a bit painful
> > to
> > >> see differences otherwise, at least for me.
> > >>
> > >> That said anything new should solve a real world use case, not merely
> > >> something that might be useful (or not) 😉
> > >>
> > >> I think seeing tests in a PR will help clarify what it is you are
> > >> proposing
> > >> that the current code doesn't do.
> > >>
> > >> See also also https://github.com/apache/commons-text/pull/450
> > >>
> > >> TY,
> > >> Gary
> > >>
> > >> On Tue, Apr 9, 2024, 4:37 PM Stephan Peters
> > >> <st...@csuglobal.edu.invalid> wrote:
> > >>
> > >> > I added several methods to the org.apache.commons.CaseUtils class I
> > >> think
> > >> > would be very useful, for example to use for normalized naming
> > >> conventions
> > >> > for file paths, file names, URLs, etc.
> > >> >
> > >> > I'm planning on initiating a pull request.
> > >> >
> > >> > I would like to discuss it here.
> > >> >
> > >> > I've posted it in a fork here:
> > >> >
> > >> >
> > >>
> >
> https://github.com/speters33w/commons-text/blob/master/src/main/java/org/apache/commons/text/CaseUtils.java
> > >> >
> > >> > and written new tests for all the methods that pass here:
> > >> >
> > >> >
> > >>
> >
> https://github.com/speters33w/commons-text/blob/master/src/test/java/org/apache/commons/text/CaseUtilsTest.java
> > >> >
> > >> > There is an example of the method return values at the top of the
> > >> revised
> > >> > CaseUtils.java.
> > >> >
> > >> > The methods have a little different behavior than the existing
> > >> > toCamelCase(String, boolean, char[]) (which I left intact) in that
> > they
> > >> > normalize the input first before processing, so
> toCamelSnakeCase("The
> > >> > café’s piñata gave me déjà vu.") will return
> > >> > "the_Cafes_Pinata_Gave_Me_Deja_Vu"
> > >> >
> > >> > The main driver engine is in the toTitleCase() method and the rest
> of
> > >> the
> > >> > methods piggyback on that engine and perform minor changes to the
> > return
> > >> > value.
> > >> >
> > >> > If anyone feels like taking a look, I'd appreciate any feedback.
> > >> >
> > >> > Thank you.
> > >> >
> > >> > Stephan Peters
> > >> >
> > >>
> > >
> >
>
Re: commons.text.CaseUtils
Posted by Daniel Watson <dc...@gmail.com>.
Stephan,
On that note, I worked on the initial implementation for PR 450, and had to
pause for work but am planning to resume soon, but definitely contribute
and/or provide any thoughts as it's definitely a big change from the
current CaseUtils.
Regards,
Dan
On Wed, Apr 10, 2024, 9:20 PM Stephan Peters
<st...@csuglobal.edu.invalid> wrote:
> Gary, thank you for your response.
>
> I initiated the pull request (#528) and already received some very
> constructive feedback from user mbenson.
> I am modifying the code to contain fewer methods that may be externally
> modified by a user, if something as simple as .toLowerCase() is required.
>
> I also noticed some recent discussion of this which you commented on in
> pull 450 Cases API + 4 implementations (Pascal, Camel, Kebab, Snake) #450
>
> When I am done with the edits and new tests and pushed them to my fork, I
> may join this conversation #450.
>
> My Jira account has been approved (after an initial disapproval.) I haven't
> looked at it yet, I will look for similar topics there.
>
> I also uncovered an issue with my code when I devised some tests I
> specifically designed to break it if possible, and I need to fix this.
>
> assertThat(CaseUtils.toTitleCase(" ' \u2019 Titl'e Case \u2019 '
> ")).isEqualTo("Title_Case"); // todo fix this failure.
>
> org.opentest4j.AssertionFailedError:
> expected: "Title_Case"
> but was: "Title_Case_’_'"
> Expected :"Title_Case"
> Actual :"Title_Case_’_'"
>
> This is because of the way I handle apostrophes so "That's good!" will
> return "Thats_Good"
>
> Again, thank you for your response.
>
> Stephan Peters
>
>
> On Tue, Apr 9, 2024 at 5:56 PM Stephan Peters <
> stephan.peters@csuglobal.edu>
> wrote:
>
> > OK, I will initiate a PR.
> > Some of the added methods will be more useful than others.
> > The PR will come from speters33w.
> >
> > Thank you,
> > Stephan Peters
> >
> > On Tue, Apr 9, 2024 at 5:31 PM Gary Gregory <ga...@gmail.com>
> > wrote:
> >
> >> Hello Stephan,
> >>
> >> The best way to see what you are proposing is a PR, it's a bit painful
> to
> >> see differences otherwise, at least for me.
> >>
> >> That said anything new should solve a real world use case, not merely
> >> something that might be useful (or not) 😉
> >>
> >> I think seeing tests in a PR will help clarify what it is you are
> >> proposing
> >> that the current code doesn't do.
> >>
> >> See also also https://github.com/apache/commons-text/pull/450
> >>
> >> TY,
> >> Gary
> >>
> >> On Tue, Apr 9, 2024, 4:37 PM Stephan Peters
> >> <st...@csuglobal.edu.invalid> wrote:
> >>
> >> > I added several methods to the org.apache.commons.CaseUtils class I
> >> think
> >> > would be very useful, for example to use for normalized naming
> >> conventions
> >> > for file paths, file names, URLs, etc.
> >> >
> >> > I'm planning on initiating a pull request.
> >> >
> >> > I would like to discuss it here.
> >> >
> >> > I've posted it in a fork here:
> >> >
> >> >
> >>
> https://github.com/speters33w/commons-text/blob/master/src/main/java/org/apache/commons/text/CaseUtils.java
> >> >
> >> > and written new tests for all the methods that pass here:
> >> >
> >> >
> >>
> https://github.com/speters33w/commons-text/blob/master/src/test/java/org/apache/commons/text/CaseUtilsTest.java
> >> >
> >> > There is an example of the method return values at the top of the
> >> revised
> >> > CaseUtils.java.
> >> >
> >> > The methods have a little different behavior than the existing
> >> > toCamelCase(String, boolean, char[]) (which I left intact) in that
> they
> >> > normalize the input first before processing, so toCamelSnakeCase("The
> >> > café’s piñata gave me déjà vu.") will return
> >> > "the_Cafes_Pinata_Gave_Me_Deja_Vu"
> >> >
> >> > The main driver engine is in the toTitleCase() method and the rest of
> >> the
> >> > methods piggyback on that engine and perform minor changes to the
> return
> >> > value.
> >> >
> >> > If anyone feels like taking a look, I'd appreciate any feedback.
> >> >
> >> > Thank you.
> >> >
> >> > Stephan Peters
> >> >
> >>
> >
>
Re: commons.text.CaseUtils
Posted by Stephan Peters <st...@csuglobal.edu.INVALID>.
Gary, thank you for your response.
I initiated the pull request (#528) and already received some very
constructive feedback from user mbenson.
I am modifying the code to contain fewer methods that may be externally
modified by a user, if something as simple as .toLowerCase() is required.
I also noticed some recent discussion of this which you commented on in
pull 450 Cases API + 4 implementations (Pascal, Camel, Kebab, Snake) #450
When I am done with the edits and new tests and pushed them to my fork, I
may join this conversation #450.
My Jira account has been approved (after an initial disapproval.) I haven't
looked at it yet, I will look for similar topics there.
I also uncovered an issue with my code when I devised some tests I
specifically designed to break it if possible, and I need to fix this.
assertThat(CaseUtils.toTitleCase(" ' \u2019 Titl'e Case \u2019 '
")).isEqualTo("Title_Case"); // todo fix this failure.
org.opentest4j.AssertionFailedError:
expected: "Title_Case"
but was: "Title_Case_’_'"
Expected :"Title_Case"
Actual :"Title_Case_’_'"
This is because of the way I handle apostrophes so "That's good!" will
return "Thats_Good"
Again, thank you for your response.
Stephan Peters
On Tue, Apr 9, 2024 at 5:56 PM Stephan Peters <st...@csuglobal.edu>
wrote:
> OK, I will initiate a PR.
> Some of the added methods will be more useful than others.
> The PR will come from speters33w.
>
> Thank you,
> Stephan Peters
>
> On Tue, Apr 9, 2024 at 5:31 PM Gary Gregory <ga...@gmail.com>
> wrote:
>
>> Hello Stephan,
>>
>> The best way to see what you are proposing is a PR, it's a bit painful to
>> see differences otherwise, at least for me.
>>
>> That said anything new should solve a real world use case, not merely
>> something that might be useful (or not) 😉
>>
>> I think seeing tests in a PR will help clarify what it is you are
>> proposing
>> that the current code doesn't do.
>>
>> See also also https://github.com/apache/commons-text/pull/450
>>
>> TY,
>> Gary
>>
>> On Tue, Apr 9, 2024, 4:37 PM Stephan Peters
>> <st...@csuglobal.edu.invalid> wrote:
>>
>> > I added several methods to the org.apache.commons.CaseUtils class I
>> think
>> > would be very useful, for example to use for normalized naming
>> conventions
>> > for file paths, file names, URLs, etc.
>> >
>> > I'm planning on initiating a pull request.
>> >
>> > I would like to discuss it here.
>> >
>> > I've posted it in a fork here:
>> >
>> >
>> https://github.com/speters33w/commons-text/blob/master/src/main/java/org/apache/commons/text/CaseUtils.java
>> >
>> > and written new tests for all the methods that pass here:
>> >
>> >
>> https://github.com/speters33w/commons-text/blob/master/src/test/java/org/apache/commons/text/CaseUtilsTest.java
>> >
>> > There is an example of the method return values at the top of the
>> revised
>> > CaseUtils.java.
>> >
>> > The methods have a little different behavior than the existing
>> > toCamelCase(String, boolean, char[]) (which I left intact) in that they
>> > normalize the input first before processing, so toCamelSnakeCase("The
>> > café’s piñata gave me déjà vu.") will return
>> > "the_Cafes_Pinata_Gave_Me_Deja_Vu"
>> >
>> > The main driver engine is in the toTitleCase() method and the rest of
>> the
>> > methods piggyback on that engine and perform minor changes to the return
>> > value.
>> >
>> > If anyone feels like taking a look, I'd appreciate any feedback.
>> >
>> > Thank you.
>> >
>> > Stephan Peters
>> >
>>
>
Re: commons.text.CaseUtils
Posted by Stephan Peters <st...@csuglobal.edu.INVALID>.
OK, I will initiate a PR.
Some of the added methods will be more useful than others.
The PR will come from speters33w.
Thank you,
Stephan Peters
On Tue, Apr 9, 2024 at 5:31 PM Gary Gregory <ga...@gmail.com> wrote:
> Hello Stephan,
>
> The best way to see what you are proposing is a PR, it's a bit painful to
> see differences otherwise, at least for me.
>
> That said anything new should solve a real world use case, not merely
> something that might be useful (or not) 😉
>
> I think seeing tests in a PR will help clarify what it is you are proposing
> that the current code doesn't do.
>
> See also also https://github.com/apache/commons-text/pull/450
>
> TY,
> Gary
>
> On Tue, Apr 9, 2024, 4:37 PM Stephan Peters
> <st...@csuglobal.edu.invalid> wrote:
>
> > I added several methods to the org.apache.commons.CaseUtils class I think
> > would be very useful, for example to use for normalized naming
> conventions
> > for file paths, file names, URLs, etc.
> >
> > I'm planning on initiating a pull request.
> >
> > I would like to discuss it here.
> >
> > I've posted it in a fork here:
> >
> >
> https://github.com/speters33w/commons-text/blob/master/src/main/java/org/apache/commons/text/CaseUtils.java
> >
> > and written new tests for all the methods that pass here:
> >
> >
> https://github.com/speters33w/commons-text/blob/master/src/test/java/org/apache/commons/text/CaseUtilsTest.java
> >
> > There is an example of the method return values at the top of the revised
> > CaseUtils.java.
> >
> > The methods have a little different behavior than the existing
> > toCamelCase(String, boolean, char[]) (which I left intact) in that they
> > normalize the input first before processing, so toCamelSnakeCase("The
> > café’s piñata gave me déjà vu.") will return
> > "the_Cafes_Pinata_Gave_Me_Deja_Vu"
> >
> > The main driver engine is in the toTitleCase() method and the rest of the
> > methods piggyback on that engine and perform minor changes to the return
> > value.
> >
> > If anyone feels like taking a look, I'd appreciate any feedback.
> >
> > Thank you.
> >
> > Stephan Peters
> >
>
Re: commons.text.CaseUtils
Posted by Gary Gregory <ga...@gmail.com>.
Hello Stephan,
The best way to see what you are proposing is a PR, it's a bit painful to
see differences otherwise, at least for me.
That said anything new should solve a real world use case, not merely
something that might be useful (or not) 😉
I think seeing tests in a PR will help clarify what it is you are proposing
that the current code doesn't do.
See also also https://github.com/apache/commons-text/pull/450
TY,
Gary
On Tue, Apr 9, 2024, 4:37 PM Stephan Peters
<st...@csuglobal.edu.invalid> wrote:
> I added several methods to the org.apache.commons.CaseUtils class I think
> would be very useful, for example to use for normalized naming conventions
> for file paths, file names, URLs, etc.
>
> I'm planning on initiating a pull request.
>
> I would like to discuss it here.
>
> I've posted it in a fork here:
>
> https://github.com/speters33w/commons-text/blob/master/src/main/java/org/apache/commons/text/CaseUtils.java
>
> and written new tests for all the methods that pass here:
>
> https://github.com/speters33w/commons-text/blob/master/src/test/java/org/apache/commons/text/CaseUtilsTest.java
>
> There is an example of the method return values at the top of the revised
> CaseUtils.java.
>
> The methods have a little different behavior than the existing
> toCamelCase(String, boolean, char[]) (which I left intact) in that they
> normalize the input first before processing, so toCamelSnakeCase("The
> café’s piñata gave me déjà vu.") will return
> "the_Cafes_Pinata_Gave_Me_Deja_Vu"
>
> The main driver engine is in the toTitleCase() method and the rest of the
> methods piggyback on that engine and perform minor changes to the return
> value.
>
> If anyone feels like taking a look, I'd appreciate any feedback.
>
> Thank you.
>
> Stephan Peters
>