Skip to content

Commit

Permalink
Merge pull request #4 from Snawoot/normalize_unicode
Browse files Browse the repository at this point in the history
Normalize Unicode
  • Loading branch information
Snawoot authored Feb 15, 2024
2 parents 3c9dbf2 + d036982 commit 9bc79a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/copeland/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

"github.com/Snawoot/copeland"
"golang.org/x/text/unicode/norm"
)

const (
Expand All @@ -23,13 +24,14 @@ const (
var (
version = "undefined"

showVersion = flag.Bool("version", false, "show program version and exit")
normalizeCase = flag.Bool("normalize-case", true, "normalize case")
scoreWin = flag.Float64("score-win", 1, "score for win against opponent")
scoreTie = flag.Float64("score-tie", .5, "score for tie against opponent")
scoreLoss = flag.Float64("score-loss", 0, "score for tie against opponent")
names = flag.String("names", "", "filename of list of names in the voting. If not specified names inferred from first ballot")
skipErrors = flag.Bool("skip-errors", false, "skip ballot errors, but still report them")
showVersion = flag.Bool("version", false, "show program version and exit")
normalizeCase = flag.Bool("normalize-case", true, "normalize case")
normalizeUnicode = flag.Bool("normalize-unicode", true, "normalize unicode characters")
scoreWin = flag.Float64("score-win", 1, "score for win against opponent")
scoreTie = flag.Float64("score-tie", .5, "score for tie against opponent")
scoreLoss = flag.Float64("score-loss", 0, "score for tie against opponent")
names = flag.String("names", "", "filename of list of names in the voting. If not specified names inferred from first ballot")
skipErrors = flag.Bool("skip-errors", false, "skip ballot errors, but still report them")
)

func cmdVersion() int {
Expand Down Expand Up @@ -154,6 +156,9 @@ func readBallot(input io.Reader) ([]string, error) {
if line == "" {
continue
}
if normalizeUnicode != nil && *normalizeUnicode {
line = norm.NFKC.String(line)
}
if normalizeCase != nil && *normalizeCase {
line = strings.ToUpper(line)
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/Snawoot/copeland

go 1.21.6

require golang.org/x/text v0.14.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

0 comments on commit 9bc79a1

Please sign in to comment.