ReplaceRestrictedChars

This commit is contained in:
Timerix22 2023-03-22 14:22:25 +06:00
parent 48eab00a37
commit b86e565077
6 changed files with 31 additions and 26 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<!--package info--> <!--package info-->
<PackageId>DTLib.Dtsod</PackageId> <PackageId>DTLib.Dtsod</PackageId>
<Version>1.1.4</Version> <Version>1.1.5</Version>
<Authors>Timerix</Authors> <Authors>Timerix</Authors>
<Description>Definitely not json</Description> <Description>Definitely not json</Description>
<RepositoryType>GIT</RepositoryType> <RepositoryType>GIT</RepositoryType>
@ -33,7 +33,7 @@
<ProjectReference Include="..\DTLib\DTLib.csproj" /> <ProjectReference Include="..\DTLib\DTLib.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Debug' "> <ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<PackageReference Include="DTLib" Version="1.1.5" /> <PackageReference Include="DTLib" Version="1.1.9" />
</ItemGroup> </ItemGroup>
<!--project files--> <!--project files-->

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<!--package info--> <!--package info-->
<PackageId>DTLib.Logging</PackageId> <PackageId>DTLib.Logging</PackageId>
<Version>1.1.4</Version> <Version>1.1.5</Version>
<Authors>Timerix</Authors> <Authors>Timerix</Authors>
<Description>Loggers with dependency injection</Description> <Description>Loggers with dependency injection</Description>
<RepositoryType>GIT</RepositoryType> <RepositoryType>GIT</RepositoryType>
@ -30,7 +30,7 @@
<ProjectReference Include="..\DTLib.Ben.Demystifier\DTLib.Ben.Demystifier.csproj" /> <ProjectReference Include="..\DTLib.Ben.Demystifier\DTLib.Ben.Demystifier.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Debug' "> <ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<PackageReference Include="DTLib" Version="1.1.5" /> <PackageReference Include="DTLib" Version="1.1.9" />
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" /> <PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<!--package info--> <!--package info-->
<PackageId>DTLib.Network</PackageId> <PackageId>DTLib.Network</PackageId>
<Version>1.1.4</Version> <Version>1.1.5</Version>
<Authors>Timerix</Authors> <Authors>Timerix</Authors>
<Description>Some sick network protocols</Description> <Description>Some sick network protocols</Description>
<RepositoryType>GIT</RepositoryType> <RepositoryType>GIT</RepositoryType>
@ -32,6 +32,6 @@
<ProjectReference Include="..\DTLib.Dtsod\DTLib.Dtsod.csproj" /> <ProjectReference Include="..\DTLib.Dtsod\DTLib.Dtsod.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Debug' "> <ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<PackageReference Include="DTLib.Dtsod" Version="1.1.4" /> <PackageReference Include="DTLib.Dtsod" Version="1.1.5" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -27,10 +27,10 @@
<ProjectReference Include="..\DTLib\DTLib.csproj" /> <ProjectReference Include="..\DTLib\DTLib.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Debug' "> <ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<PackageReference Include="DTLib" Version="1.1.5" /> <PackageReference Include="DTLib" Version="1.1.9" />
<PackageReference Include="DTLib.Dtsod" Version="1.1.4" /> <PackageReference Include="DTLib.Dtsod" Version="1.1.5" />
<PackageReference Include="DTLib.Network" Version="1.1.4" /> <PackageReference Include="DTLib.Network" Version="1.1.5" />
<PackageReference Include="DTLib.Logging" Version="1.1.4" /> <PackageReference Include="DTLib.Logging" Version="1.1.5" />
</ItemGroup> </ItemGroup>
<!--project files--> <!--project files-->

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<!--package info--> <!--package info-->
<PackageId>DTLib</PackageId> <PackageId>DTLib</PackageId>
<Version>1.1.8</Version> <Version>1.1.9</Version>
<Authors>Timerix</Authors> <Authors>Timerix</Authors>
<Description>Library for all my C# projects</Description> <Description>Library for all my C# projects</Description>
<RepositoryType>GIT</RepositoryType> <RepositoryType>GIT</RepositoryType>

View File

@ -19,33 +19,38 @@ public static class Path
throw new Exception($"path <{path}> uses <..>, that's not allowed"); throw new Exception($"path <{path}> uses <..>, that's not allowed");
} }
/// Replaces restricted characters in string /// Replaces characters restricted in filesystem path
public static IOPath ReplaceRestrictedChars(string str) public static IOPath ReplaceRestrictedChars(string str)
{ {
char[] r = str.ToCharArray(); char[] r = str.ToCharArray();
StringBuilder b = new(r.Length);
for (int i = 0; i < str.Length; i++) for (int i = 0; i < str.Length; i++)
{ {
switch (r[i]) char c = r[i];
switch (c)
{ {
case '/': case '\\': case '\n': case '\r':
case ':': case ';': case ':': case ';':
r[i] = '-';
break; break;
case '\n': case '\r': case '\'': case '/': case '\\':
case '"': case '`': b.Append('-');
break; break;
case ' ': case '&': case '{': case '}': case '<': case '>':
case '<': case '>': case '*': case '?': case '?': case '|':
case '$': case '%': case '@': case '|': b.Append('_');
// case '!': break;
// case '#': case '"':
r[i] = '_'; b.Append('\'');
break;
case '*':
b.Append('X');
break;
default:
b.Append(c);
break; break;
} }
} }
return new IOPath(b.ToString(), true);
return new IOPath(r);
} }
#if !USE_SPAN #if !USE_SPAN