mirror of
https://github.com/rumanzo/bt2qbt.git
synced 2024-11-25 11:52:56 +01:00
0b305dd2f9
* handle windows fs prohibited symbols * fix abs path symbols replace * more readable code * better replacer new replacer function with tests * return zero files from torrent info file tree if there are single file torrent * don't harm torrent file function, handle filelist size in another places * more accurate handling single files * use mapped files for directories or torrent names with space on ending * normalize backslases too * Don't normalize cesu8\prohibited symbols on torrent name if torrent file contain several files. But normalize for single file torrent and normalize last space character for both * Better torrent name and torrent file paths handling helpers tests * move torrents functions to torrents functions cache single flag * update README.md * fix deprecation warnings
36 lines
771 B
Go
36 lines
771 B
Go
package normalization
|
|
|
|
import (
|
|
"github.com/rumanzo/bt2qbt/pkg/helpers"
|
|
"regexp"
|
|
)
|
|
|
|
// ProhibitedSymbolsStrict we can't use these symbols on Windows systems, but can use in *nix
|
|
var ProhibitedSymbolsStrict = regexp.MustCompilePOSIX(`[\\/:*?"<>|]`)
|
|
|
|
func NormalizeSpaceEnding(str string) (string, bool) {
|
|
var normalized bool
|
|
if string(str[len(str)-1]) == ` ` {
|
|
str = str[:len(str)-1] + `_`
|
|
normalized = true
|
|
}
|
|
return str, normalized
|
|
}
|
|
|
|
func FullNormalize(str string) (string, bool) {
|
|
var normalized bool
|
|
s1 := ProhibitedSymbolsStrict.ReplaceAllString(str, `_`)
|
|
if s1 != str {
|
|
normalized = true
|
|
}
|
|
s2 := helpers.HandleCesu8(s1)
|
|
if s1 != s2 {
|
|
normalized = true
|
|
}
|
|
s3, n := NormalizeSpaceEnding(s2)
|
|
if n {
|
|
normalized = true
|
|
}
|
|
return s3, normalized
|
|
}
|