wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 4  →  ?path2? @ 5
/Arrays.cs
@@ -20,7 +20,7 @@
/// <param name="index">a positive or negative index of the element</param>
/// <param name="data">the array</param>
/// <return>an array element</return>
public static T wasGetElementAt<T>(T[] data, int index)
public static T GetElementAt<T>(T[] data, int index)
{
switch (index < 0)
{
@@ -42,7 +42,7 @@
/// <param name="start">the start index</param>
/// <param name="stop">the stop index (-1 denotes the end)</param>
/// <returns>the array slice between start and stop</returns>
public static T[] wasGetSubArray<T>(T[] data, int start, int stop)
public static T[] GetSubArray<T>(T[] data, int start, int stop)
{
if (stop.Equals(-1))
stop = data.Length - 1;
@@ -62,7 +62,7 @@
/// <param name="start">the start index</param>
/// <param name="stop">the stop index (-1 denotes the end)</param>
/// <returns>the array without elements between start and stop</returns>
public static T[] wasDeleteSubArray<T>(T[] data, int start, int stop)
public static T[] DeleteSubArray<T>(T[] data, int start, int stop)
{
if (stop.Equals(-1))
stop = data.Length - 1;
@@ -81,7 +81,7 @@
/// <typeparam name="T">the array type</typeparam>
/// <param name="arrays">multiple arrays</param>
/// <returns>a flat array with all arrays concatenated</returns>
public static T[] wasConcatenateArrays<T>(params T[][] arrays)
public static T[] ConcatenateArrays<T>(params T[][] arrays)
{
int resultLength = 0;
foreach (T[] o in arrays)
@@ -108,13 +108,13 @@
/// <param name="input">the array</param>
/// <param name="times">the number of times to permute</param>
/// <returns>the array with the elements permuted</returns>
public static T[] wasReversePermuteArrayElements<T>(T[] input, int times)
public static T[] ReversePermuteArrayElements<T>(T[] input, int times)
{
if (times.Equals(0)) return input;
T[] slice = new T[input.Length];
Array.Copy(input, 1, slice, 0, input.Length - 1);
Array.Copy(input, 0, slice, input.Length - 1, 1);
return wasReversePermuteArrayElements(slice, --times);
return ReversePermuteArrayElements(slice, --times);
}
 
///////////////////////////////////////////////////////////////////////////
@@ -127,13 +127,13 @@
/// <param name="input">the array</param>
/// <param name="times">the number of times to permute</param>
/// <returns>the array with the elements permuted</returns>
public static T[] wasForwardPermuteArrayElements<T>(T[] input, int times)
public static T[] ForwardPermuteArrayElements<T>(T[] input, int times)
{
if (times.Equals(0)) return input;
T[] slice = new T[input.Length];
Array.Copy(input, input.Length - 1, slice, 0, 1);
Array.Copy(input, 0, slice, 1, input.Length - 1);
return wasForwardPermuteArrayElements(slice, --times);
return ForwardPermuteArrayElements(slice, --times);
}
}
}
/BitTwiddling.cs
@@ -16,7 +16,7 @@
/// </summary>
/// <param name="q">first integer to swap</param>
/// <param name="p">second integer to swap</param>
public static void wasXORSwap(ref int q, ref int p)
public static void XORSwap(ref int q, ref int p)
{
q ^= p;
p ^= q;
/CSV.cs
@@ -22,7 +22,7 @@
/// <param name="l">a list of strings</param>
/// <returns>a commma-separated list of values</returns>
/// <remarks>compliant with RFC 4180</remarks>
public static string wasEnumerableToCSV(IEnumerable<string> l)
public static string FromEnumerable(IEnumerable<string> l)
{
string[] csv = l.Select(o => o).ToArray();
char[] escapeCharacters = {'"', ' ', ',', '\r', '\n'};
@@ -52,7 +52,7 @@
/// <param name="csv">a comma-separated list of values</param>
/// <returns>a list of strings</returns>
/// <remarks>compliant with RFC 4180</remarks>
public static IEnumerable<string> wasCSVToEnumerable(string csv)
public static IEnumerable<string> ToEnumerable(string csv)
{
Stack<char> s = new Stack<char>();
StringBuilder m = new StringBuilder();
/Cryptography.cs
@@ -25,7 +25,7 @@
/// <param name="plugs">the letter representing the start character for the rotor</param>
/// <param name="reflector">any one of: B, b, C, c</param>
/// <returns>either a decrypted or encrypted string</returns>
public static string wasEnigma(string message, char[] rotors, char[] plugs, char reflector)
public static string ENIGMA(string message, char[] rotors, char[] plugs, char reflector)
{
Dictionary<char, char[]> def_rotors = new Dictionary<char, char[]>
{
@@ -187,9 +187,9 @@
char plug = plugs[Array.IndexOf(rotors, rotor)];
int i = Array.IndexOf(def_rotors[rotor], plug);
if (i.Equals(0)) continue;
def_rotors[rotor] = Arrays.wasConcatenateArrays(new[] {plug},
Arrays.wasGetSubArray(Arrays.wasDeleteSubArray(def_rotors[rotor], i, i), i, -1),
Arrays.wasGetSubArray(Arrays.wasDeleteSubArray(def_rotors[rotor], i + 1, -1), 0, i - 1));
def_rotors[rotor] = Arrays.ConcatenateArrays(new[] {plug},
Arrays.GetSubArray(Arrays.DeleteSubArray(def_rotors[rotor], i, i), i, -1),
Arrays.GetSubArray(Arrays.DeleteSubArray(def_rotors[rotor], i + 1, -1), 0, i - 1));
}
 
StringBuilder result = new StringBuilder();
@@ -209,14 +209,14 @@
int i = o.Length - 1;
do
{
def_rotors[o[0]] = Arrays.wasForwardPermuteArrayElements(def_rotors[o[0]], 1);
def_rotors[o[0]] = Arrays.ForwardPermuteArrayElements(def_rotors[o[0]], 1);
if (i.Equals(0))
{
rotors = Arrays.wasReversePermuteArrayElements(o, 1);
rotors = Arrays.ReversePermuteArrayElements(o, 1);
continue;
}
l = Arrays.wasGetElementAt(def_rotors[o[1]], Array.IndexOf(def_rotors[o[0]], l) - 1);
o = Arrays.wasReversePermuteArrayElements(o, 1);
l = Arrays.GetElementAt(def_rotors[o[1]], Array.IndexOf(def_rotors[o[0]], l) - 1);
o = Arrays.ReversePermuteArrayElements(o, 1);
} while (--i > -1);
};
 
@@ -252,7 +252,7 @@
/// <param name="input">the input to expand to</param>
/// <param name="enc_key">the key to expand</param>
/// <returns>the expanded key</returns>
public static string wasVigenereExpandKey(string input, string enc_key)
public static string VIGENEREExpandKey(string input, string enc_key)
{
string exp_key = string.Empty;
int i = 0, j = 0;
@@ -282,7 +282,7 @@
/// <param name="input">the input to encrypt</param>
/// <param name="enc_key">the key to encrypt with</param>
/// <returns>the encrypted input</returns>
public static string wasEncryptVIGENERE(string input, string enc_key)
public static string EncryptVIGENERE(string input, string enc_key)
{
char[] a =
{
@@ -290,7 +290,7 @@
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
};
 
enc_key = wasVigenereExpandKey(input, enc_key);
enc_key = VIGENEREExpandKey(input, enc_key);
string result = string.Empty;
int i = 0;
do
@@ -303,7 +303,7 @@
continue;
}
char q =
Arrays.wasReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i]))[
Arrays.ReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i]))[
Array.IndexOf(a, char.ToLowerInvariant(p))];
if (char.IsUpper(p))
{
@@ -324,7 +324,7 @@
/// <param name="input">the input to decrypt</param>
/// <param name="enc_key">the key to decrypt with</param>
/// <returns>the decrypted input</returns>
public static string wasDecryptVIGENERE(string input, string enc_key)
public static string DecryptVIGENERE(string input, string enc_key)
{
char[] a =
{
@@ -332,7 +332,7 @@
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
};
 
enc_key = wasVigenereExpandKey(input, enc_key);
enc_key = VIGENEREExpandKey(input, enc_key);
string result = string.Empty;
int i = 0;
do
@@ -346,7 +346,7 @@
}
char q =
a[
Array.IndexOf(Arrays.wasReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i])),
Array.IndexOf(Arrays.ReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i])),
char.ToLowerInvariant(p))];
if (char.IsUpper(p))
{
@@ -366,7 +366,7 @@
/// </summary>
/// <param name="data">the data to encrypt or decrypt</param>
/// <returns>the encrypted or decrypted data</returns>
public static string wasATBASH(string data)
public static string ATBASH(string data)
{
char[] a =
{
/KeyValue.cs
@@ -21,7 +21,7 @@
/// <param name="key">the key of the value</param>
/// <param name="data">the key-value data segment</param>
/// <returns>true if the key was found in data</returns>
public static string wasKeyValueGet(string key, string data)
public static string Get(string key, string data)
{
return data.Split('&')
.AsParallel()
@@ -50,7 +50,7 @@
/// a key-value data string or the empty string if either key or
/// value are empty
/// </returns>
public static string wasKeyValueSet(string key, string value, string data)
public static string Set(string key, string value, string data)
{
HashSet<string> output = new HashSet<string>(data.Split('&')
.AsParallel()
@@ -78,7 +78,7 @@
/// <param name="key">the key to search for</param>
/// <param name="data">the key-value data segment</param>
/// <returns>a key-value pair string</returns>
public static string wasKeyValueDelete(string key, string data)
public static string Delete(string key, string data)
{
return string.Join("&", data.Split('&')
.AsParallel()
@@ -102,7 +102,7 @@
/// </summary>
/// <param name="data">the key-value pair data</param>
/// <returns>a dictionary containing the keys and values</returns>
public static Dictionary<string, string> wasKeyValueDecode(string data)
public static Dictionary<string, string> Decode(string data)
{
return data.Split('&')
.AsParallel()
@@ -125,7 +125,7 @@
/// </summary>
/// <param name="data">a dictionary</param>
/// <returns>a key-value data encoded string</returns>
public static string wasKeyValueEncode(Dictionary<string, string> data)
public static string Encode(Dictionary<string, string> data)
{
return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key, o.Value)));
}
@@ -136,7 +136,7 @@
/// <summary>Escapes a dictionary's keys and values for sending as POST data.</summary>
/// <param name="data">A dictionary containing keys and values to be escaped</param>
/// <param name="func">The function to use to escape the keys and values in the dictionary.</param>
public static Dictionary<string, string> wasKeyValueEscape(Dictionary<string, string> data,
public static Dictionary<string, string> Escape(Dictionary<string, string> data,
Func<string, string> func)
{
return data.AsParallel().ToDictionary(o => func(o.Key), p => func(p.Value));
/Numerics.cs
@@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
namespace wasSharp
{
public class Numerics
{
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Given a value in a source value range and a target range, map
/// the value from the source range into the target range.
/// </summary>
/// <param name="value">the value to map</param>
/// <param name="xMin">the lower bound of the source range</param>
/// <param name="xMax">the upper bound of the source range</param>
/// <param name="yMin">the lower bound of the target range</param>
/// <param name="yMax">the upper bound of the target range</param>
public static double MapValueToRange(double value, double xMin, double xMax, double yMin, double yMax)
{
return yMin + (
(
yMax - yMin
)
*
(
value - xMin
)
/
(
xMax - xMin
)
);
}
}
}
/Properties/AssemblyInfo.cs
@@ -26,4 +26,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
 
[assembly: AssemblyVersion("1.3.*")]
[assembly: AssemblyVersion("1.4.*")]
/Reflection.cs
@@ -20,7 +20,7 @@
/// Retrieves an attribute of type T from an enumeration.
/// </summary>
/// <returns>an attribute of type T</returns>
public static T wasGetAttributeFromEnumValue<T>(Enum value) where T : Attribute
public static T GetAttributeFromEnumValue<T>(Enum value) where T : Attribute
{
return (T) value.GetType()
.GetRuntimeField(value.ToString())
@@ -36,11 +36,11 @@
/// </summary>
/// <typeparam name="T">the attribute to retrieve</typeparam>
/// <returns>a list of attributes</returns>
public static IEnumerable<T> wasGetEnumAttributes<T>(Enum e) where T : Attribute
public static IEnumerable<T> GetEnumAttributes<T>(Enum e) where T : Attribute
{
return e.GetType().GetRuntimeFields()
.AsParallel()
.Select(o => wasGetAttributeFromEnumValue<T>((Enum) o.GetValue(Activator.CreateInstance<T>())));
.Select(o => GetAttributeFromEnumValue<T>((Enum) o.GetValue(Activator.CreateInstance<T>())));
}
 
///////////////////////////////////////////////////////////////////////////
@@ -50,7 +50,7 @@
/// Returns all the field names of an enumeration.
/// </summary>
/// <returns>the field names</returns>
public static IEnumerable<string> wasGetEnumNames<T>()
public static IEnumerable<string> GetEnumNames<T>()
{
return
typeof (T).GetRuntimeFields()
@@ -68,7 +68,7 @@
/// Returns all the values of an enumeration.
/// </summary>
/// <returns>the values of the enumeration</returns>
public static IEnumerable<T> wasGetEnumValues<T>()
public static IEnumerable<T> GetEnumValues<T>()
{
return Enum.GetValues(typeof (T)).Cast<object>().Select(value => (T) value);
}
@@ -81,7 +81,7 @@
/// </summary>
/// <param name="value">an enumeration value</param>
/// <returns>the description or the empty string</returns>
public static string wasGetNameFromEnumValue(Enum value)
public static string GetNameFromEnumValue(Enum value)
{
NameAttribute attribute = value.GetType()
.GetRuntimeField(value.ToString())
@@ -98,7 +98,7 @@
/// </summary>
/// <param name="value">an enumeration value</param>
/// <returns>the description or the empty string</returns>
public static string wasGetDescriptionFromEnumValue(Enum value)
public static string GetDescriptionFromEnumValue(Enum value)
{
DescriptionAttribute attribute = value.GetType()
.GetRuntimeField(value.ToString())
@@ -116,7 +116,7 @@
/// <typeparam name="T">the enumeration type</typeparam>
/// <param name="name">the description of a member</param>
/// <returns>the value or the default of T if case no name attribute found</returns>
public static T wasGetEnumValueFromName<T>(string name)
public static T GetEnumValueFromName<T>(string name)
{
var field = typeof (T).GetRuntimeFields()
.AsParallel().SelectMany(f => f.GetCustomAttributes(
@@ -136,7 +136,7 @@
/// <param name="structure">the structure to search</param>
/// <param name="item">the value of the item to search</param>
/// <returns>the description or the empty string</returns>
public static string wasGetStructureMemberName<T>(T structure, object item) where T : struct
public static string GetStructureMemberName<T>(T structure, object item) where T : struct
{
var field = typeof (T).GetRuntimeFields()
.AsParallel().SelectMany(f => f.GetCustomAttributes(typeof (NameAttribute), false),
/Time.cs
@@ -109,7 +109,7 @@
/// another lined-up event. This is mostly used to check that throttles
/// are being respected.
/// </summary>
public class wasTimedThrottle : IDisposable
public class TimedThrottle : IDisposable
{
private readonly uint EventsAllowed;
private readonly object LockObject = new object();
@@ -116,7 +116,7 @@
private Timer timer;
private uint TriggeredEvents;
 
public wasTimedThrottle(uint events, uint seconds)
public TimedThrottle(uint events, uint seconds)
{
EventsAllowed = events;
if (timer == null)
@@ -168,7 +168,7 @@
/// <remarks>
/// (C) Wizardry and Steamworks 2013 - License: GNU GPLv3
/// </remarks>
public class wasAdaptiveAlarm : IDisposable
public class DecayingAlarm : IDisposable
{
[Flags]
public enum DECAY_TYPE
@@ -189,16 +189,16 @@
/// <summary>
/// The default constructor using no decay.
/// </summary>
public wasAdaptiveAlarm()
public DecayingAlarm()
{
Signal = new ManualResetEvent(false);
}
 
/// <summary>
/// The constructor for the wasAdaptiveAlarm class taking as parameter a decay type.
/// The constructor for the DecayingAlarm class taking as parameter a decay type.
/// </summary>
/// <param name="decay">the type of decay: arithmetic, geometric, harmonic, heronian or quadratic</param>
public wasAdaptiveAlarm(DECAY_TYPE decay)
public DecayingAlarm(DECAY_TYPE decay)
{
Signal = new ManualResetEvent(false);
this.decay = decay;
/Web.cs
@@ -18,7 +18,7 @@
/// <summary>RFC3986 URI Escapes a string</summary>
/// <param name="data">a string to escape</param>
/// <returns>an RFC3986 escaped string</returns>
public static string wasURIEscapeDataString(string data)
public static string URIEscapeDataString(string data)
{
// Uri.EscapeDataString can only handle 32766 characters at a time
return string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766)
@@ -32,7 +32,7 @@
/// <summary>URI unescapes an RFC3986 URI escaped string</summary>
/// <param name="data">a string to unescape</param>
/// <returns>the resulting string</returns>
public static string wasURIUnescapeDataString(string data)
public static string URIUnescapeDataString(string data)
{
// Uri.UnescapeDataString can only handle 32766 characters at a time
return string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766)
@@ -46,7 +46,7 @@
/// <summary>RFC1738 URL Escapes a string</summary>
/// <param name="data">a string to escape</param>
/// <returns>an RFC1738 escaped string</returns>
public static string wasURLEscapeDataString(string data)
public static string URLEscapeDataString(string data)
{
return WebUtility.UrlEncode(data);
}
@@ -57,7 +57,7 @@
/// <summary>RFC1738 URL Unescape a string</summary>
/// <param name="data">a string to unescape</param>
/// <returns>an RFC1738 unescaped string</returns>
public static string wasURLUnescapeDataString(string data)
public static string URLUnescapeDataString(string data)
{
return WebUtility.UrlDecode(data);
}
/wasSharp.csproj
@@ -43,6 +43,7 @@
<Compile Include="Cryptography.cs" />
<Compile Include="CSV.cs" />
<Compile Include="KeyValue.cs" />
<Compile Include="Numerics.cs" />
<Compile Include="Reflection.cs" />
<Compile Include="Time.cs" />
<Compile Include="wasSharp.cs" />