This commit is contained in:
TheXamlGuy
2024-04-26 23:05:36 +01:00
parent 9f90ef693d
commit bc55c4649b
206 changed files with 3106 additions and 3204 deletions
@@ -1,57 +1,54 @@
using System;
using System.Collections.Generic;
namespace Gma.QrCodeNet.Encoding.DataEncodation.InputRecognition;
public static class InputRecognise
{
public static RecognitionStruct Recognise(string content)
{
string encodingName = EightBitByteRecognision(content, 0, content.Length);
return new RecognitionStruct(encodingName);
}
public static RecognitionStruct Recognise(string content)
{
string encodingName = EightBitByteRecognision(content, 0, content.Length);
return new RecognitionStruct(encodingName);
}
private static string EightBitByteRecognision(string content, int startPos, int contentLength)
{
if(string.IsNullOrEmpty(content))
private static string EightBitByteRecognision(string content, int startPos, int contentLength)
{
if (string.IsNullOrEmpty(content))
throw new ArgumentNullException(nameof(content));
var eciSets = new ECISet(ECISet.AppendOption.NameToValue);
var eciSets = new ECISet(ECISet.AppendOption.NameToValue);
Dictionary<string, int>? eciSet = eciSets.GetECITable();
Dictionary<string, int>? eciSet = eciSets.GetECITable();
if(eciSet == null)
if (eciSet == null)
return string.Empty;
// we will not check for utf8 encoding.
eciSet.Remove(QRCodeConstantVariable.UTF8Encoding);
eciSet.Remove(QRCodeConstantVariable.DefaultEncoding);
// we will not check for utf8 encoding.
eciSet.Remove(QRCodeConstantVariable.UTF8Encoding);
eciSet.Remove(QRCodeConstantVariable.DefaultEncoding);
int scanPos = startPos;
int scanPos = startPos;
// default encoding as priority
scanPos = ModeEncodeCheck.TryEncodeEightBitByte(content, QRCodeConstantVariable.DefaultEncoding, scanPos, contentLength);
if (scanPos == -1)
{
return QRCodeConstantVariable.DefaultEncoding;
}
// default encoding as priority
scanPos = ModeEncodeCheck.TryEncodeEightBitByte(content, QRCodeConstantVariable.DefaultEncoding, scanPos, contentLength);
if (scanPos == -1)
{
return QRCodeConstantVariable.DefaultEncoding;
}
foreach (KeyValuePair<string, int> kvp in eciSet)
{
scanPos = ModeEncodeCheck.TryEncodeEightBitByte(content, kvp.Key, scanPos, contentLength);
if (scanPos == -1)
{
return kvp.Key;
}
}
foreach (KeyValuePair<string, int> kvp in eciSet)
{
scanPos = ModeEncodeCheck.TryEncodeEightBitByte(content, kvp.Key, scanPos, contentLength);
if (scanPos == -1)
{
return kvp.Key;
}
}
if (scanPos == -1)
{
throw new ArgumentException("foreach Loop check give wrong result.");
}
else
{
return QRCodeConstantVariable.UTF8Encoding;
}
}
}
if (scanPos == -1)
{
throw new ArgumentException("foreach Loop check give wrong result.");
}
else
{
return QRCodeConstantVariable.UTF8Encoding;
}
}
}