<commit_before>// Copyright 2012 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
	"flag"
	"fmt"
	"os"
	"regexp"
	"sort"
	"strings"
)

type ProgramArguments struct {
	KeepCase    bool
	KeepNonword bool
}

var gProgramArgs ProgramArguments

// Used to implement lexicographical string sorting.
type SortableRunes []rune

func (s SortableRunes) Len() int {
	return len(s)
}

func (s SortableRunes) Less(i, j int) bool {
	return s[i] < s[j]
}

func (s SortableRunes) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func CheckAnagrams(a, b string) bool {
	// Fast path: if a and b have different lengths, then they cannot be
	// anagrams.
	if len(a) != len(b) {
		return false
	}

	aRunes, bRunes := SortableRunes(a), SortableRunes(b)
	sort.Sort(aRunes)
	sort.Sort(bRunes)
	return string(aRunes) == string(bRunes)
}

func StripInput(input string) string {
	if !gProgramArgs.KeepCase {
		input = strings.ToLower(input)
	}
	if !gProgramArgs.KeepNonword {
		stripRegexp := regexp.MustCompile("\\W")
		return stripRegexp.ReplaceAllString(input, "")
	}
	return input
}

func Usage() {
	fmt.Fprint(os.Stderr,
		"usage: check_anagram [options] string1 string2\n\n" +
		"Prints \"Yes\" if string1 and string2 are anagrams, \"No\" otherwise.\n\n" +
		"Options:\n")
	flag.PrintDefaults()<commit_msg>[Go] Correct formatting (gofmt).<commit_after>// Copyright 2012 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
	"flag"
	"fmt"
	"os"
	"regexp"
	"sort"
	"strings"
)

type ProgramArguments struct {
	KeepCase    bool
	KeepNonword bool
}

var gProgramArgs ProgramArguments

// Used to implement lexicographical string sorting.
type SortableRunes []rune

func (s SortableRunes) Len() int {
	return len(s)
}

func (s SortableRunes) Less(i, j int) bool {
	return s[i] < s[j]
}

func (s SortableRunes) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func CheckAnagrams(a, b string) bool {
	// Fast path: if a and b have different lengths, then they cannot be
	// anagrams.
	if len(a) != len(b) {
		return false
	}

	aRunes, bRunes := SortableRunes(a), SortableRunes(b)
	sort.Sort(aRunes)
	sort.Sort(bRunes)
	return string(aRunes) == string(bRunes)
}

func StripInput(input string) string {
	if !gProgramArgs.KeepCase {
		input = strings.ToLower(input)
	}
	if !gProgramArgs.KeepNonword {
		stripRegexp := regexp.MustCompile("\\W")
		return stripRegexp.ReplaceAllString(input, "")
	}
	return input
}

func Usage() {
	fmt.Fprint(os.Stderr, "usage: check_anagram [options] string1 string2\n\n"+
		"Prints \"Yes\" if string1 and string2 are anagrams, \"No\" otherwise.\n\n"+
		"Options:\n")
	flag.PrintDefaults()
{'fraction_non_alphanumeric': 0.12332512988788624, 'fraction_numerical': 0.006562756357670222, 'mean_word_length': 3.8450331125827812, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2707295', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1250, 'n_words': 416}