This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
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?
ImageIO/utils/fromUpperToCamelCase.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
18 lines (18 sloc)
821 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |