< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 72
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 24
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
IndexOfFileName(...)0%10100%
GetFileName(...)0%220%
CombinePathWithRelativePath(...)0%880%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/PathUtilities.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.IO;
 6
 7namespace System.Reflection.Metadata
 8{
 9    internal static class PathUtilities
 10    {
 11        private const char DirectorySeparatorChar = '\\';
 12        private const char AltDirectorySeparatorChar = '/';
 13        private const char VolumeSeparatorChar = ':';
 14
 15        private static string? s_platformSpecificDirectorySeparator;
 16
 17        private static string PlatformSpecificDirectorySeparator =>
 18            // '*' is a valid char on Unix-based FS
 019            s_platformSpecificDirectorySeparator ??=
 020                (Array.IndexOf(Path.GetInvalidFileNameChars(), '*') >= 0 ? DirectorySeparatorChar : AltDirectorySeparato
 21
 22        /// <summary>
 23        /// Returns the position in given path where the file name starts.
 24        /// </summary>
 25        /// <returns>-1 if path is null.</returns>
 26        internal static int IndexOfFileName(string path)
 027        {
 028            if (path == null)
 029            {
 030                return -1;
 31            }
 32
 033            for (int i = path.Length - 1; i >= 0; i--)
 034            {
 035                char ch = path[i];
 036                if (ch == DirectorySeparatorChar || ch == AltDirectorySeparatorChar || ch == VolumeSeparatorChar)
 037                {
 038                    return i + 1;
 39                }
 040            }
 41
 042            return 0;
 043        }
 44
 45        /// <summary>
 46        /// Get file name from path.
 47        /// </summary>
 48        /// <remarks>Unlike <see cref="System.IO.Path.GetFileName(string)"/> this method doesn't check for invalid path 
 49        internal static string GetFileName(string path)
 050        {
 051            int fileNameStart = IndexOfFileName(path);
 052            return (fileNameStart <= 0) ? path : path.Substring(fileNameStart);
 053        }
 54
 55        internal static string CombinePathWithRelativePath(string root, string relativePath)
 056        {
 057            if (root.Length == 0)
 058            {
 059                return relativePath;
 60            }
 61
 062            char c = root[root.Length - 1];
 063            if (c == DirectorySeparatorChar || c == AltDirectorySeparatorChar || c == VolumeSeparatorChar)
 064            {
 065                return root + relativePath;
 66            }
 67
 068            return root + PlatformSpecificDirectorySeparator + relativePath;
 069        }
 70    }
 71}
 72