Skip to content

Commit

Permalink
Add option to remove diacritics in text
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed May 5, 2021
1 parent b18c877 commit de8e164
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion src/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
19 changes: 18 additions & 1 deletion src/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions src/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit de8e164

Please sign in to comment.