Skip to content

Commit a6db95e

Browse files
Add preserveAcronyms support to objCEnumItemLabel. (#879)
1 parent 849eef1 commit a6db95e

File tree

2 files changed

+11
-4
lines changed
  • src-electron/generator/matter

2 files changed

+11
-4
lines changed

src-electron/generator/matter/app/zap-templates/templates/app/helper.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ function asCamelCase(label, firstLower, preserveAcronyms) {
395395

396396
let str = tokens
397397
.map((token, index) => {
398-
let isAcronym = token == token.toUpperCase();
398+
let isAllUpperCase = token == token.toUpperCase();
399+
// PERSONAL is not actually an acronym.
400+
let isAcronym = isAllUpperCase && token != "PERSONAL";
399401

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

411-
if (!isAcronym) {
413+
if (!isAllUpperCase) {
412414
if (token.length > 1) {
413415
newToken += token.substring(1);
414416
}
415417
return newToken;
416418
}
417419

418-
// if preserveAcronyms is false, then anything beyond the first letter becomes lower-case.
420+
// If this is an all-upper-case thing not being preserved as an acronym,
421+
// then anything beyond the first letter becomes lower-case.
419422
if (token.length > 1) {
420423
newToken += token.substring(1).toLowerCase();
421424
}

src-electron/generator/matter/darwin/Framework/CHIP/templates/helper.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ function objCEnumName(clusterName, enumLabel, options) {
318318
return 'MTR' + clusterName + enumLabel;
319319
}
320320

321-
function objCEnumItemLabel(itemLabel) {
321+
function objCEnumItemLabel(itemLabel, options) {
322+
if (options.hash.preserveAcronyms) {
323+
return appHelper.asUpperCamelCase.call(this, itemLabel, options);
324+
}
325+
322326
// Check for the case when we're:
323327
// 1. A single word (that's the regexp at the beginning, which matches the
324328
// word-splitting regexp in string.toCamelCase).

0 commit comments

Comments
 (0)