-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed as not planned
Closed as not planned
Copy link
Labels
api-ready-for-reviewAPI is ready for review, it is NOT ready for implementationAPI is ready for review, it is NOT ready for implementationarea-System.IO
Milestone
Description
Background and motivation
Path.GetInvalidFileNameChars() and Path.GetInvalidPathChars() each make a copy and aren't even very convenient for one of the most common operation you want to do with them: ask if your string contains one.
API Proposal
namespace System.IO;
public partial static class Path
{
public static bool ContainsInvalidPathChar(ReadOnlySpan<char> path);
public static bool ContainsInvalidFileNameChar(ReadOnlySpan<char> fileName);
}API Usage
if (Path.ContainsInvalidPathNameChar(pipeName) || pipeName.EndsWith(Path.DirectorySeparatorChar))
throw new PlatformNotSupportedException(SR.PlatformNotSupported_InvalidPipeNameChars);if (Path.ContainsInvalidFileNameChar(pipeName))
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_InvalidPipeNameChars);
}(Instead of caching in a static and using .AsSpan().ContainsAny(...).)
Alternative Designs
Maybe expose SearchValues. (Could do this in addition to the above proposal.)
namespace System.IO;
public partial static class Path
{
public static SearchValues<char> InvalidPathCharSearchValues { get; }
public static SearchValues<char> InvalidFileNameCharSearchValues { get; }
}Risks
No response
colejohnson66, JakeYallop and inelisoni
Metadata
Metadata
Assignees
Labels
api-ready-for-reviewAPI is ready for review, it is NOT ready for implementationAPI is ready for review, it is NOT ready for implementationarea-System.IO