<commit_before>package jamon

import (
	"bufio"
	"os"
	"strings"
)

// A configuration type may hold multiple categories of settings
type Config map[string]Category

// A category holds key-value pairs of settings
type Category map[string]string

// Loads a configuration file
func Load(filename string) (Config, error) {
	file, err := os.Open(filename)
	if err != nil {
		return Config{}, err
	}

	fr := bufio.NewReader(file)

	config := Config{}
	currentCategory := "JAMON.NO_CATEGORY"

	for {
		line_bytes, _, err := fr.ReadLine()
		if err != nil {
			break
		}

		isCategory, value, key, skip := parseLine(string(line_bytes))

		switch {
		case skip:
			continue

		case isCategory:
			currentCategory = value
			continue
		}

		if config[currentCategory] == nil {
			config[currentCategory] = make(Category)
		}

		config[currentCategory][key] = value
	}

	return config, nil
}

// Attempts to parse an entry in the config file. The first return value specifies
// whether 'value' is the name of a category or the value of a key.
func parseLine(line string) (isCategory bool, value, key string, skip bool) {
	line = strings.Trim(strings.SplitN(line, "#", 2)[0], " \t\r\n")

	// Is comment?
	if strings.HasPrefix(line, "#") || len(line) == 0 {
		skip = true
		return
	}

	// Is category?
	if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
		isCategory = true
		value = strings.Trim(line, "[]")
		return
	}<commit_msg>reduced ifs<commit_after>package jamon

import (
	"bufio"
	"os"
	"strings"
)

// A configuration type may hold multiple categories of settings
type Config map[string]Category

// A category holds key-value pairs of settings
type Category map[string]string

// Loads a configuration file
func Load(filename string) (Config, error) {
	file, err := os.Open(filename)
	if err != nil {
		return Config{}, err
	}

	fr := bufio.NewReader(file)

	config := Config{}
	currentCategory := "JAMON.NO_CATEGORY"

	for {
		line_bytes, _, err := fr.ReadLine()
		if err != nil {
			break
		}

		isCategory, value, key, skip := parseLine(string(line_bytes))

		switch {
		case skip:
			continue

		case isCategory:
			currentCategory = value
			continue

		case config[currentCategory] == nil:
			config[currentCategory] = make(Category)
		}

		config[currentCategory][key] = value
	}

	return config, nil
}

// Attempts to parse an entry in the config file. The first return value specifies
// whether 'value' is the name of a category or the value of a key.
func parseLine(line string) (isCategory bool, value, key string, skip bool) {
	line = strings.Trim(strings.SplitN(line, "#", 2)[0], " \t\r\n")

	// Is comment?
	if strings.HasPrefix(line, "#") || len(line) == 0 {
		skip = true
		return
	}

	// Is category?
	if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
		isCategory = true
		value = strings.Trim(line, "[]")
		return
	}
{'fraction_non_alphanumeric': 0.12931334959916346, 'fraction_numerical': 0.0020913210177762286, 'mean_word_length': 3.644012944983819, 'pattern_counts': {'":': 0, '<': 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': '1383257', 'n_tokens_mistral': 1024, 'n_tokens_neox': 934, 'n_words': 291}