Bug 61759 - New __changeCase function
Summary: New __changeCase function
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.3
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-14 18:28 UTC by Philippe Mouawad
Modified: 2017-12-23 14:32 UTC (History)
2 users (show)



Attachments
Patch with new change case function (14.29 KB, patch)
2017-11-20 07:37 UTC, orimarko
Details | Diff
Patch with update changeCase add support of non English letters (2.30 KB, patch)
2017-11-22 11:00 UTC, orimarko
Details | Diff
Update patch remove camel case (4.94 KB, patch)
2017-11-30 05:59 UTC, orimarko
Details | Diff
Remove camel case from messages (1.95 KB, patch)
2017-12-11 06:07 UTC, orimarko
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Mouawad 2017-11-14 18:28:41 UTC
We frequently need to do such things:

- Upper case
- Lower case


So signature would be:

- __changeCase(MODE, string, exported_var)

Where modes would be:
- UPPER
- LOWER
- CAPITALIZE
Comment 1 orimarko 2017-11-15 10:31:18 UTC
 I suggest adding camel case support (as myVarName), new mode: CAMEL_CASE
Comment 2 Graham Russell 2017-11-15 19:10:12 UTC
What is the use case for these? I'd prefer separate functions i.e.:

__toUpper(string, outputVarName)
__toLower(string, outputVarName)

I think we could have
__capitalise(string, outputVarName)

but it is a bit ambiguous, does it mean just the first letter, or for each sentence or "fully" i.e. each letter after whitespace?

Camel case doesn't seem a common use case to warrant adding, I could be wrong, what did you have in mind? It seems to me ambiguous and hard to implement, what sort of camel case would it apply to "thiscouldbecamelcased" as I'd expect "thisCouldBeCamelCased", but this woudn't be possible to implement well, especially across languages.
Comment 3 Graham Russell 2017-11-15 19:16:34 UTC
Actually, I prefer:

__toUpper(string)
__toLower(string)

which just return the result, rather than having another variable. Similar to __urlencode.
Comment 4 Philippe Mouawad 2017-11-15 20:07:29 UTC
(In reply to Graham Russell from comment #3)
> Actually, I prefer:
> 
> __toUpper(string)
> __toLower(string)
> 
> which just return the result, rather than having another variable. Similar
> to __urlencode.

The aim was to avoid having too many functions.

I feel having a MODE (enum in Java) would be interesting as it would allow adding modes without having to introduce new functions.

It is true that CAPITALIZE might be luxurious, but as it's available with StringUtils and I had the need 2 or 3 times in my work I thought it might be interesting.
We can also add CamelCase
Comment 5 Graham Russell 2017-11-15 21:47:25 UTC
This is slightly off topic (or rather overarching), but to prevent the aversion to introducing more but well named functions we should better design the function names and the function helper. Perhaps something like __StringUtils.toUpper() and the function helper GUI can be organised to group based on the grouping? I will start an email discussion if this seems useful?
Comment 6 orimarko 2017-11-16 14:23:57 UTC
About camel case, we should distinguish between upper and lower camel case,

Someone can expect camelCaseMode or CamelCaseMode

I suggest 2 modes: CAMEL_CASE and CAMEL_CASE_FIRST_LOWER

I suggest it will get a string as "abc_def-Ghi jkl" and return AbcDefGhiJkl or abcDefGhiJkl
Comment 7 orimarko 2017-11-19 07:43:20 UTC
My suggestion:

- __changeCase(string, MODE, exported_var)

Where modes would be:
- UPPER     (default value)
- LOWER
- CAPITALIZE
- CAMEL_CASE 
- CAMEL_CASE_FIRST_LOWER

Only first variable is mandatory
Comment 8 Philippe Mouawad 2017-11-19 08:45:33 UTC
ok for me

(In reply to orimarko from comment #7)
> My suggestion:
> 
> - __changeCase(string, MODE, exported_var)
> 
> Where modes would be:
> - UPPER     (default value)
> - LOWER
> - CAPITALIZE
> - CAMEL_CASE 
> - CAMEL_CASE_FIRST_LOWER
> 
> Only first variable is mandatory
Comment 9 orimarko 2017-11-20 07:37:16 UTC
Created attachment 35538 [details]
Patch with new change case function

Patch with new change case function and tests and documentation
Fixed also duplicate sect-num in functions
Comment 10 Philippe Mouawad 2017-11-20 19:51:10 UTC
Author: pmouawad
Date: Mon Nov 20 19:50:51 2017
New Revision: 1815838

URL: http://svn.apache.org/viewvc?rev=1815838&view=rev
Log:
Bug 61759 - New __changeCase function
Contributed by Orimarko
Bugzilla Id: 61759

Added:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java   (with props)
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java   (with props)
Modified:
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/functions.xml
Comment 11 Philippe Mouawad 2017-11-20 20:05:02 UTC
Author: pmouawad
Date: Mon Nov 20 19:59:48 2017
New Revision: 1815839

URL: http://svn.apache.org/viewvc?rev=1815839&view=rev
Log:
Bug 61759 - New __changeCase function
Add i18n
Bugzilla Id: 61759

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
Comment 12 Philippe Mouawad 2017-11-20 20:34:52 UTC
Author: pmouawad
Date: Mon Nov 20 20:34:10 2017
New Revision: 1815851

URL: http://svn.apache.org/viewvc?rev=1815851&view=rev
Log:
Bug 61759 - New __changeCase function
Handle first char Uppercase error
Bugzilla Id: 61759

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java
Comment 13 Philippe Mouawad 2017-11-20 21:03:42 UTC
Author: pmouawad
Date: Mon Nov 20 20:55:50 2017
New Revision: 1815855

URL: http://svn.apache.org/viewvc?rev=1815855&view=rev
Log:
Bug 61759 - New __changeCase function
Fix checkstyle error
Bugzilla Id: 61759

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java
Comment 14 Philippe Mouawad 2017-11-22 07:34:45 UTC
Author: pmouawad
Date: Wed Nov 22 07:27:11 2017
New Revision: 1816006

URL: http://svn.apache.org/viewvc?rev=1816006&view=rev
Log:
Bug 61759 __changeCase</code> function to change different cases of a string
Take into account some remarks from Felix:
- Change enum names
- Make  CamelCase  work as described in wikipedia
- rename cz
Bugzilla Id: 61759

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java
    jmeter/trunk/xdocs/usermanual/functions.xml
Comment 15 orimarko 2017-11-22 10:45:28 UTC
About regex support of non English letter as umlauts, 

I suggest to use include expression [\s\-_]+ 

Which split words by any group of Whitespace character (\s) hyphen (-) and Undercore (_)
Comment 16 orimarko 2017-11-22 11:00:15 UTC
Created attachment 35545 [details]
Patch with update changeCase add support of non English letters
Comment 17 orimarko 2017-11-29 08:44:10 UTC
I thought camel case would be a nice to have feature, 
But it's not using Apache code as the other cases and I'm not sure it's needed and it raises questions/issues, I'm voting to currently remove camel case option from changeCase function
Comment 18 Graham Russell 2017-11-29 16:54:30 UTC
I agree with removal.
I can't see a use case for it, at least not one worth keeping the code in core. If someone really needs it they can write their own with the particular requirements they have.
Comment 19 orimarko 2017-11-30 05:59:23 UTC
Created attachment 35567 [details]
Update patch remove camel case
Comment 20 Philippe Mouawad 2017-12-09 14:32:42 UTC
Author: pmouawad
Date: Sat Dec  9 14:31:49 2017
New Revision: 1817615

URL: http://svn.apache.org/viewvc?rev=1817615&view=rev
Log:
Bug 61759 - New __changeCase function
Remove camel case as per Ori Marko contribution
More edge cases for changeCase function and slight behaviour changes contributed by Felix Schumacher
This closes #342
Bugzilla Id: 61759

Added:
    jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy
Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java
    jmeter/trunk/xdocs/usermanual/functions.xml
Comment 21 orimarko 2017-12-11 06:07:10 UTC
Created attachment 35599 [details]
Remove camel case from messages

Remove camel case from messages
Comment 22 orimarko 2017-12-11 06:07:47 UTC
Add patch to remove camel case from messages
Comment 23 Philippe Mouawad 2017-12-23 14:32:10 UTC
Author: pmouawad
Date: Sat Dec 23 14:31:52 2017
New Revision: 1819152

URL: http://svn.apache.org/viewvc?rev=1819152&view=rev
Log:
Bug 61759 - New __changeCase function
Remove useless message labels as per orimarko patch
Bugzilla Id: 61759

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties