Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of Humanizer Dependency #95

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

using AdvancedDLSupport.Tests.Data;
using AdvancedDLSupport.Tests.TestBases;
using Xunit;

#pragma warning disable SA1600, CS1591

namespace AdvancedDLSupport.Tests.Integration
{
public class SymbolTransformationTests2 : LibraryTestBase<ISymbolTransformationTests2>
{
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

using AdvancedDLSupport.Tests.Data;
using AdvancedDLSupport.Tests.TestBases;
using Xunit;

#pragma warning disable SA1600, CS1591

namespace AdvancedDLSupport.Tests.Integration
{
public class SymbolTransformationTests3 : LibraryTestBase<ISymbolTransformationTests3>
{
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

using AdvancedDLSupport.Tests.Data;
using AdvancedDLSupport.Tests.TestBases;
using Xunit;

#pragma warning disable SA1600, CS1591

namespace AdvancedDLSupport.Tests.Integration
{
public class SymbolTransformationTests4 : LibraryTestBase<ISymbolTransformationTests4>
{
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);
}
}
}
3 changes: 3 additions & 0 deletions AdvancedDLSupport.Tests/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ list(
IndirectCallTests
NameManglingTests
SymbolTransformationTests
SymbolTransformationTests2
SymbolTransformationTests3
SymbolTransformationTests4
GenericDelegateTests
BooleanMarshallingTests
SpanMarshallingTests
Expand Down
7 changes: 7 additions & 0 deletions AdvancedDLSupport.Tests/c/src/SymbolTransformationTests2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdlib.h>
#include "comp.h"

__declspec(dllexport) int32_t AbCeD_CDEfDdaDfjc_ZDDdDdf_TestCode(int32_t a, int32_t b)
{
return a * b;
}
7 changes: 7 additions & 0 deletions AdvancedDLSupport.Tests/c/src/SymbolTransformationTests3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdlib.h>
#include "comp.h"

__declspec(dllexport) int32_t abCeD_CDEfDdaDfjc_ZDDdDdf_TestCode(int32_t a, int32_t b)
{
return a * b;
}
7 changes: 7 additions & 0 deletions AdvancedDLSupport.Tests/c/src/SymbolTransformationTests4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdlib.h>
#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;
}
1 change: 0 additions & 1 deletion AdvancedDLSupport/AdvancedDLSupport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.5.16" PrivateAssets="Compile;Build;Analyzers;ContentFiles" />
<PackageReference Include="StrictEmit" Version="2.4.2" PrivateAssets="Compile;Build;Analyzers;ContentFiles" />
</ItemGroup>
<ItemGroup>
Expand Down
67 changes: 57 additions & 10 deletions AdvancedDLSupport/SymbolTransformation/SymbolTransformer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// SymbolTransformer.cs
//
// Copyright (c) 2018 Firwood Software
Expand All @@ -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;

Expand Down Expand Up @@ -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:
{
Expand Down