<commit_before>package common

import (
	"fmt"
	"os"
	"regexp"
	"strconv"
	"path/filepath"
	"strings"

	"github.com/mgutz/ansi"
)

func UsageAndExit(message string, args ...interface{}) {
	if message != "" {
		fmt.Fprintf(os.Stderr, "\n")
		fmt.Fprintf(os.Stderr, ansi.Color(message, "red"), args...)
		fmt.Fprintf(os.Stderr, "\n")
	}
	//flag.Usage()
	fmt.Fprintf(os.Stderr, "\n")
	os.Exit(1)
}

func InfoErr(msg string, args ...interface{}) {
	if _, err := fmt.Fprintf(os.Stderr, ansi.Color(msg, "magenta"), args...); err != nil {
		panic(err)
	}
}

var fileSizePattern = regexp.MustCompile("([0-9]+)x([0-9]+)?")

func FileSizeFromPath(path string) (width, height int) {
	m := fileSizePattern.FindStringSubmatch(path)
	if len(m) == 3 {
		width, _ = strconv.Atoi(m[1])
		height, _ = strconv.Atoi(m[2])
	}
	if height == 0 {
		height = width
	}
	return
}

var ps = string(os.PathSeparator)

func ContainsFolderName(path string, names ...string) bool {
	for _, n := range names {
		if strings.Contains(path, ps+n+ps) {
			return true
		}
	}
	return false
}

func IsImage(path string) (ok bool) {

	switch filepath.Ext(path) {
	case ".png", ".gif", ".jpg", ".jpeg", ".ico":
		ok = true
	}
	return
}<commit_msg>Update common docs<commit_after>package common

import (
	"fmt"
	"os"
	"regexp"
	"strconv"
	"path/filepath"
	"strings"

	"github.com/mgutz/ansi"
)

func UsageAndExit(message string, args ...interface{}) {
	if message != "" {
		fmt.Fprintf(os.Stderr, "\n")
		fmt.Fprintf(os.Stderr, ansi.Color(message, "red"), args...)
		fmt.Fprintf(os.Stderr, "\n")
	}
	//flag.Usage()
	fmt.Fprintf(os.Stderr, "\n")
	os.Exit(1)
}

func InfoErr(msg string, args ...interface{}) {
	if _, err := fmt.Fprintf(os.Stderr, ansi.Color(msg, "magenta"), args...); err != nil {
		panic(err)
	}
}

var fileSizePattern = regexp.MustCompile("([0-9]+)x([0-9]+)?")

func FileSizeFromPath(path string) (width, height int) {
	m := fileSizePattern.FindStringSubmatch(path)
	if len(m) == 3 {
		width, _ = strconv.Atoi(m[1])
		height, _ = strconv.Atoi(m[2])
	}
	if height == 0 {
		height = width
	}
	return
}

var ps = string(os.PathSeparator)

// ContainsFolderName checks if path contains a name. A name will be prepended
// with an OS specific path separator, e.g.: .svn becomes /.svn
func ContainsFolderName(path string, names ...string) bool {
	for _, n := range names {
		if strings.Contains(path, ps+n) {
			return true
		}
	}
	return false
}

// IsImage checks if path to a file is an image by extracting the file extension
// and checking it against an internal list.
func IsImage(path string) (ok bool) {
	switch filepath.Ext(path) {
	case ".png", ".gif", ".jpg", ".jpeg", ".ico":
		ok = true
	}
	return
}
{'fraction_non_alphanumeric': 0.18046234153616703, 'fraction_numerical': 0.006711409395973154, 'mean_word_length': 3.6179001721170394, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '718513', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1047, 'n_words': 252}