I'm working on a Delphi mobile app and want to convert camelCase or PascalCase identifiers into space-separated, human-readable labels.
For example this is my array:
const
ReadableIdentifiers: array[0..8] of string = (
'LoadUserData',
'SaveToFile',
'CreateNewUserAccount',
'IsUserLoggedIn',
'GenerateReportPreview',
'HandleRequestError',
'FetchUserProfile',
'ParseDateString',
'ValidateInputField'
);
I want them to become:
Load User Data Save To File Create New User Account Is User Logged In Generate Report Preview Handle Request Error Fetch User Profile Parse Date String Validate Input Field
The goal is to add a space wherever a lowercase letter is immediately followed by an uppercase one as that is when a new word will begin in my array.
This is what I have done currently:
function ManualCamelCaseLabel(Input: string): string;
begin
if Input = 'LoadUserData' then
Result := 'Load User Data'
else if Input = 'SaveToFile' then
Result := 'Save To File'
else if Input = 'CreateNewUserAccount' then
Result := 'Create New User Account'
else if Input = 'IsUserLoggedIn' then
Result := 'Is User Logged In'
else if Input = 'GenerateReportPreview' then
Result := 'Generate Report Preview'
else if Input = 'HandleRequestError' then
Result := 'Handle Request Error'
else if Input = 'FetchUserProfile' then
Result := 'Fetch User Profile'
else if Input = 'ParseDateString' then
Result := 'Parse Date String'
else if Input = 'ValidateInputField' then
Result := 'Validate Input Field'
else
Result := Input;
end;
It works, but it's hardcoded and I need something better.