Repository: microsoft/PowerToys
File: src/modules/AdvancedPaste/AdvancedPaste/Helpers/JsonHelper.cs (C#)

Code before:
            catch (Exception ex)
            {
                Logger.LogError("Failed parsing input as ini", ex);
            }

            // Try convert CSV
            try
            {
                if (string.IsNullOrEmpty(jsonText))
                {
                    var csv = new List<string[]>();

                    string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                    // Detect the csv delimiter and the count of occurrence based on the first two csv lines.
                    GetCsvDelimiter(lines, out char delim, out int delimCount);

                    foreach (var line in lines)
                    {
                        // If line is separator property line, then skip it
                        if (CsvSepIdentifierRegex.IsMatch(line))
                        {
                            continue;
                        }

                        // A CSV line is valid, if the delimiter occurs more or equal times in every line compared to the first data line. (More because sometimes the delimiter occurs in a data string.)
                        if (Regex.Count(line, delim + CsvDelimSepRegexStr) == delimCount && int.IsEvenInteger(Regex.Count(line, delim + CsvDelimSepRegexStr)))
                        {
                            csv.Add(Regex.Split(line, delim + CsvDelimSepRegexStr, RegexOptions.IgnoreCase));
                        }
                        else
                        {
                            throw new FormatException("Invalid CSV format: Number of delimiters wrong in the current line.");
                        }
                    }

                    Logger.LogDebug("Convert from csv.");
                    jsonText = JsonConvert.SerializeObject(csv, Newtonsoft.Json.Formatting.Indented);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Failed parsing input as csv", ex);
            }

            // Try convert Plain Text
            try
            {
                if (string.IsNullOrEmpty(jsonText))
                {
                    var plainText = new List<string>();

Review comment (suggestion):
```suggestion
                        // A CSV line is valid, if the delimiter occurs equal times in every line compared to the first data line
                        // and if every line contains no or an even count of quotation marks.
```


Code after:
            catch (Exception ex)
            {
                Logger.LogError("Failed parsing input as ini", ex);
            }

            // Try convert CSV
            try
            {
                if (string.IsNullOrEmpty(jsonText))
                {
                    var csv = new List<string[]>();

                    string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                    // Detect the csv delimiter and the count of occurrence based on the first two csv lines.
                    GetCsvDelimiter(lines, out char delim, out int delimCount);

                    foreach (var line in lines)
                    {
                        // If line is separator property line, then skip it
                        if (CsvSepIdentifierRegex.IsMatch(line))
                        {
                            continue;
                        }

                        // A CSV line is valid, if the delimiter occurs equal times in every line compared to the first data line
                        // and if every line contains no or an even count of quotation marks.
                        if (Regex.Count(line, delim + CsvDelimSepRegexStr) == delimCount && int.IsEvenInteger(line.Count(x => x == '"')))
                        {
                            csv.Add(Regex.Split(line, delim + CsvDelimSepRegexStr, RegexOptions.IgnoreCase));
                        }
                        else
                        {
                            throw new FormatException("Invalid CSV format: Number of delimiters wrong in the current line.");
                        }
                    }

                    Logger.LogDebug("Convert from csv.");
                    jsonText = JsonConvert.SerializeObject(csv, Newtonsoft.Json.Formatting.Indented);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Failed parsing input as csv", ex);
            }

            // Try convert Plain Text
            try
            {
                if (string.IsNullOrEmpty(jsonText))
                {