Skip to content

Commit 3917ca2

Browse files
committed
Fixed renaming when items of an enum only differ by case.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent fcb3b93 commit 3917ca2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Generator/Passes/RenamePass.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,12 @@ static string ConvertCaseString(Declaration decl, RenameCasePattern pattern)
364364

365365
for (int i = sb.Length - 1; i >= 0; i--)
366366
{
367-
// ensure separation by not ending up with more capitals or digits in a row than before
368-
if (sb[i] != '_' || (i > 0 && (char.IsUpper(sb[i - 1]) ||
369-
(i < sb.Length - 1 && char.IsDigit(sb[i + 1]) && char.IsDigit(sb[i - 1])))))
367+
if (sb[i] != '_' ||
368+
// lower case intentional if the first character is already upper case
369+
(i + 1 < sb.Length && char.IsLower(sb[i + 1]) && char.IsUpper(sb[0])) ||
370+
// don't end up with more capitals or digits in a row than before
371+
(i > 0 && (char.IsUpper(sb[i - 1]) ||
372+
(i < sb.Length - 1 && char.IsDigit(sb[i + 1]) && char.IsDigit(sb[i - 1])))))
370373
continue;
371374

372375
if (i < sb.Length - 1)

tests/Common/Common.Tests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public void TestCodeGeneration()
4444
e = EnumWithUnderscores.CAPITALS_More;
4545
e = EnumWithUnderscores.UsesDigits1_0;
4646
e.GetHashCode();
47+
ItemsDifferByCase itemsDifferByCase = ItemsDifferByCase.Case_a;
48+
itemsDifferByCase = ItemsDifferByCase.CaseA;
49+
itemsDifferByCase.GetHashCode();
4750
Common.SMallFollowedByCapital();
4851
using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) { }
4952

tests/Common/Common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,3 +1427,9 @@ namespace hasUnnamedDecl
14271427
{
14281428
}
14291429
}
1430+
1431+
enum ItemsDifferByCase
1432+
{
1433+
Case_a,
1434+
Case_A
1435+
};

0 commit comments

Comments
 (0)