Skip to content

Commit

Permalink
update of packages
Browse files Browse the repository at this point in the history
  • Loading branch information
RNoeldner committed Jun 13, 2024
1 parent 58746b7 commit 3875e96
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 67 deletions.
44 changes: 10 additions & 34 deletions Library/ClassLibraryCSV/ClassLibraryCsvExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public delegate DateTime TimeZoneChangeDelegate(in DateTime input, in string src
public static class ClassLibraryCsvExtensionMethods
{
// RegEx to get placeholders in brackets {} or {{ }}
private static readonly Regex m_BracesRegEx = new Regex(@"\{{1,2}[^\}]+\}{1,2}");
private static readonly Regex BracesRegEx = new Regex(@"\{{1,2}[^\}]+\}{1,2}");

/// <summary>
/// Move the field from on position in the list to another
Expand All @@ -66,14 +66,14 @@ public static void Move<T>(this IList<T> list, int oldIndex, int newIndex) where
}

/// <summary>
/// Generate a hash for a case insensitive text
/// Generate a hash for a case-insensitive text
/// </summary>
/// <param name="name">The identifier to base the hash on.</param>
public static int IdentifierHash(this string name)
=> name.ToUpperInvariant().GetHashCode();

/// <summary>
/// Generate a hash for two texts both case insensitive
/// Generate a hash for two texts both case-insensitive
/// </summary>
public static int IdentifierHash(this string name, in string name2)
=> name.ToUpperInvariant().GetHashCode() + name2.ToUpperInvariant().GetHashCode();
Expand Down Expand Up @@ -116,7 +116,7 @@ public static bool AssumePgp(this string fileName) =>
/// <returns></returns>
public static bool AssumeZip(this string fileName) => fileName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase);

/// <summary>Assumes its a delimited file, based on extension</summary>
/// <summary>Assumes it's a delimited file, based on extension</summary>
/// <param name="fileName">Name of the file.</param>
/// <returns>
/// <br />
Expand Down Expand Up @@ -334,7 +334,7 @@ public static string GetIdFromFileName(this string path)

/// <summary>
/// Gets the .NET type for a given CsvTools type Always using long for integer values no
/// matter if 32 or 64 bit system
/// matter if 32 or 64-bit system
/// </summary>
/// <param name="dt">The <see cref="DataTypeEnum" />.</param>
/// <returns>The .NET Type</returns>
Expand All @@ -354,7 +354,7 @@ public static Type GetNetType(this DataTypeEnum dt) =>
/// Get a list of column names that are not artificial
/// </summary>
/// <param name="dataTable">The <see cref="DataTable" /> containing the columns</param>
/// <returns>A enumeration of ColumnNames</returns>
/// <returns>An enumeration of ColumnNames</returns>
public static IEnumerable<DataColumn> GetRealColumns(this DataTable dataTable) =>
dataTable.Columns.Cast<DataColumn>().Where(col => NoArtificialField(col.ColumnName));

Expand Down Expand Up @@ -423,7 +423,7 @@ public static string NewLineString(this RecordDelimiterTypeEnum type) =>

#endif
/// <summary>
/// Replaces placeholders with a text. The placeholder are identified surrounding { or [
/// Replaces placeholders with a text. The placeholder is identified surrounding { or [
/// </summary>
/// <param name="input">The input.</param>
/// <param name="placeholder">The placeholder.</param>
Expand Down Expand Up @@ -649,30 +649,6 @@ public static string ReplaceDefaults(this string inputValue, in char old1, in ch
return new string(result, 0, pos);
}

//public static void ReplaceDefaults(this Span<char> inputValue, in char old1, in char new1, in char old2, in char new2)
//{
// if (inputValue.IsEmpty)
// return;

// // Assume the text stays the same, it could only be shorter

// int pos = 0;
// // ReSharper disable once ForCanBeConvertedToForeach
// for (int i = 0; i < inputValue.Length; i++)
// {
// if (inputValue[i] == old1)
// {
// if (new1 != char.MinValue)
// inputValue[pos++]=new1;
// }
// else if (inputValue[i] == old2)
// {
// if (new2 != char.MinValue)
// inputValue[pos++]=new2;
// }
// }
//}

/// <summary>
/// Replaces the two string
/// </summary>
Expand Down Expand Up @@ -725,7 +701,7 @@ public static string ReplacePlaceholderWithPropertyValues(this string template,
var props = obj.GetType().GetProperties().Where(prop => prop.GetMethod != null).ToList();

// ReSharper disable once RedundantEnumerableCastCall
foreach (var value in m_BracesRegEx.Matches(template).OfType<Match>().Select(x => x.Value))
foreach (var value in BracesRegEx.Matches(template).OfType<Match>().Select(x => x.Value))
{
if (string.IsNullOrEmpty(value) || placeholder.ContainsKey(value) || value.Length < 2)
continue;
Expand Down Expand Up @@ -764,7 +740,7 @@ public static string ReplacePlaceholderWithText(this string template, params str
var placeholder = new Dictionary<string, string>();
var index = 0;
// ReSharper disable once RedundantEnumerableCastCall
foreach (var value in m_BracesRegEx.Matches(template).OfType<Match>().Select(x => x.Value))
foreach (var value in BracesRegEx.Matches(template).OfType<Match>().Select(x => x.Value))
{
if (index >= values.Length)
break;
Expand Down Expand Up @@ -797,7 +773,7 @@ public static void SetMaximum(this IProgress<ProgressInfo>? progress, long maxim
}

/// <summary>
/// Get the inner most exception message
/// Get the innermost exception message
/// </summary>
/// <param name="exception">Any exception <see cref="Exception" /></param>
[DebuggerStepThrough]
Expand Down
6 changes: 3 additions & 3 deletions Library/ClassLibraryCSV/Detection/InspectionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace CsvTools
public sealed class InspectionResult
{
/// <summary>Number of rows to skip</summary>
[DefaultValue(0)] public int SkipRows = 0;
[DefaultValue(0)] public int SkipRows;
/// <summary>.NET CodePage ID</summary>
[DefaultValue(65001)] public int CodePageId = 65001;
/// <summary>Does encoding use BOM</summary>
[DefaultValue(false)] public bool ByteOrderMark = false;
[DefaultValue(false)] public bool ByteOrderMark;
/// <summary>Identifier in container like zip</summary>
[DefaultValue("")] public string IdentifierInContainer = string.Empty;
/// <summary>Prefix for lines to be ignored</summary>
Expand All @@ -39,7 +39,7 @@ public sealed class InspectionResult
/// <summary>Qualifier of a columns to allow linefeed or delimiter</summary>
[DefaultValue('"')] public char FieldQualifier = '"';
/// <summary>Context-sensitive quoting looks at eh surrounding area to determine if this is really a quote</summary>
[DefaultValue(false)] public bool ContextSensitiveQualifier = false;
[DefaultValue(false)] public bool ContextSensitiveQualifier;
/// <summary>In case a quote is part of a quoted column, the quote should be repeated</summary>
[DefaultValue(true)] public bool DuplicateQualifierToEscape = true;
/// <summary>Does the file have a header row</summary>
Expand Down
2 changes: 1 addition & 1 deletion Library/ClassLibraryCSV/Exceptions/ConversionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace CsvTools
{
/// <summary>
/// Raised if the a conversion of types of or timezone conversion has issues
/// Raised if the conversion of types of or timezone conversion has issues
/// </summary>
/// <seealso cref="System.ApplicationException" />
public sealed class ConversionException : ApplicationException
Expand Down
2 changes: 1 addition & 1 deletion Library/ClassLibraryCSV/FileWriter/CsvFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public override async Task WriteReaderAsync(IFileReader reader, Stream output, C
/// <param name="handleWarning">Action to perform if text is cut off for fixed length</param>
/// <returns></returns>
/// <exception cref="FileWriterException"></exception>
public string HandleText(string text, int fieldLength, Action<string>? handleWarning = null)
private string HandleText(string text, int fieldLength, Action<string>? handleWarning = null)
{
if (m_IsFixedLength && fieldLength == 0)
throw new FileWriterException("For fix length output the length of the columns needs to be specified.");
Expand Down
2 changes: 1 addition & 1 deletion Library/ClassLibraryCSV/FileWriter/StructuredFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public override async Task WriteReaderAsync(IFileReader reader, Stream output, C
// Static template for the row, built once
var sb = new StringBuilder(2048);

await WriteReaderAsync(reader, async row =>
await WriteReaderAsync(reader, async _ =>
{
if (Records > 1)
sb.Append(RecordDelimiter());
Expand Down
59 changes: 58 additions & 1 deletion Library/ClassLibraryCSV/Immutable/ManifestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@
namespace CsvTools
{
/// <summary>
/// Manifest data describing Json data
/// Information describing an entity in Json data
/// </summary>
public sealed class ManifestData
{
internal const string cCsvManifestExtension = ".manifest.json";

/// <summary>
/// Manifest for Json files
/// </summary>
/// <param name="pubName">Public Name</param>
/// <param name="heading">Long Name</param>
/// <param name="desc">Description</param>
/// <param name="delta">Does support delta</param>
/// <param name="hydration">Hydration</param>
/// <param name="hasUserDefinedFields"></param>
/// <param name="fields">Fields</param>
[JsonConstructor]
public ManifestData(
string? pubName,
Expand All @@ -49,18 +59,39 @@ public ManifestData(
Delta = delta;
}

/// <summary>
/// <c>true</c> if the entity does support delta
/// </summary>
public bool Delta { get; }

/// <summary>
/// Description for entity
/// </summary>
public string Desc { get; }

/// <summary>
/// Fields
/// </summary>
public ManifestField[] Fields { get; }

/// <summary>
/// Has CustomFields
/// </summary>
public bool HasUserDefinedFields { get; }

/// <summary>
/// Heading
/// </summary>
public string Heading { get; }

/// <summary>
/// Hydration
/// </summary>
public string Hydration { get; }

/// <summary>
/// Public Name
/// </summary>
public string PubName { get; }

/// <summary>
Expand Down Expand Up @@ -186,8 +217,19 @@ private static async Task<InspectionResult> ReadManifestFromStream(
return detectionResult;
}

/// <summary>
/// Field in a Manifest Json
/// </summary>
public class ManifestField
{
/// <summary>
///
/// </summary>
/// <param name="pubName">Public Name</param>
/// <param name="heading">Long Name</param>
/// <param name="desc">Description</param>
/// <param name="type">Data Type</param>
/// <param name="ordinal">Ordinal number</param>
[JsonConstructor]
public ManifestField(string? pubName, string? heading, string? desc, string? type, int ordinal)
{
Expand All @@ -198,14 +240,29 @@ public ManifestField(string? pubName, string? heading, string? desc, string? typ
Type = type ?? string.Empty;
}

/// <summary>
/// Description for field
/// </summary>
public string Desc { get; }

/// <summary>
/// Long Name
/// </summary>
public string Heading { get; }

/// <summary>
/// Ordinal number of the field
/// </summary>
public int Ordinal { get; }

/// <summary>
/// Public Name
/// </summary>
public string PubName { get; }

/// <summary>
/// Data Type
/// </summary>
public string Type { get; }
}
}
Expand Down
14 changes: 7 additions & 7 deletions Library/ClassLibraryCSV/StringConversionSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static class StringConversionSpan
/// <param name="trueValue">An additional value that would evaluate to true</param>
/// <param name="falseValue">An additional value that would evaluate to false</param>
/// <returns>
/// <c>Null</c> if the value is empty, other wise <c>true</c> if identified as boolean or
/// <c>Null</c> if the value is empty, otherwise <c>true</c> if identified as boolean or
/// <c>false</c> otherwise
/// </returns>
[SuppressMessage("ReSharper", "LoopCanBeConvertedToQuery")]
Expand Down Expand Up @@ -256,7 +256,7 @@ public static class StringConversionSpan
/// <param name="trueValue">An additional value that would evaluate to true</param>
/// <param name="falseValue">An additional value that would evaluate to false</param>
/// <returns>
/// <c>Null</c> if the value can not be identified as boolean, other wise a tuple with
/// <c>Null</c> if the value can not be identified as boolean, otherwise a tuple with
/// <c>true</c> or <c>false</c> and the value that had been used
/// </returns>
[SuppressMessage("ReSharper", "LoopCanBeConvertedToQuery")]
Expand Down Expand Up @@ -300,7 +300,7 @@ public static (bool?, string value) StringToBooleanWithMatch(
/// <returns>
/// An <see cref="DateTime" /> if the value could be interpreted, <c>null</c> otherwise
/// </returns>
/// <remarks>If the date part is not filled its the 1/1/1</remarks>
/// <remarks>If the date part is not filled it's the 1/1/1</remarks>
public static DateTime? StringToDateTime(
this ReadOnlySpan<char> text,
ReadOnlySpan<char> dateFormats,
Expand All @@ -320,7 +320,7 @@ public static (bool?, string value) StringToBooleanWithMatch(
&& (stringDateValue.IndexOf(timeSeparatorChar) == -1))
return SerialStringToDateTime(stringDateValue);

// in case its time only and we do not have any date separator try a timespan
// in case its time only, and we do not have any date separator try a timespan
if (stringDateValue.IndexOf(dateSeparatorChar) != -1 || dateFormats.IndexOf('/') != -1) return null;
var ts = StringToTimeSpan(stringDateValue, timeSeparatorChar, false);
if (ts.HasValue)
Expand Down Expand Up @@ -410,7 +410,7 @@ public static (bool?, string value) StringToBooleanWithMatch(
/// <param name="groupSeparatorChar">The thousand separator. Do not pass in written punctuation</param>
/// <param name="allowPercentage">If set to true, a % or ‰ will be recognized</param>
/// <param name="currencyRemoval">A list of currency symbols to remove before parsing</param>
/// <returns>An decimal if the value could be interpreted, <c>null</c> otherwise</returns>
/// <returns>A decimal if the value could be interpreted, <c>null</c> otherwise</returns>
public static decimal? StringToDecimal(
this ReadOnlySpan<char> text,
char decimalSeparatorChar,
Expand All @@ -435,7 +435,7 @@ public static (bool?, string value) StringToBooleanWithMatch(
var startDecimal = text.Length;
var lastPos = -3;
// Sanity Check: In case the decimalSeparator occurs multiple times is not a number in case
// the thousand separator are closer then 3 characters together
// the thousand separator are closer than 3 characters together
for (var pos = 0; pos < text.Length; pos++)
{
if (text[pos] == decimalSeparatorChar)
Expand Down Expand Up @@ -765,7 +765,7 @@ private static int IndexOf(

// Use ParseExact since Parse does not work if a date separator is set but the date
// separator is not part of the date format
// Still this does not work properly the separator is often not enforced, assuming if "-" is set and the date contains a "." its still parsed
// Still this does not work properly the separator is often not enforced, assuming if "-" is set and the date contains a "." It's still parsed
if (DateTime.TryParseExact(
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
stringDateValue
Expand Down
4 changes: 2 additions & 2 deletions Library/ClassLibraryCSV/StringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ public static string SqlQuote(this string? contents) =>
/// <returns></returns>
public static string StringEscapeLike(this string? inputValue)
{
if (string.IsNullOrEmpty(inputValue))
if (inputValue == null || inputValue.Length==0)
return string.Empty;
var returnVal = new StringBuilder(inputValue!.Length);
var returnVal = new StringBuilder(inputValue.Length);
foreach (var c in inputValue)
{
switch (c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Compile Include="..\UnitTestBasic\UnitTestStaticForms.cs" Link="UnitTestStaticForms.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MSTest" Version="3.3.1" />
<PackageReference Include="MSTest" Version="3.4.3" />
<ProjectReference Include="..\..\Application\CSVQuickViewer.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest" Version="3.3.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest" Version="3.4.3" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<ProjectReference Include="..\..\Library\ClassLibraryCSV\CsvTools.ClassLibraryCSV.csproj" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 3875e96

Please sign in to comment.