< Summary

Information
Class: DirectSight.Common.StringExtensions
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Common/StringExtensions.cs
Line coverage
95%
Covered lines: 38
Uncovered lines: 2
Coverable lines: 40
Total lines: 76
Line coverage: 95%
Branch coverage
90%
Covered branches: 20
Total branches: 22
Branch coverage: 90.9%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ParseLargeInteger(...)100%22100%
SplitThatEnsuresGlobsAreSafe(...)90%202093.93%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Common/StringExtensions.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3
 4namespace DirectSight.Common;
 5
 6/// <summary>
 7/// String extensions.
 8/// </summary>
 9public static class StringExtensions
 10{
 11    /// <summary>
 12    /// Parses integers from string.
 13    /// If parsing fails int.MaxValue is returned.
 14    /// </summary>
 15    /// <param name="input">The number as string.</param>
 16    /// <returns>The parsed number.</returns>
 17    public static int ParseLargeInteger(this string input)
 2574718    {
 2574719        if (int.TryParse(input, out int result))
 2574620        {
 2574621            return result;
 22        }
 23        else
 124        {
 125            return int.MaxValue;
 26        }
 2574727    }
 28
 29    /// <summary>
 30    /// Splits the string at the specified separator, but ensures that globs are not split.
 31    /// </summary>
 32    /// <param name="input">The input string.</param>
 33    /// <param name="separators">List of separators.</param>
 34    /// <returns>The parts.</returns>
 35    public static string[] SplitThatEnsuresGlobsAreSafe(this string input, params char[] separators)
 636    {
 637        if (separators == null || separators.Length == 0)
 038        {
 039            return [input];
 40        }
 41
 642        var parts = new List<string>();
 643        var braceCount = 0;
 644        var start = 0;
 45
 58446        for (int i = 0; i < input.Length; i++)
 28647        {
 28648            if (input[i] == '{')
 249            {
 250                braceCount++;
 251            }
 28452            else if (input[i] == '}')
 153            {
 154                braceCount--;
 155            }
 56
 28657            if (braceCount > 0 && input.IndexOf('}', i + 1) == -1)
 158            {
 159                braceCount = 0;
 160            }
 61
 28662            if (separators.Contains(input[i]) && braceCount == 0)
 763            {
 764                parts.Add(input[start..i].Trim());
 765                start = i + 1;
 766            }
 28667        }
 68
 669        if (start < input.Length)
 670        {
 671            parts.Add(input[start..].Trim());
 672        }
 73
 674        return [.. parts];
 675    }
 76}