Use Ascii Encoding For Translation (#144)

* bug fix

* delete unnecessary using

* mistyped string

* nonempty fallbackexception

* update

* fix
This commit is contained in:
Matthew Jin 2022-06-30 14:24:00 -07:00 коммит произвёл GitHub
Родитель 76ec796141
Коммит ffc520c1d7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 39 добавлений и 4 удалений

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

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Text;
namespace Cilsil
{
@ -100,7 +101,14 @@ namespace Cilsil
(var cfg, var tenv) = ExecuteTranslation(paths, extprogress);
File.WriteAllText(cfgtxt ?? "./cfg.txt", cfg.ToString());
var Utf8Encoder = Encoding.GetEncoding(
"us-ascii",
new EncoderReplacementFallback("_"),
new DecoderExceptionFallback()
);
File.WriteAllText(cfgtxt ?? "./cfg.txt", cfg.ToString(), Utf8Encoder);
cfg.WriteToFile(outcfg);
tenv.WriteToFile(outtenv);
@ -201,7 +209,7 @@ namespace Cilsil
return (filteredAssemblies, totalSize);
}
private static void PrintFiles(string[] files = null, string procs = null)
private static void PrintFiles(string[] files, string procs)
{
foreach (var file in files)
{

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

@ -9,6 +9,7 @@ using QuickGraph.Graphviz.Dot;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Cilsil.Sil
{
@ -109,8 +110,20 @@ namespace Cilsil.Sil
/// <param name="path">The file path.</param>
public void WriteToFile(string path)
{
var ascii = Encoding.GetEncoding(
"us-ascii",
new EncoderReplacementFallback("_"),
new DecoderReplacementFallback("|")
);
var serializer = JsonSerializer.Create(JsonSerializerSettings);
using (var streamWriter = new StreamWriter(path ?? "./cfg.json"))
var output = path ?? "./cfg.json";
if (File.Exists(output))
{
File.Delete(output);
}
using (var fs = File.Open(output, FileMode.CreateNew, FileAccess.Write))
using (var streamWriter = new StreamWriter(fs, ascii))
using (var writer = new JsonTextWriter(streamWriter))
{
serializer.Serialize(writer, this);

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

@ -7,6 +7,7 @@ using Newtonsoft.Json.Serialization;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Cilsil.Sil
{
@ -74,8 +75,21 @@ namespace Cilsil.Sil
/// <param name="path">The file path.</param>
public void WriteToFile(string path)
{
var ascii = Encoding.GetEncoding(
"us-ascii",
new EncoderReplacementFallback("_"),
new DecoderReplacementFallback("|")
);
var serializer = JsonSerializer.Create(JsonSerializerSettings);
using (var streamWriter = new StreamWriter(path ?? "./tenv.json"))
var output = path ?? "./tenv.json";
if (File.Exists(output))
{
File.Delete(output);
}
using (var fs = File.Open(output, FileMode.CreateNew, FileAccess.Write))
using (var streamWriter = new StreamWriter(fs, encoding: ascii))
using (var writer = new JsonTextWriter(streamWriter))
{
serializer.Serialize(writer, this);