REFACTOR: Final cleanup of DiscImageChef.Helpers.

This commit is contained in:
2017-12-24 02:46:53 +00:00
parent f9cc6e6918
commit 5bdd1ea0cd
19 changed files with 345 additions and 230 deletions

View File

@@ -53,7 +53,8 @@ namespace DiscImageChef
{ {
if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray)); if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray));
if(value.Length > destinationArray.Length) throw new ArgumentException("Length of value array must not be more than length of destination"); if(value.Length > destinationArray.Length)
throw new ArgumentException("Length of value array must not be more than length of destination");
// set the initial array value // set the initial array value
Array.Copy(value, destinationArray, value.Length); Array.Copy(value, destinationArray, value.Length);
@@ -61,7 +62,8 @@ namespace DiscImageChef
int arrayToFillHalfLength = destinationArray.Length / 2; int arrayToFillHalfLength = destinationArray.Length / 2;
int copyLength; int copyLength;
for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1)
Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength);
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
} }

View File

@@ -175,9 +175,12 @@ namespace DiscImageChef
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>true if the byte at <see cref="startIndex"/> in value is nonzero; otherwise, false.</returns> /// <returns>true if the byte at <see cref="startIndex" /> in value is nonzero; otherwise, false.</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// <see cref="startIndex" /> is less than zero or greater than the
/// length of value minus 1.
/// </exception>
public static bool ToBoolean(byte[] value, int startIndex) public static bool ToBoolean(byte[] value, int startIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@@ -188,24 +191,34 @@ namespace DiscImageChef
/// </summary> /// </summary>
/// <param name="value">An array.</param> /// <param name="value">An array.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A character formed by two bytes beginning at <see cref="startIndex"/>.</returns> /// <returns>A character formed by two bytes beginning at <see cref="startIndex" />.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> equals the length of value minus 1.</exception> /// <exception cref="System.ArgumentException"><see cref="startIndex" /> equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// <see cref="startIndex" /> is less than zero or greater than the
/// length of value minus 1.
/// </exception>
public static char ToChar(byte[] value, int startIndex) public static char ToChar(byte[] value, int startIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <summary> /// <summary>
/// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array. /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte
/// array.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A double precision floating point number formed by eight bytes beginning at <see cref="startIndex"/>.</returns> /// <returns>A double precision floating point number formed by eight bytes beginning at <see cref="startIndex" />.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception> /// <exception cref="System.ArgumentException">
/// <see cref="startIndex" /> is greater than or equal to the length of value
/// minus 7, and is less than or equal to the length of value minus 1.
/// </exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// <see cref="startIndex" /> is less than zero or greater than the
/// length of value minus 1.
/// </exception>
public static double ToDouble(byte[] value, int startIndex) public static double ToDouble(byte[] value, int startIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@@ -216,10 +229,13 @@ namespace DiscImageChef
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A 16-bit signed integer formed by two bytes beginning at <see cref="startIndex"/>.</returns> /// <returns>A 16-bit signed integer formed by two bytes beginning at <see cref="startIndex" />.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> equals the length of value minus 1.</exception> /// <exception cref="System.ArgumentException"><see cref="startIndex" /> equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// startIndex is less than zero or greater than the length of value
/// minus 1.
/// </exception>
public static short ToInt16(byte[] value, int startIndex) public static short ToInt16(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -232,10 +248,16 @@ namespace DiscImageChef
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A 32-bit signed integer formed by four bytes beginning at <see cref="startIndex"/>.</returns> /// <returns>A 32-bit signed integer formed by four bytes beginning at <see cref="startIndex" />.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception> /// <exception cref="System.ArgumentException">
/// <see cref="startIndex" /> is greater than or equal to the length of value
/// minus 3, and is less than or equal to the length of value minus 1.
/// </exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// startIndex is less than zero or greater than the length of value
/// minus 1.
/// </exception>
public static int ToInt32(byte[] value, int startIndex) public static int ToInt32(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -248,10 +270,16 @@ namespace DiscImageChef
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A 64-bit signed integer formed by eight bytes beginning at <see cref="startIndex"/>.</returns> /// <returns>A 64-bit signed integer formed by eight bytes beginning at <see cref="startIndex" />.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception> /// <exception cref="System.ArgumentException">
/// <see cref="startIndex" /> is greater than or equal to the length of value
/// minus 7, and is less than or equal to the length of value minus 1.
/// </exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// <see cref="startIndex" /> is less than zero or greater than the
/// length of value minus 1.
/// </exception>
public static long ToInt64(byte[] value, int startIndex) public static long ToInt64(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -260,14 +288,21 @@ namespace DiscImageChef
} }
/// <summary> /// <summary>
/// Returns a single-precision floating point number converted from four bytes at a specified position in a byte array. /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte
/// array.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A single-precision floating point number formed by four bytes beginning at <see cref="startIndex"/>.</returns> /// <returns>A single-precision floating point number formed by four bytes beginning at <see cref="startIndex" />.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception> /// <exception cref="System.ArgumentException">
/// <see cref="startIndex" /> is greater than or equal to the length of value
/// minus 3, and is less than or equal to the length of value minus 1.
/// </exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// <see cref="startIndex" /> is less than zero or greater than the
/// length of value minus 1.
/// </exception>
public static float ToSingle(byte[] value, int startIndex) public static float ToSingle(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -276,10 +311,14 @@ namespace DiscImageChef
} }
/// <summary> /// <summary>
/// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation. /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string
/// representation.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A".</returns> /// <returns>
/// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding
/// element in value; for example, "7F-2C-4A".
/// </returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
public static string ToString(byte[] value) public static string ToString(byte[] value)
{ {
@@ -287,13 +326,20 @@ namespace DiscImageChef
} }
/// <summary> /// <summary>
/// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string
/// representation.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".</returns> /// <returns>
/// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding
/// element in a subarray of value; for example, "7F-2C-4A".
/// </returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// startIndex is less than zero or greater than the length of value
/// minus 1.
/// </exception>
public static string ToString(byte[] value, int startIndex) public static string ToString(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -302,15 +348,25 @@ namespace DiscImageChef
} }
/// <summary> /// <summary>
/// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string
/// representation.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <param name="length">The number of array elements in value to convert.</param> /// <param name="length">The number of array elements in value to convert.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".</returns> /// <returns>
/// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding
/// element in a subarray of value; for example, "7F-2C-4A".
/// </returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex or length is less than zero. -or- startIndex is greater than zero and is greater than or equal to the length of value.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// <exception cref="System.ArgumentException">The combination of startIndex and length does not specify a position within value; that is, the startIndex parameter is greater than the length of value minus the length parameter.</exception> /// startIndex or length is less than zero. -or- startIndex is greater
/// than zero and is greater than or equal to the length of value.
/// </exception>
/// <exception cref="System.ArgumentException">
/// The combination of startIndex and length does not specify a position within
/// value; that is, the startIndex parameter is greater than the length of value minus the length parameter.
/// </exception>
public static string ToString(byte[] value, int startIndex, int length) public static string ToString(byte[] value, int startIndex, int length)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -326,7 +382,10 @@ namespace DiscImageChef
/// <returns>A 16-bit unsigned integer formed by two bytes beginning at startIndex.</returns> /// <returns>A 16-bit unsigned integer formed by two bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex equals the length of value minus 1.</exception> /// <exception cref="System.ArgumentException">startIndex equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// startIndex is less than zero or greater than the length of value
/// minus 1.
/// </exception>
public static ushort ToUInt16(byte[] value, int startIndex) public static ushort ToUInt16(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -340,9 +399,15 @@ namespace DiscImageChef
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A 32-bit unsigned integer formed by four bytes beginning at startIndex.</returns> /// <returns>A 32-bit unsigned integer formed by four bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception> /// <exception cref="System.ArgumentException">
/// startIndex is greater than or equal to the length of value minus 3, and is
/// less than or equal to the length of value minus 1.
/// </exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// startIndex is less than zero or greater than the length of value
/// minus 1.
/// </exception>
public static uint ToUInt32(byte[] value, int startIndex) public static uint ToUInt32(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -356,9 +421,15 @@ namespace DiscImageChef
/// <param name="value">An array of bytes.</param> /// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param> /// <param name="startIndex">The starting position within value.</param>
/// <returns>A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.</returns> /// <returns>A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception> /// <exception cref="System.ArgumentException">
/// startIndex is greater than or equal to the length of value minus 7, and is
/// less than or equal to the length of value minus 1.
/// </exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception> /// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception> /// <exception cref="System.ArgumentOutOfRangeException">
/// startIndex is less than zero or greater than the length of value
/// minus 1.
/// </exception>
public static ulong ToUInt64(byte[] value, int startIndex) public static ulong ToUInt64(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian

View File

@@ -183,7 +183,8 @@ namespace DiscImageChef
twocharvalue[1] = vdDateTime[15]; twocharvalue[1] = vdDateTime[15];
DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"",
StringHandlers.CToString(twocharvalue, Encoding.ASCII)); StringHandlers.CToString(twocharvalue, Encoding.ASCII));
if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) hundredths = 0; if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths))
hundredths = 0;
DicConsole.DebugWriteLine("ISO9600ToDateTime handler", DicConsole.DebugWriteLine("ISO9600ToDateTime handler",
"decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);",

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="byte"/> /// Implements extents for <see cref="byte" />
/// </summary> /// </summary>
public class ExtentsByte public class ExtentsByte
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(byte start, byte end, bool run = false) public void Add(byte start, byte end, bool run = false)
{ {
byte realEnd; byte realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<byte, byte>[] ToArray() public Tuple<byte, byte>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,8 @@ namespace Extents
public bool GetStart(byte item, out byte start) public bool GetStart(byte item, out byte start)
{ {
start = 0; start = 0;
foreach(Tuple<byte, byte> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<byte, byte> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="int"/> /// Implements extents for <see cref="int" />
/// </summary> /// </summary>
public class ExtentsInt public class ExtentsInt
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(int start, int end, bool run = false) public void Add(int start, int end, bool run = false)
{ {
int realEnd; int realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<int, int>[] ToArray() public Tuple<int, int>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,8 @@ namespace Extents
public bool GetStart(int item, out int start) public bool GetStart(int item, out int start)
{ {
start = 0; start = 0;
foreach(Tuple<int, int> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<int, int> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="long"/> /// Implements extents for <see cref="long" />
/// </summary> /// </summary>
public class ExtentsLong public class ExtentsLong
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(long start, long end, bool run = false) public void Add(long start, long end, bool run = false)
{ {
long realEnd; long realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<long, long>[] ToArray() public Tuple<long, long>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,8 @@ namespace Extents
public bool GetStart(long item, out long start) public bool GetStart(long item, out long start)
{ {
start = 0; start = 0;
foreach(Tuple<long, long> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<long, long> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="sbyte"/> /// Implements extents for <see cref="sbyte" />
/// </summary> /// </summary>
public class ExtentsSByte public class ExtentsSByte
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(sbyte start, sbyte end, bool run = false) public void Add(sbyte start, sbyte end, bool run = false)
{ {
sbyte realEnd; sbyte realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<sbyte, sbyte>[] ToArray() public Tuple<sbyte, sbyte>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,8 @@ namespace Extents
public bool GetStart(sbyte item, out sbyte start) public bool GetStart(sbyte item, out sbyte start)
{ {
start = 0; start = 0;
foreach(Tuple<sbyte, sbyte> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<sbyte, sbyte> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="short"/> /// Implements extents for <see cref="short" />
/// </summary> /// </summary>
public class ExtentsShort public class ExtentsShort
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(short start, short end, bool run = false) public void Add(short start, short end, bool run = false)
{ {
short realEnd; short realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<short, short>[] ToArray() public Tuple<short, short>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,8 @@ namespace Extents
public bool GetStart(short item, out short start) public bool GetStart(short item, out short start)
{ {
start = 0; start = 0;
foreach(Tuple<short, short> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<short, short> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="uint"/> /// Implements extents for <see cref="uint" />
/// </summary> /// </summary>
public class ExtentsUInt public class ExtentsUInt
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(uint start, uint end, bool run = false) public void Add(uint start, uint end, bool run = false)
{ {
uint realEnd; uint realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<uint, uint>[] ToArray() public Tuple<uint, uint>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,8 @@ namespace Extents
public bool GetStart(uint item, out uint start) public bool GetStart(uint item, out uint start)
{ {
start = 0; start = 0;
foreach(Tuple<uint, uint> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<uint, uint> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="ulong"/> /// Implements extents for <see cref="ulong" />
/// </summary> /// </summary>
public class ExtentsULong public class ExtentsULong
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(ulong start, ulong end, bool run = false) public void Add(ulong start, ulong end, bool run = false)
{ {
ulong realEnd; ulong realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<ulong, ulong>[] ToArray() public Tuple<ulong, ulong>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,8 @@ namespace Extents
public bool GetStart(ulong item, out ulong start) public bool GetStart(ulong item, out ulong start)
{ {
start = 0; start = 0;
foreach(Tuple<ulong, ulong> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<ulong, ulong> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -37,7 +37,7 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary> /// <summary>
/// Implements extents for <see cref="ushort"/> /// Implements extents for <see cref="ushort" />
/// </summary> /// </summary>
public class ExtentsUShort public class ExtentsUShort
{ {
@@ -126,8 +126,11 @@ namespace Extents
/// Adds a new extent /// Adds a new extent
/// </summary> /// </summary>
/// <param name="start">First element of the extent</param> /// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param> /// <param name="end">
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param> /// Last element of the extent or if <see cref="run" /> is <c>true</c> how many elements the extent runs
/// for
/// </param>
/// <param name="run">If set to <c>true</c>, <see cref="end" /> indicates how many elements the extent runs for</param>
public void Add(ushort start, ushort end, bool run = false) public void Add(ushort start, ushort end, bool run = false)
{ {
ushort realEnd; ushort realEnd;
@@ -215,9 +218,10 @@ namespace Extents
} }
/// <summary> /// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element /// Converts the list of extents to an array of <see cref="Tuple" /> where T1 is first element of the extent and T2 is
/// last element
/// </summary> /// </summary>
/// <returns>Array of <see cref="Tuple"/></returns> /// <returns>Array of <see cref="Tuple" /></returns>
public Tuple<ushort, ushort>[] ToArray() public Tuple<ushort, ushort>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
@@ -232,7 +236,9 @@ namespace Extents
public bool GetStart(ushort item, out ushort start) public bool GetStart(ushort item, out ushort start)
{ {
start = 0; start = 0;
foreach(Tuple<ushort, ushort> extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { foreach(Tuple<ushort, ushort> extent in
backend.Where(extent => item >= extent.Item1 && item <= extent.Item2))
{
start = extent.Item1; start = extent.Item1;
return true; return true;
} }

View File

@@ -118,12 +118,12 @@ namespace DiscImageChef
public static ushort Swap(ushort x) public static ushort Swap(ushort x)
{ {
return (ushort) ((x << 8) | (x >> 8)); return (ushort)((x << 8) | (x >> 8));
} }
public static short Swap(short x) public static short Swap(short x)
{ {
return (short) ((x << 8) | ((x >> 8) & 0xFF)); return (short)((x << 8) | ((x >> 8) & 0xFF));
} }
public static uint Swap(uint x) public static uint Swap(uint x)
@@ -134,8 +134,8 @@ namespace DiscImageChef
public static int Swap(int x) public static int Swap(int x)
{ {
x = (int) (((x << 8) & 0xFF00FF00) | (((uint) x >> 8) & 0xFF00FF)); x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF));
return (int) (((uint) x << 16) | (((uint) x >> 16) & 0xFFFF)); return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF));
} }
} }
} }