diff --git a/go.mod b/go.mod index 49be63d..c90ea2d 100644 --- a/go.mod +++ b/go.mod @@ -11,5 +11,6 @@ require ( github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd github.com/urfave/cli/v2 v2.2.0 golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 // indirect + golang.org/x/text v0.3.6 gopkg.in/djherbis/times.v1 v1.2.0 ) diff --git a/go.sum b/go.sum index 484a0d8..e1ea7c6 100644 --- a/go.sum +++ b/go.sum @@ -32,6 +32,9 @@ github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1z golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 h1:g9s1Ppvvun/fI+BptTMj909BBIcGrzQ32k9FNlcevOE= golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/src/app.go b/src/app.go index 630dd1b..25fb358 100644 --- a/src/app.go +++ b/src/app.go @@ -85,7 +85,7 @@ func GetApp() *cli.App { }, Usage: "F2 is a command-line tool for batch renaming multiple files and directories quickly and safely", UsageText: "FLAGS [OPTIONS] [PATHS...]", - Version: "v1.5.7", + Version: "v1.5.8", EnableBashCompletion: true, Flags: []cli.Flag{ &cli.StringFlag{ diff --git a/src/replace.go b/src/replace.go index 686655c..78df3db 100644 --- a/src/replace.go +++ b/src/replace.go @@ -7,6 +7,11 @@ import ( "regexp" "strconv" "strings" + "unicode" + + "golang.org/x/text/runes" + "golang.org/x/text/transform" + "golang.org/x/text/unicode/norm" ) type numbersToSkip struct { @@ -460,6 +465,18 @@ func (op *Operation) transformString( out = op.regexReplace(fullWindowsForbiddenRegex, fileName, "") case `\Tmac`: out = op.regexReplace(macForbiddenRegex, fileName, "") + case `\Td`: + t := transform.Chain( + norm.NFD, + runes.Remove(runes.In(unicode.Mn)), + norm.NFC, + ) + result, _, err := transform.String(t, fileName) + if err != nil { + return fileName + } + + out = result } return out @@ -468,7 +485,7 @@ func (op *Operation) transformString( func (op *Operation) replaceString(fileName string) (str string) { replacement := op.replacement - slice := []string{`\Tcu`, `\Tcl`, `\Tct`, `\Twin`, `\Tmac`} + slice := []string{`\Tcu`, `\Tcl`, `\Tct`, `\Twin`, `\Tmac`, `\Td`} if contains(slice, replacement) { return op.transformString(fileName, replacement) } diff --git a/src/replace_test.go b/src/replace_test.go index 7ce8823..ba8637e 100644 --- a/src/replace_test.go +++ b/src/replace_test.go @@ -326,6 +326,12 @@ func TestTransformation(t *testing.T) { find: `abc.*`, output: `abc<>_{}*?\/\.epub`, }, + { + input: "žůžo.txt", + transform: `\Td`, + find: "žůžo", + output: "zuzo.txt", + }, } for _, v := range cases {