This commit is contained in:
Patrik Svensson 2021-04-05 22:18:32 +02:00
Родитель a57f43b716
Коммит 156c3b48e1
27 изменённых файлов: 147 добавлений и 98 удалений

2
.github/workflows/ci.yaml поставляемый
Просмотреть файл

@ -40,7 +40,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: 5.0.100
- name: Build
shell: bash

4
.github/workflows/publish.yaml поставляемый
Просмотреть файл

@ -48,7 +48,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: 5.0.100
- name: Build
shell: bash
@ -78,7 +78,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: 5.0.100
- name: Publish
shell: bash

Просмотреть файл

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2020 Spectre Systems AB
Copyright Patrik Svensson. Phil Scott
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

Просмотреть файл

@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "0.38.4",
"version": "1.1.0",
"commands": [
"dotnet-cake"
]

Просмотреть файл

@ -1,7 +1,6 @@
{
"projects": [ "src" ],
"sdk": {
"version": "3.1.301",
"rollForward": "latestMajor"
"version": "5.0.100",
"rollForward": "latestPatch"
}
}

4
scripts/.gitignore поставляемый
Просмотреть файл

@ -1,2 +1,2 @@
Output
Data
.output
.data

Просмотреть файл

@ -2,8 +2,8 @@
# Script that generates known colors and lookup tables.
##########################################################
$Output = Join-Path $PSScriptRoot "Output"
$Data = Join-Path $PSScriptRoot "Data"
$Output = Join-Path $PSScriptRoot ".output"
$Data = Join-Path $PSScriptRoot ".data"
$Source = Join-Path $PSScriptRoot "/../src/Wcwidth/Tables"
if(!(Test-Path $Output -PathType Container)) {
@ -14,7 +14,7 @@ if(!(Test-Path $Data -PathType Container)) {
}
# Generate the files
Push-Location Generator
Push-Location (Join-Path $PSScriptRoot "../src/Wcwidth.Generator")
&dotnet run -- tables "$Output" --input "$Data"
if(!$?) {
Pop-Location

Просмотреть файл

@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Spectre.Cli" Version="0.43.0" />
<PackageReference Include="Scriban" Version="2.1.3" />
<PackageReference Include="Spectre.IO" Version="0.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Wcwidth\Wcwidth.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Templates\Table.template">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Просмотреть файл

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Generator", "Generator.csproj", "{64A7A6EB-C4EA-4537-A181-B0C11CF21CE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{64A7A6EB-C4EA-4537-A181-B0C11CF21CE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64A7A6EB-C4EA-4537-A181-B0C11CF21CE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64A7A6EB-C4EA-4537-A181-B0C11CF21CE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64A7A6EB-C4EA-4537-A181-B0C11CF21CE4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {37F50EC9-9829-4283-B046-E72EA93276CC}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -1,7 +1,7 @@
<Project>
<PropertyGroup Label="Settings">
<Deterministic>true</Deterministic>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
@ -14,12 +14,12 @@
<PropertyGroup Label="Package Information">
<Description>A .NET library that calculates the width of Unicode characters.</Description>
<Authors>Patrik Svensson</Authors>
<Authors>Patrik Svensson, Phil Scott</Authors>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/patriksvensson/wcwidth</RepositoryUrl>
<PackageProjectUrl>https://github.com/patriksvensson/wcwidth</PackageProjectUrl>
<RepositoryUrl>https://github.com/spectreconsole/wcwidth</RepositoryUrl>
<PackageProjectUrl>https://github.com/spectreconsole/wcwidth</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>https://github.com/patriksvensson/wcwidth/releases</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/spectreconsole/wcwidth/releases</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup Label="Source Link">
@ -29,16 +29,16 @@
</PropertyGroup>
<ItemGroup Label="Package References">
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.3.0" />
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.5.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.113">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.333">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="2.3.0">
<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>

Просмотреть файл

@ -0,0 +1,18 @@
root = false
[*.cs]
# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = none
# SA1600: Elements should be documented
dotnet_diagnostic.SA1600.severity = none
# CA1305: Specify IFormatProvider
dotnet_diagnostic.CA1305.severity = none
# CA1055: URI-like return values should not be strings
dotnet_diagnostic.CA1055.severity = none
# Default severity for all analyzer diagnostics
dotnet_analyzer_diagnostic.severity = none

Просмотреть файл

@ -5,7 +5,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Spectre.Cli;
using Spectre.Console.Cli;
using Spectre.Console;
using Spectre.IO;
using Wcwidth;
@ -30,6 +30,11 @@ namespace Generator
public override async Task<int> ExecuteAsync(CommandContext context, TableGeneratorSettings settings)
{
if (settings is null)
{
throw new ArgumentNullException(nameof(settings));
}
// Get the output path
var output = new DirectoryPath(settings.Output);
if (!_fileSystem.Directory.Exists(settings.Output))
@ -43,24 +48,24 @@ namespace Generator
: output;
// Get all versions
var versions = GetVersions();
var versions = GetUnicodeVersions();
foreach (var generator in _generators)
{
// Generate the source
AnsiConsole.MarkupLine("⏳ Generating [yellow]{0}[/]...", generator.ClassName);
AnsiConsole.MarkupLine($"⏳ Generating [yellow]{generator.ClassName}[/]...");
var result = await generator.Build(data, versions);
// Write the generated source to disk
var file = output.CombineWithFilePath($"{generator.ClassName}.Generated.cs");
AnsiConsole.MarkupLine("💾 Saving [yellow]{0}[/]...", file.GetFilename().FullPath);
AnsiConsole.MarkupLine($"💾 Saving [yellow]{file.GetFilename().FullPath}[/]...");
File.WriteAllText(file.FullPath, result);
}
return 0;
}
private List<string> GetVersions()
private static List<string> GetUnicodeVersions()
{
var result = new List<string>();
foreach (var field in typeof(Unicode).GetFields().Where(x => x.IsStatic))

Просмотреть файл

@ -1,5 +1,5 @@
using System.ComponentModel;
using Spectre.Cli;
using Spectre.Console.Cli;
namespace Generator
{

Просмотреть файл

@ -5,6 +5,6 @@ namespace Generator
public sealed class UnicodeData
{
public string Version { get; set; }
public List<(int start, int end)> Ranges { get; set; }
public List<(int Start, int End)> Ranges { get; set; }
}
}

Просмотреть файл

@ -28,6 +28,11 @@ namespace Generator
throw new ArgumentNullException(nameof(stream));
}
if (predicate is null)
{
throw new ArgumentNullException(nameof(predicate));
}
var result = new List<int>();
using var reader = new StreamReader(stream);
@ -43,6 +48,7 @@ namespace Generator
{
continue;
}
if (string.IsNullOrWhiteSpace(line))
{
continue;
@ -76,7 +82,7 @@ namespace Generator
return null;
}
private static (int, int) GetStartAndEnd(Match match)
private static (int Start, int End) GetStartAndEnd(Match match)
{
var start = match.GetGroupValue("start")?.Trim();
if (start == null)
@ -100,7 +106,7 @@ namespace Generator
return new UnicodeData
{
Version = version,
Ranges = ranges.OrderBy(x => x.Start).ToList()
Ranges = ranges.OrderBy(x => x.Start).ToList(),
};
}

Просмотреть файл

@ -20,6 +20,16 @@ namespace Generator
public async Task<string> Build(DirectoryPath path, IEnumerable<string> versions)
{
if (path is null)
{
throw new ArgumentNullException(nameof(path));
}
if (versions is null)
{
throw new ArgumentNullException(nameof(versions));
}
// Compile the template
var template = ScribanTemplate.Parse(File.ReadAllText(Template));
@ -33,14 +43,14 @@ namespace Generator
context.PushGlobal(new ScriptObject
{
["data"] = data,
["name"] = ClassName
["name"] = ClassName,
});
// Render template
return template.Render(context);
}
protected abstract string GetUrl(string version);
protected abstract Uri GetUrl(string version);
protected abstract bool Filter(string category);
private async Task<IEnumerable<UnicodeData>> GetAllData(
@ -51,8 +61,10 @@ namespace Generator
var result = new List<UnicodeData>();
foreach (var version in versions)
{
using var stream = await GetDataStream(data, version);
result.Add(UnicodeDataParser.Parse(version, stream, predicate));
using (var stream = await GetDataStream(data, version))
{
result.Add(UnicodeDataParser.Parse(version, stream, predicate));
}
}
return result;

Просмотреть файл

@ -7,9 +7,9 @@ namespace Generator
public override string ClassName => "WideTable";
protected override string DataFilename => "EastAsianWidth";
protected override string GetUrl(string version)
protected override Uri GetUrl(string version)
{
return $"http://www.unicode.org/Public/{version}/ucd/EastAsianWidth.txt";
return new Uri($"http://www.unicode.org/Public/{version}/ucd/EastAsianWidth.txt");
}
protected override bool Filter(string category)

Просмотреть файл

@ -7,9 +7,9 @@ namespace Generator
public override string ClassName => "ZeroTable";
protected override string DataFilename => "DerivedGeneralCategory";
protected override string GetUrl(string version)
protected override Uri GetUrl(string version)
{
return $"http://www.unicode.org/Public/{version}/ucd/extracted/DerivedGeneralCategory.txt";
return new Uri($"http://www.unicode.org/Public/{version}/ucd/extracted/DerivedGeneralCategory.txt");
}
protected override bool Filter(string category)

Просмотреть файл

@ -1,4 +1,4 @@
using Spectre.Cli;
using Spectre.Console.Cli;
namespace Generator
{

Просмотреть файл

@ -8,6 +8,11 @@ namespace Generator
{
public static string GetGroupValue(this Match match, string group, string defaultValue = null)
{
if (match is null)
{
throw new ArgumentNullException(nameof(match));
}
return match.Groups[group].Success
? match.Groups[group].Value
: defaultValue;
@ -23,7 +28,6 @@ namespace Generator
return Enumerate(source.GetEnumerator());
}
public static IEnumerable<(int Index, T Item)> Enumerate<T>(this IEnumerator<T> source)
{
if (source is null)

Просмотреть файл

@ -1,3 +1,4 @@
using System;
using Scriban.Runtime;
namespace Generator
@ -16,7 +17,12 @@ namespace Generator
public static string StringVer(string version)
{
return version.Replace(".", "_");
if (version is null)
{
return string.Empty;
}
return version.Replace(".", "_", StringComparison.Ordinal);
}
public static string HexPad(int value, int pad)

Просмотреть файл

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Scriban" Version="3.6.0" />
<PackageReference Include="Spectre.Console" Version="0.38.1-preview.0.24" />
<PackageReference Include="Spectre.IO" Version="0.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wcwidth\Wcwidth.csproj" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
</ItemGroup>
<ItemGroup>
<None Update="Templates\Table.template">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
@ -10,11 +10,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\README.md = ..\README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wcwidth.Generator", "Wcwidth.Generator\Wcwidth.Generator.csproj", "{765045E2-05BC-4236-BA3D-D63A6F1AAB86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -49,6 +51,18 @@ Global
{A90C8C46-58DF-41B8-B273-B24396E8424C}.Release|x64.Build.0 = Release|Any CPU
{A90C8C46-58DF-41B8-B273-B24396E8424C}.Release|x86.ActiveCfg = Release|Any CPU
{A90C8C46-58DF-41B8-B273-B24396E8424C}.Release|x86.Build.0 = Release|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Debug|x64.ActiveCfg = Debug|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Debug|x64.Build.0 = Debug|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Debug|x86.ActiveCfg = Debug|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Debug|x86.Build.0 = Debug|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Release|Any CPU.Build.0 = Release|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Release|x64.ActiveCfg = Release|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Release|x64.Build.0 = Release|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Release|x86.ActiveCfg = Release|Any CPU
{765045E2-05BC-4236-BA3D-D63A6F1AAB86}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>