diff --git a/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests2.cs b/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests2.cs new file mode 100644 index 00000000..b138f018 --- /dev/null +++ b/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests2.cs @@ -0,0 +1,31 @@ +// +// ISymbolTransformationTests2.cs +// +// Copyright (c) 2018 Firwood Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using static AdvancedDLSupport.SymbolTransformationMethod; + +#pragma warning disable SA1600, CS1591 + +namespace AdvancedDLSupport.Tests.Data +{ + [NativeSymbols(Prefix = "abCeD_cDEfDdaDfjc_zDDdDdf_", SymbolTransformationMethod = Pascalize)] + public interface ISymbolTransformationTests2 + { + int TestCode(int a, int b); + } +} diff --git a/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests3.cs b/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests3.cs new file mode 100644 index 00000000..2a8082a4 --- /dev/null +++ b/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests3.cs @@ -0,0 +1,31 @@ +// +// ISymbolTransformationTests3.cs +// +// Copyright (c) 2018 Firwood Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using static AdvancedDLSupport.SymbolTransformationMethod; + +#pragma warning disable SA1600, CS1591 + +namespace AdvancedDLSupport.Tests.Data +{ + [NativeSymbols(Prefix = "abCeD_cDEfDdaDfjc_zDDdDdf_", SymbolTransformationMethod = Camelize)] + public interface ISymbolTransformationTests3 + { + int TestCode(int a, int b); + } +} diff --git a/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests4.cs b/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests4.cs new file mode 100644 index 00000000..2c2efbd9 --- /dev/null +++ b/AdvancedDLSupport.Tests/Data/Interfaces/ISymbolTransformationTests4.cs @@ -0,0 +1,31 @@ +// +// ISymbolTransformationTests4.cs +// +// Copyright (c) 2018 Firwood Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using static AdvancedDLSupport.SymbolTransformationMethod; + +#pragma warning disable SA1600, CS1591 + +namespace AdvancedDLSupport.Tests.Data +{ + [NativeSymbols(Prefix = "abCeD_CDEfDdaDfjc_ZDDdDdf", SymbolTransformationMethod = Underscore)] + public interface ISymbolTransformationTests4 + { + int TestCode(int a, int b); + } +} diff --git a/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests2.cs b/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests2.cs new file mode 100644 index 00000000..18eded9b --- /dev/null +++ b/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests2.cs @@ -0,0 +1,46 @@ +// +// SymbolTransformationTests2.cs +// +// Copyright (c) 2018 Firwood Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using AdvancedDLSupport.Tests.Data; +using AdvancedDLSupport.Tests.TestBases; +using Xunit; + +#pragma warning disable SA1600, CS1591 + +namespace AdvancedDLSupport.Tests.Integration +{ + public class SymbolTransformationTests2 : LibraryTestBase + { + private const string LibraryName = "SymbolTransformationTests2"; + + public SymbolTransformationTests2() + : base(LibraryName) + { + } + + [Fact] + public void CanPascalizeString() + { + var expected = 5 * 5; + var actual = Library.TestCode(5, 5); + + Assert.Equal(expected, actual); + } + } +} diff --git a/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests3.cs b/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests3.cs new file mode 100644 index 00000000..88e334df --- /dev/null +++ b/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests3.cs @@ -0,0 +1,46 @@ +// +// SymbolTransformationTests3.cs +// +// Copyright (c) 2018 Firwood Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using AdvancedDLSupport.Tests.Data; +using AdvancedDLSupport.Tests.TestBases; +using Xunit; + +#pragma warning disable SA1600, CS1591 + +namespace AdvancedDLSupport.Tests.Integration +{ + public class SymbolTransformationTests3 : LibraryTestBase + { + private const string LibraryName = "SymbolTransformationTests3"; + + public SymbolTransformationTests3() + : base(LibraryName) + { + } + + [Fact] + public void CanCamelizeString() + { + var expected = 5 * 5; + var actual = Library.TestCode(5, 5); + + Assert.Equal(expected, actual); + } + } +} diff --git a/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests4.cs b/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests4.cs new file mode 100644 index 00000000..f7239a0d --- /dev/null +++ b/AdvancedDLSupport.Tests/Tests/Integration/SymbolTransformationTests4.cs @@ -0,0 +1,46 @@ +// +// SymbolTransformationTests4.cs +// +// Copyright (c) 2018 Firwood Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +using AdvancedDLSupport.Tests.Data; +using AdvancedDLSupport.Tests.TestBases; +using Xunit; + +#pragma warning disable SA1600, CS1591 + +namespace AdvancedDLSupport.Tests.Integration +{ + public class SymbolTransformationTests4 : LibraryTestBase + { + private const string LibraryName = "SymbolTransformationTests4"; + + public SymbolTransformationTests4() + : base(LibraryName) + { + } + + [Fact] + public void CanUnderscoreString() + { + var expected = 5 * 5; + var actual = Library.TestCode(5, 5); + + Assert.Equal(expected, actual); + } + } +} diff --git a/AdvancedDLSupport.Tests/c/CMakeLists.txt b/AdvancedDLSupport.Tests/c/CMakeLists.txt index 78346d6c..60d95e35 100644 --- a/AdvancedDLSupport.Tests/c/CMakeLists.txt +++ b/AdvancedDLSupport.Tests/c/CMakeLists.txt @@ -39,6 +39,9 @@ list( IndirectCallTests NameManglingTests SymbolTransformationTests + SymbolTransformationTests2 + SymbolTransformationTests3 + SymbolTransformationTests4 GenericDelegateTests BooleanMarshallingTests SpanMarshallingTests diff --git a/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests2.c b/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests2.c new file mode 100644 index 00000000..73b24383 --- /dev/null +++ b/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests2.c @@ -0,0 +1,7 @@ +#include +#include "comp.h" + +__declspec(dllexport) int32_t AbCeD_CDEfDdaDfjc_ZDDdDdf_TestCode(int32_t a, int32_t b) +{ + return a * b; +} diff --git a/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests3.c b/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests3.c new file mode 100644 index 00000000..bdcec307 --- /dev/null +++ b/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests3.c @@ -0,0 +1,7 @@ +#include +#include "comp.h" + +__declspec(dllexport) int32_t abCeD_CDEfDdaDfjc_ZDDdDdf_TestCode(int32_t a, int32_t b) +{ + return a * b; +} diff --git a/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests4.c b/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests4.c new file mode 100644 index 00000000..0acfb960 --- /dev/null +++ b/AdvancedDLSupport.Tests/c/src/SymbolTransformationTests4.c @@ -0,0 +1,7 @@ +#include +#include "comp.h" + +__declspec(dllexport) int32_t ab_ce_d_cd_ef_dda_dfjc_zd_dd_ddf_test_code(int32_t a, int32_t b) +{ + return a * b; +} diff --git a/AdvancedDLSupport/AdvancedDLSupport.csproj b/AdvancedDLSupport/AdvancedDLSupport.csproj index a38356ad..cdf03612 100644 --- a/AdvancedDLSupport/AdvancedDLSupport.csproj +++ b/AdvancedDLSupport/AdvancedDLSupport.csproj @@ -36,7 +36,6 @@ - diff --git a/AdvancedDLSupport/SymbolTransformation/SymbolTransformer.cs b/AdvancedDLSupport/SymbolTransformation/SymbolTransformer.cs index 6cbace31..0eb1b203 100644 --- a/AdvancedDLSupport/SymbolTransformation/SymbolTransformer.cs +++ b/AdvancedDLSupport/SymbolTransformation/SymbolTransformer.cs @@ -1,4 +1,4 @@ -// +// // SymbolTransformer.cs // // Copyright (c) 2018 Firwood Software @@ -20,8 +20,8 @@ using System; using System.Linq; using System.Reflection; +using System.Text; using AdvancedDLSupport.Reflection; -using Humanizer; using JetBrains.Annotations; using static AdvancedDLSupport.SymbolTransformationMethod; @@ -121,23 +121,70 @@ private string Transform } case Pascalize: { - return concatenated.Pascalize(); + var pascalized = new StringBuilder(concatenated); + for (var i = 1; i < pascalized.Length; ++i) + { + var previousCharacter = pascalized[i - 1]; + if (previousCharacter == '_' || + previousCharacter == ' ') + { + pascalized[i] = char.ToUpper(pascalized[i]); + } + } + + pascalized[0] = char.ToUpper(pascalized[0]); + return pascalized.ToString(); } case Camelize: { - return concatenated.Camelize(); + var camelized = new StringBuilder(concatenated); + for (var i = 1; i < camelized.Length; ++i) + { + var previousCharacter = camelized[i - 1]; + if (previousCharacter == '_' || + previousCharacter == ' ') + { + camelized[i] = char.ToUpper(camelized[i]); + } + } + + camelized[0] = char.ToLower(camelized[0]); + return camelized.ToString(); } case Underscore: { - return concatenated.Underscore(); - } - case Dasherize: - { - return concatenated.Dasherize(); + var underscore = new StringBuilder(concatenated); + for (var i = 1; i < underscore.Length; ++i) + { + var previousCharacter = underscore[i - 1]; + char? nextCharacter = null; + if (underscore.Length > i + 1) + { + nextCharacter = underscore[i + 1]; + } + + // ReSharper disable once SA1028 + if (nextCharacter.HasValue && + char.IsUpper(previousCharacter) && + char.IsUpper(underscore[i]) && + char.IsLower(nextCharacter.Value)) + { + underscore.Insert(i, "_"); + } + else if (char.IsLower(previousCharacter) && char.IsUpper(underscore[i])) + { + underscore.Insert(i, "_"); + } + } + + underscore.Replace("-", "_"); + + return underscore.ToString().ToLower(); } case Kebaberize: + case Dasherize: { - return concatenated.Kebaberize(); + return concatenated.Replace("_", "-"); } default: {