Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vs/*
**/bin/*
**/obj/*
packages/*
41 changes: 41 additions & 0 deletions Ude.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Ude</id>
<title>Ude</title>
<version>$version$</version>
<authors>Rudi Pettazzi</authors>
<owners>Rudi Pettazzi</owners>
<projectUrl>https://github.com/errepi/ude</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>Ude is a C# port of Mozilla Universal Charset Detector.</summary>
<description>Ude can recognize the following charsets:
- UTF-8
- UTF-16 (BE and LE)
- UTF-32 (BE and LE)
- windows-1252 (mostly equivalent to iso8859-1)
- windows-1251 and ISO-8859-5 (cyrillic)
- windows-1253 and ISO-8859-7 (greek)
- windows-1255 (logical hebrew. Includes ISO-8859-8-I and most of x-mac-hebrew)
- ISO-8859-8 (visual hebrew)
- Big-5
- gb18030 (superset of gb2312)
- HZ-GB-2312
- Shift-JIS
- EUC-KR, EUC-JP, EUC-TW
- ISO-2022-JP, ISO-2022-KR, ISO-2022-CN
- KOI8-R
- x-mac-cyrillic
- IBM855 and IBM866
- X-ISO-10646-UCS-4-3412 and X-ISO-10646-UCS-4-2413 (unusual BOM)
- ASCII</description>
<language>en-US</language>
<tags>charset encoding utf-8 utf ascii windows-1252 ISO-8859</tags>
</metadata>
<files>
<file src="src\Library\bin\$configuration$\Ude.dll" target="lib\net46" />
<file src="src\Library\bin\$configuration$\Ude.pdb" target="lib\net46" />
<file src="src\NetStandard\bin\$configuration$\Ude.NetStandard.dll" target="lib\netstandard1.0\Ude.NetStandard.dll" />
<file src="src\NetStandard\bin\$configuration$\Ude.NetStandard.pdb" target="lib\netstandard1.0\Ude.NetStandard.pdb" />
</files>
</package>
12 changes: 10 additions & 2 deletions Ude.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ude.Example", "src\Example\Ude.Example.csproj", "{F672E6C2-14CC-47B6-8451-4D8AEDE86130}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ude.Tests", "src\Tests\Ude.Tests.csproj", "{53C6763B-CA4B-4F14-9326-A43C29FF0B4E}"
Expand All @@ -10,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ude.Tests", "src\Tests\Ude.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ude", "src\Library\Ude.csproj", "{7BECB850-389A-44FC-8523-3EF0B2540F07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ude.NetStandard", "src\NetStandard\Ude.NetStandard.csproj", "{68156FEE-8FE1-45F5-8267-4D0098A029D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -28,6 +32,10 @@ Global
{7BECB850-389A-44FC-8523-3EF0B2540F07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BECB850-389A-44FC-8523-3EF0B2540F07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BECB850-389A-44FC-8523-3EF0B2540F07}.Release|Any CPU.Build.0 = Release|Any CPU
{68156FEE-8FE1-45F5-8267-4D0098A029D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68156FEE-8FE1-45F5-8267-4D0098A029D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68156FEE-8FE1-45F5-8267-4D0098A029D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68156FEE-8FE1-45F5-8267-4D0098A029D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
21 changes: 17 additions & 4 deletions src/Example/Ude.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{F672E6C2-14CC-47B6-8451-4D8AEDE86130}</ProjectGuid>
<RootNamespace>Ude.Example</RootNamespace>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputType>Exe</OutputType>
Expand All @@ -17,6 +25,7 @@
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<DefineConstants>DEBUG</DefineConstants>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputType>Exe</OutputType>
Expand All @@ -30,6 +39,7 @@
<DefineConstants>
</DefineConstants>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand All @@ -40,9 +50,12 @@
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<ProjectReference Include="..\Library\Ude.csproj">
<Project>{7BECB850-389A-44FC-8523-3EF0B2540F07}</Project>
<Name>Ude</Name>
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetStandard\Ude.NetStandard.csproj">
<Project>{68156fee-8fe1-45f5-8267-4d0098a029d0}</Project>
<Name>Ude.NetStandard</Name>
</ProjectReference>
</ItemGroup>
</Project>
43 changes: 28 additions & 15 deletions src/Example/Ude.Example/Udetect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,50 @@
//

using System;
using System.Diagnostics;
using System.IO;

using Ude;
namespace Ude.Example {

namespace Ude.Example
{
public class Udetect
{
public class Udetect {
/// <summary>
/// Command line example: detects the encoding of the given file.
/// Command line example: detects the encoding of the given file.
/// </summary>
/// <param name="args">a filename</param>
public static void Main(String[] args)
{
public static void Main(string[] args) {
if (args.Length == 0) {
Console.WriteLine("Usage: udetect <filename>");
return;
}
string filename = args[0];
using (FileStream fs = File.OpenRead(filename)) {

var filename = args[0];
using (var fs = File.OpenRead(filename)) {
ICharsetDetector cdet = new CharsetDetector();
cdet.Feed(fs);
cdet.DataEnd();

Console.WriteLine();
if (cdet.Charset != null) {
Console.WriteLine("Charset: {0}, confidence: {1}",
cdet.Charset, cdet.Confidence);
} else {
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Charset: {0}, confidence: {1}", cdet.Charset, cdet.Confidence);
}
else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Detection failed.");
}
Console.ResetColor();
}
}

Exit();
}

[Conditional("DEBUG")]
private static void Exit() {
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press [ENTER] to exit...");
Console.ReadLine();
}
}

}
3 changes: 3 additions & 0 deletions src/Example/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
Loading