Browse Source

Changed the renaming not to lose separation in new names.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/787/merge
Dimitar Dobrev 8 years ago
parent
commit
ea9c12842a
  1. 23
      src/Generator/Passes/RenamePass.cs
  2. 5
      tests/Common/Common.Tests.cs
  3. 2
      tests/Common/Common.h

23
src/Generator/Passes/RenamePass.cs

@ -338,24 +338,25 @@ namespace CppSharp.Passes @@ -338,24 +338,25 @@ namespace CppSharp.Passes
if (sb[0] == '@')
sb.Remove(0, 1);
// do not remove underscores from ALL_CAPS names
if (!decl.Name.Where(char.IsLetter).All(char.IsUpper))
for (int i = sb.Length - 1; i >= 0; i--)
{
for (int i = sb.Length - 1; i >= 0; i--)
{
if (sb[i] == '_' && i < sb.Length - 1)
{
sb[i + 1] = char.ToUpperInvariant(sb[i + 1]);
sb.Remove(i, 1);
}
}
// 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])))))
continue;
if (i < sb.Length - 1)
sb[i + 1] = char.ToUpperInvariant(sb[i + 1]);
sb.Remove(i, 1);
}
var @class = decl as Class;
switch (pattern)
{
case RenameCasePattern.UpperCamelCase:
sb[0] = char.ToUpperInvariant(sb[0]);
// ensure separation by not ending up with more capitals in a row than before
if (sb.Length == 1 || !char.IsUpper(sb[1]))
sb[0] = char.ToUpperInvariant(sb[0]);
if (@class != null && @class.Type == ClassType.Interface)
sb[1] = char.ToUpperInvariant(sb[1]);
break;

5
tests/Common/Common.Tests.cs

@ -37,7 +37,10 @@ public class CommonTests : GeneratorTestFixture @@ -37,7 +37,10 @@ public class CommonTests : GeneratorTestFixture
using (var hasProtectedEnum = new HasProtectedEnum())
{
}
EnumWithUnderscores e = 0;
EnumWithUnderscores e = EnumWithUnderscores.lOWER_BEFORE_CAPITAL;
e = EnumWithUnderscores.UnderscoreAtEnd;
e = EnumWithUnderscores.CAPITALS_More;
e = EnumWithUnderscores.UsesDigits1_0;
e.GetHashCode();
#pragma warning restore 0168

2
tests/Common/Common.h

@ -1219,4 +1219,4 @@ DLL_API void hasPointerParam(const Foo& foo); @@ -1219,4 +1219,4 @@ DLL_API void hasPointerParam(const Foo& foo);
enum EmptyEnum { };
enum __enum_with_underscores { };
enum __enum_with_underscores { lOWER_BEFORE_CAPITAL, CAPITALS_More, underscore_at_end_, usesDigits1_0 };

Loading…
Cancel
Save