Language: Add RemoveInvalidCharacters function

This commit is contained in:
Jonathan Jenne
2021-07-08 13:48:36 +02:00
parent 6709827740
commit 51b23a8ebe
3 changed files with 42 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@@ -74,6 +74,7 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="InvalidChars.vb" />
<Compile Include="Utils.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">

View File

@@ -1,5 +1,6 @@
Imports System.Drawing
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
''' <summary>
''' Provides common utility functions that do not require a specific context.
@@ -105,6 +106,38 @@ Public Class Utils
Return oBuilder.ToString()
End Function
''' <summary>
''' Removes Invalid characters from a string, suitable for file and path names
'''
''' Removed characters are:
'''
''' * Illegal File-characters
''' * Illegal Path-characters
''' * Unicode characters that classify as Emoji
''' * All characters above codepoint U+10000
''' </summary>
''' <returns></returns>
Public Shared Function RemoveInvalidCharacters(pString As String) As String
Dim oResult = pString
' Remove all Unicode above Codepoint U+10000
oResult = Regex.Replace(oResult, InvalidChars.UnicodeSurrogates, String.Empty)
' Remove all Emojis (Version 13)
oResult = Regex.Replace(oResult, InvalidChars.Emojis, String.Empty)
' Remove Invalid filename characters
oResult = Regex.Replace(oResult, InvalidChars.Filenames, String.Empty)
' Remove Invalid filename characters
oResult = Regex.Replace(oResult, InvalidChars.Paths, String.Empty)
' Remove excess space chars
oResult = oResult.Trim()
Return oResult
End Function
''' <summary>
''' Checks if a point is Visible on any screen
''' </summary>