|
|
|
|
@ -15,7 +15,7 @@ type Opts struct { |
|
|
|
|
Numeric bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func parse_opts() Opts { |
|
|
|
|
func ParseOpts() Opts { |
|
|
|
|
var opts Opts |
|
|
|
|
|
|
|
|
|
flag.BoolVar(&opts.IgnoreCase, "f", false, "ignore case") |
|
|
|
|
@ -26,7 +26,7 @@ func parse_opts() Opts { |
|
|
|
|
return opts |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func numeric_sort(a string, b string) int { |
|
|
|
|
func NumericSort(a string, b string) int { |
|
|
|
|
a_int, a_err := strconv.Atoi(a) |
|
|
|
|
b_int, b_err := strconv.Atoi(b) |
|
|
|
|
|
|
|
|
|
@ -37,13 +37,13 @@ func numeric_sort(a string, b string) int { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ignore_case_sort(a string, b string) int { |
|
|
|
|
func IgnoreCase(a string, b string) int { |
|
|
|
|
return strings.Compare(strings.ToLower(a), strings.ToLower(b)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
lines := make([]string, 0, 100) |
|
|
|
|
opts := parse_opts() |
|
|
|
|
opts := ParseOpts() |
|
|
|
|
|
|
|
|
|
scan := bufio.NewScanner(os.Stdin) |
|
|
|
|
|
|
|
|
|
@ -53,9 +53,9 @@ func main() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if opts.Numeric { |
|
|
|
|
slices.SortFunc(lines, numeric_sort) |
|
|
|
|
slices.SortFunc(lines, NumericSort) |
|
|
|
|
} else if opts.IgnoreCase{ |
|
|
|
|
slices.SortFunc(lines, ignore_case_sort) |
|
|
|
|
slices.SortFunc(lines, IgnoreCase) |
|
|
|
|
} else { |
|
|
|
|
slices.Sort(lines) |
|
|
|
|
} |
|
|
|
|
|