func (i IsFullWidthChecker) IsFormat(data string) bool {
	return govalidator.IsFullWidth(data)
}
Exemple #2
0
func (r *Report) parseRecord(record []string) (nullCount int) {
	r.Records++
	size := len(record)
	if size > len(r.Fields) {
		for i := len(r.Fields); i < size; i++ {
			f := new(ReportField)
			f.Name = fmt.Sprintf("Column%03d", i+1)
			f.Blank = r.Records - 1 // suppose all cells are blank until up to here.
			r.Fields = append(r.Fields, f)
		}
	}
	for i := 0; i < size; i++ {
		f := r.Fields[i]
		val := strings.TrimSpace(record[i])
		if len(val) == 0 {
			nullCount++
			f.Blank++
			continue
		}
		stringLength := utf8.RuneCountInString(val)
		if f.MinLength == 0 || f.MinLength > stringLength {
			f.MinLength = stringLength
		}
		if f.MaxLength < stringLength {
			f.MaxLength = stringLength
		}
		if valid.IsFullWidth(val) {
			f.fullWidth++
		}
		if valInt, err := strconv.Atoi(val); err == nil {
			v := float64(valInt)
			if f.Minimum == nil {
				f.Minimum = new(float64)
				*f.Minimum = v
			}
			if f.Maximum == nil {
				f.Maximum = new(float64)
				*f.Maximum = v
			}
			if v < *f.Minimum {
				*f.Minimum = v
			}
			if v > *f.Maximum {
				*f.Maximum = v
			}
			f.TypeInt++
		}
		if valFloat, err := strconv.ParseFloat(val, 64); err == nil {
			if f.Minimum == nil {
				f.Minimum = new(float64)
				*f.Minimum = valFloat
			}
			if f.Maximum == nil {
				f.Maximum = new(float64)
				*f.Maximum = valFloat
			}
			if valFloat < *f.Minimum {
				*f.Minimum = valFloat
			}
			if valFloat > *f.Maximum {
				*f.Maximum = valFloat
			}
			f.TypeFloat++
		}
		if valBool, err := strconv.ParseBool(val); err == nil {
			if f.TypeBool == 0 {
				f.BoolTrue = new(int)
				f.BoolFalse = new(int)
			}
			if valBool {
				*f.BoolTrue++
			} else {
				*f.BoolFalse++
			}
			f.TypeBool++
		}
		if valTime, err := parseDateTime(val); err == nil {
			if f.TypeTime == 0 {
				f.MinTime = new(time.Time)
				f.MaxTime = new(time.Time)
				*f.MinTime = valTime
				*f.MaxTime = valTime
			}
			if valTime.Before(*f.MinTime) {
				*f.MinTime = valTime
			}
			if valTime.After(*f.MaxTime) {
				*f.MaxTime = valTime
			}
			f.TypeTime++
		}
	}
	return nullCount
}