Initial Commit
commit
919a4205f4
|
@ -0,0 +1,40 @@
|
|||
# Autosave files
|
||||
*~
|
||||
|
||||
# build
|
||||
[Oo]bj/
|
||||
[Bb]in/
|
||||
packages/
|
||||
TestResults/
|
||||
|
||||
# globs
|
||||
Makefile.in
|
||||
*.DS_Store
|
||||
*.sln.cache
|
||||
*.suo
|
||||
*.cache
|
||||
*.pidb
|
||||
*.userprefs
|
||||
*.usertasks
|
||||
config.log
|
||||
config.make
|
||||
config.status
|
||||
aclocal.m4
|
||||
install-sh
|
||||
autom4te.cache/
|
||||
*.user
|
||||
*.tar.gz
|
||||
tarballs/
|
||||
test-results/
|
||||
Thumbs.db
|
||||
|
||||
# Mac bundle stuff
|
||||
*.dmg
|
||||
*.app
|
||||
|
||||
# resharper
|
||||
*_Resharper.*
|
||||
*.Resharper
|
||||
|
||||
# dotCover
|
||||
*.dotCover
|
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public static class ArrayExtension
|
||||
{
|
||||
public static bool ArrayEquals<T>(this T[] a,T[] b){
|
||||
if (a.Length != b.Length){
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int n = 0; n < a.Length;n++){
|
||||
if (!a[n].Equals(b[n])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static T[] Extend<T>(this T[] source, int len)
|
||||
{
|
||||
if (source.Length < len)
|
||||
{
|
||||
T[] c = new T[len];
|
||||
Array.Copy(source, 0, c, 0, source.Length);
|
||||
Fill<T>(c, default(T),source.Length);
|
||||
return c;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
public static T[] Resize<T>(this T[] source, int len)
|
||||
{
|
||||
if (source.Length < len)
|
||||
{
|
||||
T[] c = new T[len];
|
||||
Array.Copy(source, 0, c, 0, source.Length);
|
||||
return c;
|
||||
} else if (source.Length > len){
|
||||
return Segment(source, 0, len);
|
||||
}
|
||||
return Segment(source, 0);
|
||||
}
|
||||
|
||||
public static T[] Segment<T>(this T[] source, int start) {
|
||||
return Segment(source, start, source.Length - start);
|
||||
}
|
||||
public static T[] Segment<T>(this T[] source,int start,int len){
|
||||
T[] temp = new T[len];
|
||||
Array.Copy(source,start,temp,0,len);
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static T[] Reverse<T>(this T[] source){
|
||||
T[] t = new T[source.Length];
|
||||
Array.Copy(source,t,source.Length);
|
||||
Array.Reverse(t);
|
||||
return t;
|
||||
}
|
||||
|
||||
public static void Fill<T>(this T[] a, T value)
|
||||
{
|
||||
Fill(a, value, 0, a.Length);
|
||||
}
|
||||
|
||||
public static void Fill<T>(this T[] a, T value,int start)
|
||||
{
|
||||
Fill(a, value, start, a.Length - start);
|
||||
}
|
||||
|
||||
public static void Fill<T>(this T[] a, T value,int start,int len)
|
||||
{
|
||||
for (int n = start; n < (start+len); n++)
|
||||
{
|
||||
a[n] = value;
|
||||
}
|
||||
}
|
||||
public static T[] Insert<T>(this T[] a, T[] insert, int start,int len) {
|
||||
Array.Copy(insert,0,a,start,len);
|
||||
return a;
|
||||
}
|
||||
public static T[] Insert<T>(this T[] a,T[] insert,int start){
|
||||
return Insert(a, insert, start, insert.Length);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.IO;
|
||||
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public static class DataReader
|
||||
{
|
||||
public static Int64 readVarInt(this TextReader reader){
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
using System;
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public enum Endianess
|
||||
{
|
||||
LittleEndian, BigEndian
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public class HexString
|
||||
{
|
||||
public static byte[] toBytes(string hexstring)
|
||||
{
|
||||
byte[] bytes = new byte[hexstring.Length >> 1];
|
||||
for (int n = 0; n < hexstring.Length >> 1;n++){
|
||||
bytes[n] = Convert.ToByte(hexstring.Substring(n << 1, 2), 16);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static String toString(byte[] bytes)
|
||||
{
|
||||
return BitConverter.ToString(bytes).Replace("-", String.Empty);
|
||||
}
|
||||
|
||||
public static String toString(byte[] bytes,int groupsize)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String hs = BitConverter.ToString(bytes).Replace("-", String.Empty);
|
||||
int n = hs.Length / (groupsize * 2);
|
||||
|
||||
for (int i = 0; i < n;i++){
|
||||
sb.Append(hs.Substring(n * (groupsize * 2), (groupsize * 2)));
|
||||
sb.Append(" ");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static String toString(byte[] bytes, int groupsize,int linewidth)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String hs = BitConverter.ToString(bytes).Replace("-", String.Empty);
|
||||
int n = hs.Length / (groupsize * 2);
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
sb.Append(hs.Substring(i * (groupsize * 2), (groupsize * 2)));
|
||||
if ((i!=0)&&((i % linewidth)==(linewidth-1))){
|
||||
sb.AppendLine();
|
||||
} else {
|
||||
sb.Append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("sharp.extensions")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string[] splitConstantWidth(this string s,int len){
|
||||
string[] result = new string[(s.Length+len-1) / len];
|
||||
for (int n = 0; n < result.Length;n++){
|
||||
result[n] = s.Substring(n * len, (n < result.Length - 1) ? len : s.Length % len);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] toBytes(this string hexstring)
|
||||
{
|
||||
byte[] bytes = new byte[hexstring.Length >> 1];
|
||||
for (int n = 0; n < hexstring.Length >> 1; n++)
|
||||
{
|
||||
bytes[n] = Convert.ToByte(hexstring.Substring(n << 1, 2), 16);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static String toHexString(this byte[] bytes)
|
||||
{
|
||||
return BitConverter.ToString(bytes).Replace("-", String.Empty);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public struct Tripple<_X>{
|
||||
public _X X { get; set; }
|
||||
public _X Y { get; set; }
|
||||
public _X Z { get; set; }
|
||||
|
||||
public Tripple(_X x, _X y, _X z)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
this.Z = z;
|
||||
}
|
||||
|
||||
public Tuple<_X> XY { get { return new Tuple<_X>(X, Y); } }
|
||||
public Tuple<_X> YZ { get { return new Tuple<_X>(Y, Z); } }
|
||||
public Tuple<_X> XZ { get { return new Tuple<_X>(X, Z); } }
|
||||
}
|
||||
|
||||
public struct Tripple<_X, _Y, _Z>
|
||||
{
|
||||
public _X X { get; set; }
|
||||
public _Y Y { get; set; }
|
||||
public _Z Z { get; set; }
|
||||
|
||||
public Tripple(_X x,_Y y,_Z z)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
this.Z = z;
|
||||
}
|
||||
|
||||
public Tuple<_X,_Y> XY { get { return new Tuple<_X,_Y>(X, Y); } }
|
||||
public Tuple<_Y,_Z> YZ { get { return new Tuple<_Y,_Z>(Y, Z); } }
|
||||
public Tuple<_X,_Z> XZ { get { return new Tuple<_X,_Z>(X, Z); } }
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public struct Tuple<_X>
|
||||
{
|
||||
public _X X { get; set; }
|
||||
public _X Y { get; set; }
|
||||
|
||||
public Tuple(_X x, _X y)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Tuple<_X,_Y>
|
||||
{
|
||||
public _X X { get; set; }
|
||||
public _Y Y { get; set; }
|
||||
|
||||
public Tuple(_X x,_Y y)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace sharp.extensions
|
||||
{
|
||||
public static class UInt64Extender
|
||||
{
|
||||
public static UInt64 RotateLeft(this UInt64 value, int count)
|
||||
{
|
||||
return (value << count) | (value >> (64 - count));
|
||||
}
|
||||
public static UInt64 RotateRight(this UInt64 value, int count)
|
||||
{
|
||||
return (value >> count) | (value << (64 - count));
|
||||
}
|
||||
|
||||
public static byte[] GetBytes(this UInt64 value){
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
public static byte[] GetBytes(this UInt64 value,Endianess endianess)
|
||||
{
|
||||
byte[] r = BitConverter.GetBytes(value);
|
||||
if (endianess != value.CurrentEndianess()){
|
||||
Array.Reverse(r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public static byte[] GetBytes(this Int64 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
public static byte[] GetBytes(this Int64 value, Endianess endianess)
|
||||
{
|
||||
byte[] r = BitConverter.GetBytes(value);
|
||||
if (endianess != value.CurrentEndianess())
|
||||
{
|
||||
Array.Reverse(r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public static byte[] GetBytes(this Int32 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
public static byte[] GetBytes(this Int32 value, Endianess endianess)
|
||||
{
|
||||
byte[] r = BitConverter.GetBytes(value);
|
||||
if (endianess != value.CurrentEndianess())
|
||||
{
|
||||
Array.Reverse(r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public static byte[] GetBytes(this UInt32 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
public static byte[] GetBytes(this UInt32 value, Endianess endianess)
|
||||
{
|
||||
byte[] r = BitConverter.GetBytes(value);
|
||||
if (endianess != value.CurrentEndianess())
|
||||
{
|
||||
Array.Reverse(r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
public static Endianess CurrentEndianess(this UInt64 v) { return BitConverter.IsLittleEndian ? Endianess.LittleEndian : Endianess.BigEndian; }
|
||||
public static Endianess CurrentEndianess(this UInt32 v) { return BitConverter.IsLittleEndian ? Endianess.LittleEndian : Endianess.BigEndian; }
|
||||
public static Endianess CurrentEndianess(this Int64 v) { return BitConverter.IsLittleEndian ? Endianess.LittleEndian : Endianess.BigEndian; }
|
||||
public static Endianess CurrentEndianess(this Int32 v) { return BitConverter.IsLittleEndian ? Endianess.LittleEndian : Endianess.BigEndian; }
|
||||
|
||||
public static byte[] getBytes(this UInt32[] values)
|
||||
{
|
||||
byte[] b = new byte[values.Length << 2];
|
||||
for (int n = 0; n < values.Length; n++)
|
||||
{
|
||||
b.Insert(values[n].GetBytes(), n << 2);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
public static UInt32[] toUInt32(this byte[] values)
|
||||
{
|
||||
UInt32[] r = new UInt32[ (values.Length + 0x03) >> 2 ];
|
||||
values = values.Extend(r.Length << 2);
|
||||
for (int n = 0; n < r.Length; n++)
|
||||
{
|
||||
r[n] = BitConverter.ToUInt32(values, (n << 2));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{97CA3CA9-98B3-4492-B072-D7A5995B68E9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>sharp.extensions</RootNamespace>
|
||||
<AssemblyName>sharp.extensions</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="HexString.cs" />
|
||||
<Compile Include="UInt64Extension.cs" />
|
||||
<Compile Include="Array.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
<Compile Include="Endianess.cs" />
|
||||
<Compile Include="DataReader.cs" />
|
||||
<Compile Include="Tripple.cs" />
|
||||
<Compile Include="Tuple.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Loading…
Reference in New Issue