Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
b2faf8451a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
18 lines (18 sloc) 821 Bytes
function str = fromUpperToCamelCase(upperscore_compound)
% converts upperscore_compound to CamelCase
%
% Not always exactly invertible
%
% Examples:
% fromUpperToCamelCase('ONE') --> 'one'
% fromUpperToCamelCase('ONE_TWO_THREE') --> 'oneTwoThree'
% fromUpperToCamelCase('#$ONE_TWO_THREE') --> 'oneTwoThree'
% fromUpperToCamelCase('One_Two_Three') --> !error! lower case only mixes with alphanumerics
% fromUpperToCamelCase('5_TWO_THREE') --> !error! cannot start with a digit
assert(isempty(regexp(upperscore_compound, '\s', 'once')), ...
'white space is not allowed' )
assert(~ismember(upperscore_compound(1), '0':'9'), 'string cannot begin with a digit')
str = lower(upperscore_compound);
str = regexprep(str, '(^|[_\W]+)([a-zA-Z])', '${upper($2)}');
str = [lower(str(1)) str(2:end)];
end