Extensions Wiki » Extensions » Camel Case

Camel Case

Last modified by Sergiu Dumitriu on 2013/05/29 18:08
cogSplits CamelCaseWords to separate words (Camel Case Words)
TypeSnippet
Developed by

Melv Ng

LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Code

{{velocity}}
## Assign text in Velocity script
#set ($text = 'This is MyText. Also with a LongCamelCaseWord. This is notACamelCase, though.')

## View old, before value
Old: $text

## Add space using regexp
#foreach ($i in [0..1000])
  #set ($foreach.text = $text.replaceAll('\b(\p{Upper})(\S*?\p{Lower})(\p{Upper})', '$1$2 $3'))
  #if ($foreach.text == $text)
    #break($foreach)
  #end
  #set ($text = $foreach.text)
#end

## View new value
New: $text
{{/velocity}}

Result

Old: This is MyText. Also with a LongCamelCaseWord. This is notACamelCase, though.

New: This is My Text. Also with a Long Camel Case Word. This is notACamelCase, though.

Tags: groovy
Created by melv on 2007/01/29 15:12

Download XWiki