tidy
This commit is contained in:
+52
-54
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace Gma.QrCodeNet.Encoding.DataEncodation;
|
||||
|
||||
/// <summary>
|
||||
@@ -14,67 +12,67 @@ namespace Gma.QrCodeNet.Encoding.DataEncodation;
|
||||
/// <remarks>ISO/IEC 18004:2000 Chapter 8.4.4 Page 22</remarks>
|
||||
internal class EightBitByteEncoder : EncoderBase
|
||||
{
|
||||
private const string DefaultEncoding = QRCodeConstantVariable.DefaultEncoding;
|
||||
private const string DefaultEncoding = QRCodeConstantVariable.DefaultEncoding;
|
||||
|
||||
/// <summary>
|
||||
/// Bitcount, Chapter 8.4.4, P.24
|
||||
/// </summary>
|
||||
private const int EightBitByteBitcount = 8;
|
||||
/// <summary>
|
||||
/// Bitcount, Chapter 8.4.4, P.24
|
||||
/// </summary>
|
||||
private const int EightBitByteBitcount = 8;
|
||||
|
||||
/// <summary>
|
||||
/// EightBitByte encoder's encoding will change according to different region
|
||||
/// </summary>
|
||||
/// <param name="encoding">Default encoding is "iso-8859-1"</param>
|
||||
internal EightBitByteEncoder(string encoding) : base()
|
||||
{
|
||||
Encoding = encoding ?? DefaultEncoding;
|
||||
}
|
||||
/// <summary>
|
||||
/// EightBitByte encoder's encoding will change according to different region
|
||||
/// </summary>
|
||||
/// <param name="encoding">Default encoding is "iso-8859-1"</param>
|
||||
internal EightBitByteEncoder(string encoding) : base()
|
||||
{
|
||||
Encoding = encoding ?? DefaultEncoding;
|
||||
}
|
||||
|
||||
internal EightBitByteEncoder() : base()
|
||||
{
|
||||
Encoding = DefaultEncoding;
|
||||
}
|
||||
internal EightBitByteEncoder() : base()
|
||||
{
|
||||
Encoding = DefaultEncoding;
|
||||
}
|
||||
|
||||
internal string Encoding { get; private set; }
|
||||
internal string Encoding { get; private set; }
|
||||
|
||||
protected byte[] EncodeContent(string content, string encoding) => System.Text.Encoding.GetEncoding(encoding).GetBytes(content);
|
||||
protected byte[] EncodeContent(string content, string encoding) => System.Text.Encoding.GetEncoding(encoding).GetBytes(content);
|
||||
|
||||
internal override BitList GetDataBits(string content)
|
||||
{
|
||||
var eciSet = new ECISet(ECISet.AppendOption.NameToValue);
|
||||
if (!eciSet.ContainsECIName(Encoding))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(Encoding),
|
||||
$"Current ECI table does not support this encoding. Please check {nameof(ECISet)} class for more info.");
|
||||
}
|
||||
internal override BitList GetDataBits(string content)
|
||||
{
|
||||
var eciSet = new ECISet(ECISet.AppendOption.NameToValue);
|
||||
if (!eciSet.ContainsECIName(Encoding))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
nameof(Encoding),
|
||||
$"Current ECI table does not support this encoding. Please check {nameof(ECISet)} class for more info.");
|
||||
}
|
||||
|
||||
byte[] contentBytes = EncodeContent(content, Encoding);
|
||||
byte[] contentBytes = EncodeContent(content, Encoding);
|
||||
|
||||
return GetDataBitsByByteArray(contentBytes, Encoding);
|
||||
}
|
||||
return GetDataBitsByByteArray(contentBytes, Encoding);
|
||||
}
|
||||
|
||||
internal BitList GetDataBitsByByteArray(byte[] encodeContent, string encodingName)
|
||||
{
|
||||
var dataBits = new BitList();
|
||||
internal BitList GetDataBitsByByteArray(byte[] encodeContent, string encodingName)
|
||||
{
|
||||
var dataBits = new BitList();
|
||||
|
||||
// Current plan for UTF8 support is put Byte order Mark in front of content byte.
|
||||
// Also include ECI header before encoding header. Which will be add with encoding header.
|
||||
if (encodingName == "utf-8")
|
||||
{
|
||||
byte[] utf8BOM = QRCodeConstantVariable.UTF8ByteOrderMark;
|
||||
for (int index = 0; index < utf8BOM.Length; index++)
|
||||
{
|
||||
dataBits.Add(utf8BOM[index], EightBitByteBitcount);
|
||||
}
|
||||
}
|
||||
// Current plan for UTF8 support is put Byte order Mark in front of content byte.
|
||||
// Also include ECI header before encoding header. Which will be add with encoding header.
|
||||
if (encodingName == "utf-8")
|
||||
{
|
||||
byte[] utf8BOM = QRCodeConstantVariable.UTF8ByteOrderMark;
|
||||
for (int index = 0; index < utf8BOM.Length; index++)
|
||||
{
|
||||
dataBits.Add(utf8BOM[index], EightBitByteBitcount);
|
||||
}
|
||||
}
|
||||
|
||||
for (int index = 0; index < encodeContent.Length; index++)
|
||||
{
|
||||
dataBits.Add(encodeContent[index], EightBitByteBitcount);
|
||||
}
|
||||
return dataBits;
|
||||
}
|
||||
for (int index = 0; index < encodeContent.Length; index++)
|
||||
{
|
||||
dataBits.Add(encodeContent[index], EightBitByteBitcount);
|
||||
}
|
||||
return dataBits;
|
||||
}
|
||||
|
||||
protected override int GetBitCountInCharCountIndicator(int version) => CharCountIndicatorTable.GetBitCountInCharCountIndicator(version);
|
||||
}
|
||||
protected override int GetBitCountInCharCountIndicator(int version) => CharCountIndicatorTable.GetBitCountInCharCountIndicator(version);
|
||||
}
|
||||
Reference in New Issue
Block a user