Skip to content

Commit

Permalink
Add preserveAcronyms support to objCEnumItemLabel. (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored Jan 5, 2023
1 parent 849eef1 commit a6db95e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ function asCamelCase(label, firstLower, preserveAcronyms) {

let str = tokens
.map((token, index) => {
let isAcronym = token == token.toUpperCase();
let isAllUpperCase = token == token.toUpperCase();
// PERSONAL is not actually an acronym.
let isAcronym = isAllUpperCase && token != "PERSONAL";

if (isAcronym && preserveAcronyms) {
return token;
Expand All @@ -408,14 +410,15 @@ function asCamelCase(label, firstLower, preserveAcronyms) {
? token[0].toLowerCase()
: token[0].toUpperCase();

if (!isAcronym) {
if (!isAllUpperCase) {
if (token.length > 1) {
newToken += token.substring(1);
}
return newToken;
}

// if preserveAcronyms is false, then anything beyond the first letter becomes lower-case.
// If this is an all-upper-case thing not being preserved as an acronym,
// then anything beyond the first letter becomes lower-case.
if (token.length > 1) {
newToken += token.substring(1).toLowerCase();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ function objCEnumName(clusterName, enumLabel, options) {
return 'MTR' + clusterName + enumLabel;
}

function objCEnumItemLabel(itemLabel) {
function objCEnumItemLabel(itemLabel, options) {
if (options.hash.preserveAcronyms) {
return appHelper.asUpperCamelCase.call(this, itemLabel, options);
}

// Check for the case when we're:
// 1. A single word (that's the regexp at the beginning, which matches the
// word-splitting regexp in string.toCamelCase).
Expand Down

0 comments on commit a6db95e

Please sign in to comment.