From 85f15eee468ffe08e258a9ae1ad4b0fc3db906ae Mon Sep 17 00:00:00 2001 From: amorozov Date: Tue, 25 Jun 2024 13:24:58 +0300 Subject: [PATCH] feature: added file path restricted characters replacements --- pkg/io/files/file_name_utils.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/io/files/file_name_utils.go b/pkg/io/files/file_name_utils.go index 068c62f..35bd3df 100644 --- a/pkg/io/files/file_name_utils.go +++ b/pkg/io/files/file_name_utils.go @@ -8,6 +8,18 @@ import ( "git.tswf.io/incredible-go/incredible-go-core/pkg/collections/array_list" ) +var RestrictedFilepathCharactersReplacements = map[string]string{ + "<": "<", + ">": ">", + ":": ":", + "\"": """, + "/": "/", + "\\": "\", + "|": "|", + "?": "?", + "*": "*", +} + func GetSimpleName(filePath string) string { return SplitFileName(filePath).GetLast() } @@ -36,3 +48,11 @@ func SplitFileName(filePath string) *array_list.ArrayList[string] { return array_list.NewArrayListWithContent[string](split...) } + +func ReplaceAllRestrictedCharacters(filePath string) string { + for k, v := range RestrictedFilepathCharactersReplacements { + filePath = strings.ReplaceAll(filePath, k, v) + } + + return filePath +}