diff --git a/DateHandlers.cs b/DateHandlers.cs index aef3d49..28fd153 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -38,49 +38,49 @@ namespace Aaru.Helpers { public static class DateHandlers { - static readonly DateTime LisaEpoch = new DateTime(1901, 1, 1, 0, 0, 0); - static readonly DateTime MacEpoch = new DateTime(1904, 1, 1, 0, 0, 0); - static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); + static readonly DateTime _lisaEpoch = new DateTime(1901, 1, 1, 0, 0, 0); + static readonly DateTime _macEpoch = new DateTime(1904, 1, 1, 0, 0, 0); + static readonly DateTime _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); /// Day 0 of Julian Date system - static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); - static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); + static readonly DateTime _julianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); + static readonly DateTime _amigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); /// Converts a Macintosh timestamp to a .NET DateTime /// Macintosh timestamp (seconds since 1st Jan. 1904) /// .NET DateTime - public static DateTime MacToDateTime(ulong macTimeStamp) => MacEpoch.AddTicks((long)(macTimeStamp * 10000000)); + public static DateTime MacToDateTime(ulong macTimeStamp) => _macEpoch.AddTicks((long)(macTimeStamp * 10000000)); /// Converts a Lisa timestamp to a .NET DateTime /// Lisa timestamp (seconds since 1st Jan. 1901) /// .NET DateTime - public static DateTime LisaToDateTime(uint lisaTimeStamp) => LisaEpoch.AddSeconds(lisaTimeStamp); + public static DateTime LisaToDateTime(uint lisaTimeStamp) => _lisaEpoch.AddSeconds(lisaTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixToDateTime(int unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixToDateTime(int unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixToDateTime(long unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixToDateTime(long unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// Seconds since 1st Jan. 1970) /// Nanoseconds /// .NET DateTime public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => - UnixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); + _unixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a High Sierra Format timestamp to a .NET DateTime /// High Sierra Format timestamp @@ -188,7 +188,7 @@ namespace Aaru.Helpers { double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail - return JulianEpoch.AddMilliseconds(delta); + return _julianEpoch.AddMilliseconds(delta); } /// Converts an Amiga timestamp to a .NET DateTime @@ -198,7 +198,7 @@ namespace Aaru.Helpers /// .NET DateTime public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) { - DateTime temp = AmigaEpoch.AddDays(days); + DateTime temp = _amigaEpoch.AddDays(days); temp = temp.AddMinutes(minutes); return temp.AddMilliseconds(ticks * 20); @@ -263,7 +263,7 @@ namespace Aaru.Helpers int hours = timestamp[2]; int minutes = timestamp[3]; - DateTime temp = AmigaEpoch.AddDays(days); + DateTime temp = _amigaEpoch.AddDays(days); temp = temp.AddHours(hours); temp = temp.AddMinutes(minutes); @@ -316,7 +316,8 @@ namespace Aaru.Helpers /// Convers a Solaris high resolution timestamp to .NET DateTime /// Solaris high resolution timestamp /// .NET DateTime - public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => UnixEpoch.AddTicks((long)(hrTimeStamp / 100)); + public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => + _unixEpoch.AddTicks((long)(hrTimeStamp / 100)); /// Converts an OS-9 timestamp to .NET DateTime /// OS-9 timestamp diff --git a/StringHandlers.cs b/StringHandlers.cs index 798ca63..d2128cd 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -39,29 +39,29 @@ namespace Aaru.Helpers { /// Converts a null-terminated (aka C string) ASCII byte array to a C# string /// The corresponding C# string - /// A null-terminated (aka C string) ASCII byte array - public static string CToString(byte[] CString) => CToString(CString, Encoding.ASCII); + /// A null-terminated (aka C string) ASCII byte array + public static string CToString(byte[] cString) => CToString(cString, Encoding.ASCII); /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string /// The corresponding C# string - /// A null-terminated (aka C string) byte array in the specified encoding + /// A null-terminated (aka C string) byte array in the specified encoding /// Encoding. /// Set if encoding uses 16-bit characters. /// Start decodint at this position - public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false, int start = 0) + public static string CToString(byte[] cString, Encoding encoding, bool twoBytes = false, int start = 0) { - if(CString == null) + if(cString == null) return null; int len = 0; - for(int i = start; i < CString.Length; i++) + for(int i = start; i < cString.Length; i++) { - if(CString[i] == 0) + if(cString[i] == 0) if(twoBytes) { - if(i + 1 < CString.Length && - CString[i + 1] == 0) + if(i + 1 < cString.Length && + cString[i + 1] == 0) { len++; @@ -78,67 +78,67 @@ namespace Aaru.Helpers len--; byte[] dest = new byte[len]; - Array.Copy(CString, start, dest, 0, len); + Array.Copy(cString, start, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); } /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// The corresponding C# string - /// A length-prefixed (aka Pascal string) ASCII byte array - public static string PascalToString(byte[] PascalString) => PascalToString(PascalString, Encoding.ASCII); + /// A length-prefixed (aka Pascal string) ASCII byte array + public static string PascalToString(byte[] pascalString) => PascalToString(pascalString, Encoding.ASCII); /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// The corresponding C# string - /// A length-prefixed (aka Pascal string) ASCII byte array + /// A length-prefixed (aka Pascal string) ASCII byte array /// Encoding. /// Start decodint at this position - public static string PascalToString(byte[] PascalString, Encoding encoding, int start = 0) + public static string PascalToString(byte[] pascalString, Encoding encoding, int start = 0) { - if(PascalString == null) + if(pascalString == null) return null; - byte length = PascalString[start]; + byte length = pascalString[start]; int len = 0; - for(int i = start + 1; i < length + 1 && i < PascalString.Length; i++) + for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++) { - if(PascalString[i] == 0) + if(pascalString[i] == 0) break; len++; } byte[] dest = new byte[len]; - Array.Copy(PascalString, start + 1, dest, 0, len); + Array.Copy(pascalString, start + 1, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); } /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// The corresponding C# string - /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array - public static string SpacePaddedToString(byte[] SpacePaddedString) => - SpacePaddedToString(SpacePaddedString, Encoding.ASCII); + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + public static string SpacePaddedToString(byte[] spacePaddedString) => + SpacePaddedToString(spacePaddedString, Encoding.ASCII); /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// The corresponding C# string - /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array /// Encoding. /// Start decodint at this position - public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding, int start = 0) + public static string SpacePaddedToString(byte[] spacePaddedString, Encoding encoding, int start = 0) { - if(SpacePaddedString == null) + if(spacePaddedString == null) return null; int len = start; - for(int i = SpacePaddedString.Length; i >= start; i--) + for(int i = spacePaddedString.Length; i >= start; i--) { if(i == start) return ""; - if(SpacePaddedString[i - 1] == 0x20) + if(spacePaddedString[i - 1] == 0x20) continue; len = i; @@ -146,7 +146,7 @@ namespace Aaru.Helpers break; } - return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len); + return len == 0 ? "" : encoding.GetString(spacePaddedString, start, len); } /// Converts an OSTA compressed unicode byte array to a C# string