<commit_before>// Copyright (c) 2014 <NAME>
// Released under the MIT License, http://opensource.org/licenses/MIT

package itkconfig

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
	"strings"
	"unicode"
)

func LoadConfig(filename string, config interface{}) error {
	// Use reflect to place config keys into the right element in the struct
	configReflect := reflect.ValueOf(config).Elem()

	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	fh := bufio.NewScanner(f)

	for fh.Scan() {
		var key, value string
		line := fh.Text()
		lineParts := strings.Split(line, "\"")
		// Split the line on ", because we want to keep parts
		// inside "" unchanged.
		for i, part := range lineParts {
			if i%2 == 0 {
				commentIndex := strings.Index(part, "#")
				if commentIndex != -1 {
					// Remove comments
					part = part[:commentIndex]
				}<commit_msg>Check that the interface passed is of correct type<commit_after>// Copyright (c) 2014 <NAME>
// Released under the MIT License, http://opensource.org/licenses/MIT

package itkconfig

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"reflect"
	"strconv"
	"strings"
	"unicode"
)

func LoadConfig(filename string, config interface{}) error {
	// Use reflect to place config keys into the right element in the struct
	configPtrReflect := reflect.ValueOf(config)
	if configPtrReflect.Kind() != reflect.Ptr {
		return errors.New("Config argument must be a pointer")
	}
	configReflect := configPtrReflect.Elem()
	if configReflect.Kind() != reflect.Struct {
		return errors.New("Config argument must be a pointer to a struct")
	}

	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	fh := bufio.NewScanner(f)

	for fh.Scan() {
		var key, value string
		line := fh.Text()
		lineParts := strings.Split(line, "\"")
		// Split the line on ", because we want to keep parts
		// inside "" unchanged.
		for i, part := range lineParts {
			if i%2 == 0 {
				commentIndex := strings.Index(part, "#")
				if commentIndex != -1 {
					// Remove comments
					part = part[:commentIndex]
				}
{'fraction_non_alphanumeric': 0.13398533007334965, 'fraction_numerical': 0.006845965770171149, 'mean_word_length': 3.353191489361702, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1480699', 'n_tokens_mistral': 744, 'n_tokens_neox': 666, 'n_words': 216}