Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Query returns CamelCase string(Definition of regex to convert a snake to came case string)
Query returns CamelCase string [message #1830098] Fri, 17 July 2020 09:12 Go to next message
Michael Nestler is currently offline Michael NestlerFriend
Messages: 30
Registered: September 2014
Member
Hi,

I have a question regarding an Acceleo query to convert a snake to camel case string. I have problems to find the correct regex replace expression.

e.g.
snake_string = "camel_case" to CamelCase

[query public convertToCamelCase(snakeCase : String) : String = snakeCase.replaceAll('_([a-z])', '\\U$1').toUpperFirst()/]

with that query I get
CamelUcase. It seems '\\U$1' is the wrong expression. The 'U' is not recognized to convert the backtrace $1.

Best regards
Michael
Re: Query returns CamelCase string [message #1830104 is a reply to message #1830098] Fri, 17 July 2020 11:02 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7658
Registered: July 2009
Senior Member
Hi

I suggest you debug it in Java / ask on a Java forum since the Acceleo implementation almost certainly just calls a Java routine mindlessly.

Regards

Ed Willink
Re: Query returns CamelCase string [message #1830113 is a reply to message #1830104] Fri, 17 July 2020 13:43 Go to previous messageGo to next message
Michael Nestler is currently offline Michael NestlerFriend
Messages: 30
Registered: September 2014
Member
Hi Ed,

I have checked the replaceAll(...) function in a Java wrapper. The same behavior, it seems, it is not foreseen to manipulate the backtrack $1 in such a way.
I write an own function to do this.

Regards
Michael

Re: Query returns CamelCase string [message #1854923 is a reply to message #1830113] Sun, 18 September 2022 17:48 Go to previous message
Hamza Natek is currently offline Hamza NatekFriend
Messages: 1
Registered: September 2022
Junior Member
Hello Michael,

can you please share the function ?
I want to convert a camel case to snake case using acceleo

Thanks in advance.

Previous Topic:Call service wrapper function in the post() black
Next Topic:[Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType
Goto Forum:
  


Current Time: Sun May 19 14:20:07 GMT 2024

Powered by FUDForum. Page generated in 0.02952 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top