Skip to content

Commit

Permalink
Merge pull request #1133 from kenjiuno/fix-ctd-editor-1
Browse files Browse the repository at this point in the history
Fix text encoder/decoder of CtdEditor.
  • Loading branch information
shananas authored Dec 30, 2024
2 parents 9ffcf48 + 8d4e42c commit 8f87027
Show file tree
Hide file tree
Showing 26 changed files with 1,015 additions and 431 deletions.
4 changes: 2 additions & 2 deletions OpenKh.Bbs/Ctd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public class Message

public string Text
{
get => CtdEncoders.International.ToText(Data);
set => Data = CtdEncoders.International.FromText(value);
get => CtdEncoders.Unified.ToText(Data);
set => Data = CtdEncoders.Unified.FromText(value);
}

public override string ToString() =>
Expand Down
12 changes: 6 additions & 6 deletions OpenKh.Bbs/Messages/CtdEncoders.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using OpenKh.Bbs.Messages.Internals;
using OpenKh.Bbs.Messages.Internals;

namespace OpenKh.Bbs.Messages
{
public static class CtdEncoders
{
public static ICtdMessageEncoder International { get; } =
new InternationalCtdEncoder();

public static ICtdMessageEncoder Japanese { get; } =
new InternationalCtdEncoder();
/// <summary>
/// The unified CTD message encoder and decoder fit for both International and Japanese usage.
/// </summary>
public static ICtdMessageEncoder Unified { get; } =
new UnifiedCtdEncoder();
}
}
14 changes: 14 additions & 0 deletions OpenKh.Bbs/Messages/CtdFromTextOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace OpenKh.Bbs.Messages
{
public class CtdFromTextOptions
{
/// <summary>
/// Encode input as Shift_JIS encoding.
/// </summary>
public bool EncodeAsShiftJIS { get; set; }
}
}
19 changes: 19 additions & 0 deletions OpenKh.Bbs/Messages/CtdToTextOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace OpenKh.Bbs.Messages
{
public class CtdToTextOptions
{
/// <summary>
/// Allow to decode unknown as `{:unk FF}` alternative instead of throwing an exception.
/// </summary>
public bool AllowUnkUsage { get; set; } = true;

/// <summary>
/// Decode input as Shift_JIS encoding.
/// </summary>
public bool DecodeAsShiftJIS { get; set; }
}
}
4 changes: 2 additions & 2 deletions OpenKh.Bbs/Messages/ICtdMessageDecode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace OpenKh.Bbs.Messages
namespace OpenKh.Bbs.Messages
{
public interface ICtdMessageDecode
{
string ToText(byte[] data);
string ToText(byte[] data, CtdToTextOptions opts = null);
}
}
4 changes: 2 additions & 2 deletions OpenKh.Bbs/Messages/ICtdMessageEncode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace OpenKh.Bbs.Messages
namespace OpenKh.Bbs.Messages
{
public interface ICtdMessageEncode
{
byte[] FromText(string text);
byte[] FromText(string text, CtdFromTextOptions opts = null);
}
}
201 changes: 0 additions & 201 deletions OpenKh.Bbs/Messages/Internals/InternationalCtdEncoder.cs

This file was deleted.

Loading

0 comments on commit 8f87027

Please sign in to comment.