home contribute faq download

FunctX XQuery Functions

functx:camel-case-to-words

Turns a camelCase string into space-separated words

Google
Webxqueryfunctions.com

Description

The functx:camel-case-to-words function turns a camel-case string (one that uses upper-case letters to start new words, as in "thisIsACamelCaseTerm"), and turns them into a string of words using a space or other delimiter.

Arguments and Return Type

NameTypeDescription
$arg xs:string? the string to modify
$delim xs:string the delimiter for the words (e.g. a space)
return value xs:string

XQuery Function Declaration

See XSLT definition.
XQuery Syntax for July 2004 - January 2007 (1.0):
declare namespace functx = "http://www.functx.com"; 
declare function functx:camel-case-to-words 
  ( $arg as xs:string? ,
    $delim as xs:string )  as xs:string {
       
   concat(substring($arg,1,1),
             replace(substring($arg,2),'(\p{Lu})',
                        concat($delim, '$1')))
 } ;
XQuery Syntax for May 2003:
declare namespace functx = "http://www.functx.com" 
define function camel-case-to-words 
  ( $arg as xs:string? ,
    $delim as xs:string )  as xs:string {
       
   fn:concat(fn:substring($arg,1,1),
             fn:replace(fn:substring($arg,2),'(\p{Lu})',
                        fn:concat($delim, '$1')))
 }

Examples

XQuery ExampleResults
functx:camel-case-to-words(
     'thisIsACamelCaseTerm',' ')
this Is A Camel Case Term
functx:camel-case-to-words(
     'thisIsACamelCaseTerm',',')
this,Is,A,Camel,Case,Term

See Also

functx:words-to-camel-caseTurns a string of words into camelCase

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Need XQuery Help?
D A T Y P I C
Training | Consulting | Development

XQuery by Priscilla WalmsleyGet the book!
XQuery by Priscilla Walmsley