Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
#120 Fix SJIS tunnel GetByteCount() not matching GetBytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
www committed Feb 16, 2023
1 parent b146ed7 commit 8558ec6
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions VNTextPatch.Shared/Util/SjisTunnelEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SjisTunnelEncoding : Encoding
{
private static readonly Encoding SjisEncoding = GetEncoding(932, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);

private readonly char[] _charArray = new char[1];
private readonly byte[] _byteArray = new byte[2];
private readonly Dictionary<char, char> _mappings = new Dictionary<char, char>();

public SjisTunnelEncoding()
Expand All @@ -30,15 +30,10 @@ public override int GetByteCount(string str)

if (!tunneled)
{
try
{
_charArray[0] = str[i];
byteCount += SjisEncoding.GetByteCount(_charArray);
}
catch
{
if (TrySjisEncode(str, i, 1, _byteArray, 0, out int charByteCount))
byteCount += charByteCount;
else
tunneled = true;
}
}

if (tunneled)
Expand Down

0 comments on commit 8558ec6

Please sign in to comment.