init commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
public interface Color
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Size = 1)]
|
||||
public struct Color_Fields
|
||||
{
|
||||
public static readonly int GRAY = 11184810;
|
||||
|
||||
public static readonly int LIGHTGRAY = 12303291;
|
||||
|
||||
public static readonly int DARKGRAY = 4473924;
|
||||
|
||||
public static readonly int BLACK = 0;
|
||||
|
||||
public static readonly int WHITE = 16777215;
|
||||
|
||||
public static readonly int BLUE = 8947967;
|
||||
|
||||
public static readonly int GREEN = 8978312;
|
||||
|
||||
public static readonly int LIGHTBLUE = 12303359;
|
||||
|
||||
public static readonly int LIGHTGREEN = 12320699;
|
||||
|
||||
public static readonly int RED = 267946120;
|
||||
|
||||
public static readonly int ORANGE = 16777096;
|
||||
|
||||
public static readonly int LIGHTRED = 16759739;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using MessagingToolkit.QRCode.Geom;
|
||||
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
public class ConsoleCanvas : DebugCanvas
|
||||
{
|
||||
public void println(string str)
|
||||
{
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
|
||||
public void drawPoint(Point point, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public void drawCross(Point point, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public void drawPoints(Point[] points, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public void drawLine(Line line, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public void drawLines(Line[] lines, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public void drawPolygon(Point[] points, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public void drawMatrix(bool[][] matrix)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
public class ContentConverter
|
||||
{
|
||||
internal static char n = '\n';
|
||||
|
||||
public static string convert(string targetString)
|
||||
{
|
||||
if (targetString == null)
|
||||
{
|
||||
return targetString;
|
||||
}
|
||||
if (targetString.IndexOf("MEBKM:") > -1)
|
||||
{
|
||||
targetString = convertDocomoBookmark(targetString);
|
||||
}
|
||||
if (targetString.IndexOf("MECARD:") > -1)
|
||||
{
|
||||
targetString = convertDocomoAddressBook(targetString);
|
||||
}
|
||||
if (targetString.IndexOf("MATMSG:") > -1)
|
||||
{
|
||||
targetString = convertDocomoMailto(targetString);
|
||||
}
|
||||
if (targetString.IndexOf("http\\://") > -1)
|
||||
{
|
||||
targetString = replaceString(targetString, "http\\://", "\nhttp://");
|
||||
}
|
||||
return targetString;
|
||||
}
|
||||
|
||||
private static string convertDocomoBookmark(string targetString)
|
||||
{
|
||||
targetString = removeString(targetString, "MEBKM:");
|
||||
targetString = removeString(targetString, "TITLE:");
|
||||
targetString = removeString(targetString, ";");
|
||||
targetString = removeString(targetString, "URL:");
|
||||
return targetString;
|
||||
}
|
||||
|
||||
private static string convertDocomoAddressBook(string targetString)
|
||||
{
|
||||
targetString = removeString(targetString, "MECARD:");
|
||||
targetString = removeString(targetString, ";");
|
||||
targetString = replaceString(targetString, "N:", "NAME1:");
|
||||
targetString = replaceString(targetString, "SOUND:", n + "NAME2:");
|
||||
targetString = replaceString(targetString, "TEL:", n + "TEL1:");
|
||||
targetString = replaceString(targetString, "EMAIL:", n + "MAIL1:");
|
||||
targetString += n;
|
||||
return targetString;
|
||||
}
|
||||
|
||||
private static string convertDocomoMailto(string s)
|
||||
{
|
||||
string s2 = s;
|
||||
char c = '\n';
|
||||
s2 = removeString(s2, "MATMSG:");
|
||||
s2 = removeString(s2, ";");
|
||||
s2 = replaceString(s2, "TO:", "MAILTO:");
|
||||
s2 = replaceString(s2, "SUB:", c + "SUBJECT:");
|
||||
s2 = replaceString(s2, "BODY:", c + "BODY:");
|
||||
return s2 + c;
|
||||
}
|
||||
|
||||
private static string replaceString(string s, string s1, string s2)
|
||||
{
|
||||
string text = s;
|
||||
for (int num = text.IndexOf(s1, 0); num > -1; num = text.IndexOf(s1, num + s2.Length))
|
||||
{
|
||||
text = text.Substring(0, num) + s2 + text.Substring(num + s1.Length);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static string removeString(string s, string s1)
|
||||
{
|
||||
return replaceString(s, s1, "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using MessagingToolkit.QRCode.Geom;
|
||||
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
public interface DebugCanvas
|
||||
{
|
||||
void println(string str);
|
||||
|
||||
void drawPoint(Point point, int color);
|
||||
|
||||
void drawCross(Point point, int color);
|
||||
|
||||
void drawPoints(Point[] points, int color);
|
||||
|
||||
void drawLine(Line line, int color);
|
||||
|
||||
void drawLines(Line[] lines, int color);
|
||||
|
||||
void drawPolygon(Point[] points, int color);
|
||||
|
||||
void drawMatrix(bool[][] matrix);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using MessagingToolkit.QRCode.Geom;
|
||||
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
public class DebugCanvasAdapter : DebugCanvas
|
||||
{
|
||||
public virtual void println(string string_Renamed)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void drawPoint(Point point, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void drawCross(Point point, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void drawPoints(Point[] points, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void drawLine(Line line, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void drawLines(Line[] lines, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void drawPolygon(Point[] points, int color)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void drawMatrix(bool[][] matrix)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System.Text;
|
||||
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
public class QRCodeUtility
|
||||
{
|
||||
public static int sqrt(int val)
|
||||
{
|
||||
int num = 0;
|
||||
int num2 = 32768;
|
||||
int num3 = 15;
|
||||
do
|
||||
{
|
||||
int num4;
|
||||
if (val >= (num4 = (num << 1) + num2 << num3--))
|
||||
{
|
||||
num += num2;
|
||||
val -= num4;
|
||||
}
|
||||
}
|
||||
while ((num2 >>= 1) > 0);
|
||||
return num;
|
||||
}
|
||||
|
||||
public static bool IsUniCode(string value)
|
||||
{
|
||||
byte[] characters = AsciiStringToByteArray(value);
|
||||
byte[] characters2 = UnicodeStringToByteArray(value);
|
||||
string text = FromASCIIByteArray(characters);
|
||||
string text2 = FromUnicodeByteArray(characters2);
|
||||
if (text != text2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsUnicode(byte[] byteData)
|
||||
{
|
||||
string str = FromASCIIByteArray(byteData);
|
||||
string str2 = FromUnicodeByteArray(byteData);
|
||||
byte[] array = AsciiStringToByteArray(str);
|
||||
byte[] array2 = UnicodeStringToByteArray(str2);
|
||||
if (array[0] != array2[0])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static string FromASCIIByteArray(byte[] characters)
|
||||
{
|
||||
ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
|
||||
return aSCIIEncoding.GetString(characters);
|
||||
}
|
||||
|
||||
public static string FromUnicodeByteArray(byte[] characters)
|
||||
{
|
||||
UnicodeEncoding unicodeEncoding = new UnicodeEncoding();
|
||||
return unicodeEncoding.GetString(characters);
|
||||
}
|
||||
|
||||
public static byte[] AsciiStringToByteArray(string str)
|
||||
{
|
||||
ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
|
||||
return aSCIIEncoding.GetBytes(str);
|
||||
}
|
||||
|
||||
public static byte[] UnicodeStringToByteArray(string str)
|
||||
{
|
||||
UnicodeEncoding unicodeEncoding = new UnicodeEncoding();
|
||||
return unicodeEncoding.GetBytes(str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace MessagingToolkit.QRCode.Codec.Util;
|
||||
|
||||
public class SystemUtils
|
||||
{
|
||||
public static int ReadInput(Stream sourceStream, sbyte[] target, int start, int count)
|
||||
{
|
||||
if (target.Length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
byte[] array = new byte[target.Length];
|
||||
int num = sourceStream.Read(array, start, count);
|
||||
if (num == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int i = start; i < start + num; i++)
|
||||
{
|
||||
target[i] = (sbyte)array[i];
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public static int ReadInput(TextReader sourceTextReader, short[] target, int start, int count)
|
||||
{
|
||||
if (target.Length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
char[] array = new char[target.Length];
|
||||
int num = sourceTextReader.Read(array, start, count);
|
||||
if (num == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int i = start; i < start + num; i++)
|
||||
{
|
||||
target[i] = (short)array[i];
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public static void WriteStackTrace(Exception throwable, TextWriter stream)
|
||||
{
|
||||
stream.Write(throwable.StackTrace);
|
||||
stream.Flush();
|
||||
}
|
||||
|
||||
public static int URShift(int number, int bits)
|
||||
{
|
||||
if (number >= 0)
|
||||
{
|
||||
return number >> bits;
|
||||
}
|
||||
return (number >> bits) + (2 << ~bits);
|
||||
}
|
||||
|
||||
public static int URShift(int number, long bits)
|
||||
{
|
||||
return URShift(number, (int)bits);
|
||||
}
|
||||
|
||||
public static long URShift(long number, int bits)
|
||||
{
|
||||
if (number >= 0)
|
||||
{
|
||||
return number >> bits;
|
||||
}
|
||||
return (number >> bits) + (2L << ~bits);
|
||||
}
|
||||
|
||||
public static long URShift(long number, long bits)
|
||||
{
|
||||
return URShift(number, (int)bits);
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(sbyte[] sbyteArray)
|
||||
{
|
||||
byte[] array = null;
|
||||
if (sbyteArray != null)
|
||||
{
|
||||
array = new byte[sbyteArray.Length];
|
||||
for (int i = 0; i < sbyteArray.Length; i++)
|
||||
{
|
||||
array[i] = (byte)sbyteArray[i];
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(string sourceString)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(sourceString);
|
||||
}
|
||||
|
||||
public static byte[] ToByteArray(object[] tempObjectArray)
|
||||
{
|
||||
byte[] array = null;
|
||||
if (tempObjectArray != null)
|
||||
{
|
||||
array = new byte[tempObjectArray.Length];
|
||||
for (int i = 0; i < tempObjectArray.Length; i++)
|
||||
{
|
||||
array[i] = (byte)tempObjectArray[i];
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static sbyte[] ToSByteArray(byte[] byteArray)
|
||||
{
|
||||
sbyte[] array = null;
|
||||
if (byteArray != null)
|
||||
{
|
||||
array = new sbyte[byteArray.Length];
|
||||
for (int i = 0; i < byteArray.Length; i++)
|
||||
{
|
||||
array[i] = (sbyte)byteArray[i];
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static char[] ToCharArray(sbyte[] sByteArray)
|
||||
{
|
||||
return Encoding.UTF8.GetChars(ToByteArray(sByteArray));
|
||||
}
|
||||
|
||||
public static char[] ToCharArray(byte[] byteArray)
|
||||
{
|
||||
return Encoding.UTF8.GetChars(byteArray);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user