Browse Source

Fixed renaming when items of an enum only differ by case.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1139/head 0.8.22
Dimitar Dobrev 7 years ago
parent
commit
3917ca2584
  1. 9
      src/Generator/Passes/RenamePass.cs
  2. 3
      tests/Common/Common.Tests.cs
  3. 6
      tests/Common/Common.h

9
src/Generator/Passes/RenamePass.cs

@ -364,9 +364,12 @@ namespace CppSharp.Passes @@ -364,9 +364,12 @@ namespace CppSharp.Passes
for (int i = sb.Length - 1; i >= 0; i--)
{
// ensure separation by not ending up with more capitals or digits in a row than before
if (sb[i] != '_' || (i > 0 && (char.IsUpper(sb[i - 1]) ||
(i < sb.Length - 1 && char.IsDigit(sb[i + 1]) && char.IsDigit(sb[i - 1])))))
if (sb[i] != '_' ||
// lower case intentional if the first character is already upper case
(i + 1 < sb.Length && char.IsLower(sb[i + 1]) && char.IsUpper(sb[0])) ||
// don't end up with more capitals or digits in a row than before
(i > 0 && (char.IsUpper(sb[i - 1]) ||
(i < sb.Length - 1 && char.IsDigit(sb[i + 1]) && char.IsDigit(sb[i - 1])))))
continue;
if (i < sb.Length - 1)

3
tests/Common/Common.Tests.cs

@ -44,6 +44,9 @@ public class CommonTests : GeneratorTestFixture @@ -44,6 +44,9 @@ public class CommonTests : GeneratorTestFixture
e = EnumWithUnderscores.CAPITALS_More;
e = EnumWithUnderscores.UsesDigits1_0;
e.GetHashCode();
ItemsDifferByCase itemsDifferByCase = ItemsDifferByCase.Case_a;
itemsDifferByCase = ItemsDifferByCase.CaseA;
itemsDifferByCase.GetHashCode();
Common.SMallFollowedByCapital();
using (new DerivedFromSecondaryBaseWithIgnoredVirtualMethod()) { }

6
tests/Common/Common.h

@ -1427,3 +1427,9 @@ namespace hasUnnamedDecl @@ -1427,3 +1427,9 @@ namespace hasUnnamedDecl
{
}
}
enum ItemsDifferByCase
{
Case_a,
Case_A
};

Loading…
Cancel
Save