Skip to content

Commit 7da49cc

Browse files
committed
Add project files.
1 parent 9c71ffd commit 7da49cc

File tree

7 files changed

+758
-0
lines changed

7 files changed

+758
-0
lines changed

Unidecode.NET.sln

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{604AAA61-6C9C-4421-9DA5-0805968113A8}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C9018F64-4917-4F4F-8F78-3A674896029D}"
9+
ProjectSection(SolutionItems) = preProject
10+
global.json = global.json
11+
EndProjectSection
12+
EndProject
13+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Unidecode.NET", "src\Unidecode.NET\Unidecode.NET.xproj", "{A1A9B022-442C-4782-AF37-F8E58E5740A3}"
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{A1A9B022-442C-4782-AF37-F8E58E5740A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{A1A9B022-442C-4782-AF37-F8E58E5740A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{A1A9B022-442C-4782-AF37-F8E58E5740A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{A1A9B022-442C-4782-AF37-F8E58E5740A3}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(SolutionProperties) = preSolution
27+
HideSolutionNode = FALSE
28+
EndGlobalSection
29+
GlobalSection(NestedProjects) = preSolution
30+
{A1A9B022-442C-4782-AF37-F8E58E5740A3} = {604AAA61-6C9C-4421-9DA5-0805968113A8}
31+
EndGlobalSection
32+
EndGlobal

global.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [ "src", "test" ],
3+
"sdk": {
4+
"version": "1.0.0-preview2-003121"
5+
}
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyConfiguration("")]
9+
[assembly: AssemblyCompany("")]
10+
[assembly: AssemblyProduct("Unidecode.NET")]
11+
[assembly: AssemblyTrademark("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("a1a9b022-442c-4782-af37-f8e58e5740a3")]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>a1a9b022-442c-4782-af37-f8e58e5740a3</ProjectGuid>
11+
<RootNamespace>Unidecode.NET</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>

src/Unidecode.NET/Unidecoder.Characters.cs

Lines changed: 573 additions & 0 deletions
Large diffs are not rendered by default.

src/Unidecode.NET/Unidecoder.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Linq;
2+
using System.Text;
3+
4+
namespace Unidecode.NET
5+
{
6+
/// <summary>
7+
/// ASCII transliterations of Unicode text
8+
/// </summary>
9+
public static partial class Unidecoder
10+
{
11+
/// <summary>
12+
/// Transliterate Unicode string to ASCII string.
13+
/// </summary>
14+
/// <param name="input">String you want to transliterate into ASCII</param>
15+
/// <param name="tempStringBuilderCapacity">
16+
/// If you know the length of the result,
17+
/// pass the value for StringBuilder capacity.
18+
/// InputString.Length*2 is used by default.
19+
/// </param>
20+
/// <returns>
21+
/// ASCII string. There are [?] (3 characters) in places of some unknown(?) unicode characters.
22+
/// It is this way in Python code as well.
23+
/// </returns>
24+
public static string Unidecode(this string input, int? tempStringBuilderCapacity = null)
25+
{
26+
if (string.IsNullOrEmpty(input))
27+
{
28+
return "";
29+
}
30+
31+
if (input.All(x => x < 0x80))
32+
{
33+
return input;
34+
}
35+
36+
37+
// Unidecode result often can be at least two times longer than input string.
38+
var sb = new StringBuilder(tempStringBuilderCapacity ?? input.Length * 2);
39+
foreach (char c in input)
40+
{
41+
// Copypaste is bad, but sb.Append(c.Unidecode()); would be a bit slower.
42+
if (c < 0x80)
43+
{
44+
sb.Append(c);
45+
}
46+
else
47+
{
48+
int high = c >> 8;
49+
int low = c & 0xff;
50+
string[] transliterations;
51+
if (characters.TryGetValue(high, out transliterations))
52+
{
53+
sb.Append(transliterations[low]);
54+
}
55+
}
56+
}
57+
58+
return sb.ToString();
59+
}
60+
61+
/// <summary>
62+
/// Transliterate Unicode character to ASCII string.
63+
/// </summary>
64+
/// <param name="c">Character you want to transliterate into ASCII</param>
65+
/// <returns>
66+
/// ASCII string. Unknown(?) unicode characters will return [?] (3 characters).
67+
/// It is this way in Python code as well.
68+
/// </returns>
69+
public static string Unidecode(this char c)
70+
{
71+
string result;
72+
if (c < 0x80)
73+
{
74+
result = new string(c, 1);
75+
}
76+
else
77+
{
78+
int high = c >> 8;
79+
int low = c & 0xff;
80+
string[] transliterations;
81+
if (characters.TryGetValue(high, out transliterations))
82+
{
83+
result = transliterations[low];
84+
}
85+
else
86+
{
87+
result = "";
88+
}
89+
}
90+
91+
return result;
92+
}
93+
}
94+
}

src/Unidecode.NET/project.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "1.0.0-*",
3+
4+
"dependencies": {
5+
"NETStandard.Library": "1.6.0"
6+
},
7+
8+
"frameworks": {
9+
"netstandard1.6": {
10+
"imports": "dnxcore50"
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)