<commit_before>package internal

import (
	"encoding/xml"
	"errors"
	"fmt"
	"reflect"
	"strings"

	convert "github.com/szyhf/go-convert"
	"github.com/szyhf/go-excel/internal/twenty_six"
)

type TitleRow struct {
	// map[0]A1
	dstMap map[string]int

	typeFieldMap map[reflect.Type]map[int][]*FieldConfig
}

func newRowAsMap(rd *Read) (r *TitleRow, err error) {
	defer func() {
		if rc := recover(); rc != nil {
			err = fmt.Errorf("%s", rc)
		}
	}()
	r = &TitleRow{
		dstMap: make(map[string]int),
	}
	tempCell := &xlsxC{}
	for t, err := rd.decoder.Token(); err == nil; t, err = rd.decoder.Token() {
		switch token := t.(type) {
		case xml.StartElement:
			if token.Name.Local == "c" {
				tempCell.R = ""
				tempCell.T = ""
				for _, a := range token.Attr {
					switch a.Name.Local {
					case "r":
						tempCell.R = a.Value
					case "t":
						tempCell.T = a.Value
					}
				}
			}
		case xml.EndElement:
			if token.Name.Local == ROW {
				// 结束当前行
				r.typeFieldMap = make(map[reflect.Type]map[int][]*FieldConfig)
				return r, nil
			}
		case xml.CharData:
			trimedColumnName := strings.TrimRight(tempCell.R, ALL_NUMBER)
			columnIndex := twentySix.ToDecimalism(trimedColumnName)
			var str string
			if tempCell.T == S {
				// get string from shared
				str = rd.connecter.getSharedString(convert.MustInt(string(token)))
			} else {
				str = string(token)
			}
			// r.srcMap[columnIndex] = str
			r.dstMap[str] = columnIndex
		}
	}

	return nil, errors.New("No row")
}

// return: a copy of map[ColumnIndex][]*FieldConfig
func (this *TitleRow) MapToFields(s *Schema) (rowToFiled map[int][]*FieldConfig) {
	fieldsMap, ok := this.typeFieldMap[s.Type]
	if !ok {
		fieldsMap = make(map[int][]*FieldConfig)
		for _, field := range s.Fields {
			var cloIndex int
			// Use ColumnName to find index
			if i, ok := this.dstMap[field.ColumnName]; ok {
				cloIndex = i
			} else {
				// Use 26-number-system to find
				cloIndex = twentySix.ToDecimalism(field.ColumnName)
			}

			if fAry, ok := fieldsMap[cloIndex]; !ok {
				fieldsMap[cloIndex] = []*FieldConfig{field}
			} else {
				fieldsMap[cloIndex] = append(fAry, field)
			}
		}
		this.typeFieldMap[s.Type] = fieldsMap
	}
	copyMap := make(map[int][]*FieldConfig)
	for k, v := range fieldsMap {
		copyMap[k] = v
	}
	return copyMap
}
<commit_msg>取消在无法读到title name的时候会尝试26进制的设计。<commit_after>package internal

import (
	"encoding/xml"
	"errors"
	"fmt"
	"reflect"
	"strings"

	convert "github.com/szyhf/go-convert"
	"github.com/szyhf/go-excel/internal/twenty_six"
)

type TitleRow struct {
	// map[0]A1
	dstMap map[string]int

	typeFieldMap map[reflect.Type]map[int][]*FieldConfig
}

func newRowAsMap(rd *Read) (r *TitleRow, err error) {
	defer func() {
		if rc := recover(); rc != nil {
			err = fmt.Errorf("%s", rc)
		}
	}()
	r = &TitleRow{
		dstMap: make(map[string]int),
	}
	tempCell := &xlsxC{}
	for t, err := rd.decoder.Token(); err == nil; t, err = rd.decoder.Token() {
		switch token := t.(type) {
		case xml.StartElement:
			if token.Name.Local == "c" {
				tempCell.R = ""
				tempCell.T = ""
				for _, a := range token.Attr {
					switch a.Name.Local {
					case "r":
						tempCell.R = a.Value
					case "t":
						tempCell.T = a.Value
					}
				}
			}
		case xml.EndElement:
			if token.Name.Local == ROW {
				// 结束当前行
				r.typeFieldMap = make(map[reflect.Type]map[int][]*FieldConfig)
				return r, nil
			}
		case xml.CharData:
			trimedColumnName := strings.TrimRight(tempCell.R, ALL_NUMBER)
			columnIndex := twentySix.ToDecimalism(trimedColumnName)
			var str string
			if tempCell.T == S {
				// get string from shared
				str = rd.connecter.getSharedString(convert.MustInt(string(token)))
			} else {
				str = string(token)
			}
			// r.srcMap[columnIndex] = str
			r.dstMap[str] = columnIndex
		}
	}

	return nil, errors.New("No row")
}

// return: a copy of map[ColumnIndex][]*FieldConfig
func (this *TitleRow) MapToFields(s *Schema) (rowToFiled map[int][]*FieldConfig) {
	fieldsMap, ok := this.typeFieldMap[s.Type]
	if !ok {
		fieldsMap = make(map[int][]*FieldConfig)
		for _, field := range s.Fields {
			var cloIndex int
			// Use ColumnName to find index
			if i, ok := this.dstMap[field.ColumnName]; ok {
				cloIndex = i
			} else {
				// Use 26-number-system to find
				// cloIndex = twentySix.ToDecimalism(field.ColumnName)
				panic(fmt.Sprintf("go-excel: column name = \"%s\" is not exist.", field.ColumnName))
			}

			if fAry, ok := fieldsMap[cloIndex]; !ok {
				fieldsMap[cloIndex] = []*FieldConfig{field}
			} else {
				fieldsMap[cloIndex] = append(fAry, field)
			}
		}
		this.typeFieldMap[s.Type] = fieldsMap
	}
	copyMap := make(map[int][]*FieldConfig)
	for k, v := range fieldsMap {
		copyMap[k] = v
	}
	return copyMap
}

{'fraction_non_alphanumeric': 0.15321217244294166, 'fraction_numerical': 0.002113271344040575, 'mean_word_length': 3.130017452006981, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '7202470', 'n_tokens_mistral': 2087, 'n_tokens_neox': 1801, 'n_words': 379}