Skip to content

Commit

Permalink
Fix items discovered via SonarCloud (tspence#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
tspence committed Jul 10, 2023
1 parent 53765ac commit 55833f5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![NuGet](https://img.shields.io/nuget/v/CSVFile.svg?style=plastic)](https://www.nuget.org/packages/CSVFile/)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/tspence/csharp-csv-reader/dotnet.yml?branch=main)
[![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=tspence_csharp-csv-reader&metric=coverage)](https://sonarcloud.io/component_measures/metric/coverage/list?id=tspence_csharp-csv-reader)
[![SonarCloud Bugs](https://sonarcloud.io/api/project_badges/measure?project=tspence_csharp-csv-reader&metric=bugs)](https://sonarcloud.io/component_measures/metric/reliability_rating/list?id=tspence_csharp-csv-reader)
[![SonarCloud Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=tspence_csharp-csv-reader&metric=vulnerabilities)](https://sonarcloud.io/component_measures/metric/security_rating/list?id=tspence_csharp-csv-reader)
[![SonarCloud Coverage](https://sonarcloud.io/api/project_badges/measure?project=tspence_csharp-csv-reader&metric=coverage)](https://sonarcloud.io/component_measures?id=tspence_csharp-csv-reader&metric=coverage&view=list)
[![SonarCloud Bugs](https://sonarcloud.io/api/project_badges/measure?project=tspence_csharp-csv-reader&metric=bugs)](https://sonarcloud.io/project/issues?resolved=false&types=BUG&id=tspence_csharp-csv-reader)
[![SonarCloud Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=tspence_csharp-csv-reader&metric=vulnerabilities)](https://sonarcloud.io/project/issues?resolved=false&types=VULNERABILITY&id=tspence_csharp-csv-reader)

# CSVFile
This library is a series of unit tested, thoroughly commented CSV parsing functions which I have developed off and on since 2006. Extremely small and easy to implement; includes unit tests for the majority of odd CSV edge cases. Library supports different delimiters, qualifiers, and embedded newlines. Can read and write from data tables.
Expand Down
26 changes: 1 addition & 25 deletions src/CSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,30 +320,6 @@ public static void AppendCSVLine<T>(this StringBuilder sb, T obj, CSVSettings se
sb.Append(line);
}

/// <summary>
/// Append an array of objects to a StringBuilder in CSV format
/// </summary>
/// <param name="sb">The StringBuilder to append</param>
/// <param name="row">The list of objects to append</param>
/// <param name="settings">The CSV settings to use when exporting this array (Default: CSV)</param>
#if NET2_0
private static void AppendCSVRow(StringBuilder sb, IEnumerable<object> row, CSVSettings settings = null)
#else
private static void AppendCSVRow(this StringBuilder sb, IEnumerable<object> row, CSVSettings settings = null)
#endif
{
if (settings == null)
{
settings = CSVSettings.CSV;
}

var riskyChars = settings.GetRiskyChars();
var forceQualifierTypes = settings.GetForceQualifierTypes();
var csv = ItemsToCsv(row, settings, riskyChars, forceQualifierTypes);
sb.Append(csv);
sb.Append(settings.LineSeparator);
}

/// <summary>
/// Internal method to convert a list of things into a CSV line using the specified settings object
///
Expand Down Expand Up @@ -394,7 +370,7 @@ internal static string ItemsToCsv(IEnumerable<object> items, CSVSettings setting
// Only go character-by-character if necessary
if (s.IndexOf(settings.TextQualifier) >= 0)
{
foreach (var c in s.ToCharArray())
foreach (var c in s)
{
// Double up text qualifiers
if (c == settings.TextQualifier)
Expand Down
2 changes: 1 addition & 1 deletion src/CSVSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public char[] GetRiskyChars()
var riskyChars = new List<char>();
riskyChars.Add(FieldDelimiter);
riskyChars.Add(TextQualifier);
foreach (var c in LineSeparator.ToCharArray())
foreach (var c in LineSeparator)
{
riskyChars.Add(c);
}
Expand Down

0 comments on commit 55833f5

Please sign in to comment.