AxibugEmuOnline/AxibugEmuOnline.Client/Assets/MyNes.Core/ComponentAce.Compression.Libs.zlib/SupportClass.cs

105 lines
2.2 KiB
C#
Raw Normal View History

2024-07-03 18:15:28 +08:00
using System.IO;
using System.Text;
2024-07-03 18:22:22 +08:00
namespace ComponentAce.Compression.Libs.zlib
2024-07-03 18:15:28 +08:00
{
2024-07-03 18:22:22 +08:00
public class SupportClass
{
public static long Identity(long literal)
{
return literal;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static ulong Identity(ulong literal)
{
return literal;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static float Identity(float literal)
{
return literal;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static double Identity(double literal)
{
return literal;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static int URShift(int number, int bits)
{
if (number >= 0)
{
return number >> bits;
}
return (number >> bits) + (2 << ~bits);
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static int URShift(int number, long bits)
{
return URShift(number, (int)bits);
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static long URShift(long number, int bits)
{
if (number >= 0)
{
return number >> bits;
}
return (number >> bits) + (2L << ~bits);
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static long URShift(long number, long bits)
{
return URShift(number, (int)bits);
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static int ReadInput(Stream sourceStream, byte[] 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] = array[i];
}
return num;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static int ReadInput(TextReader sourceTextReader, byte[] 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] = (byte)array[i];
}
return num;
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static byte[] ToByteArray(string sourceString)
{
return Encoding.UTF8.GetBytes(sourceString);
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
public static char[] ToCharArray(byte[] byteArray)
{
return Encoding.UTF8.GetChars(byteArray);
}
}
2024-07-03 15:40:13 +08:00
}