in collector/logs/transforms/parser/keyvalue.go [107:165]
func reflectValue(value string) interface{} {
if len(value) == 0 {
return ""
}
// Fast path for boolean detection based on first character and length
first := value[0]
if (first == 't' || first == 'T') && len(value) == 4 {
if strings.EqualFold(value, "true") {
return true
}
} else if (first == 'f' || first == 'F') && len(value) == 5 {
if strings.EqualFold(value, "false") {
return false
}
}
// Quickly determine if the string represents a numeric value
isNumber := true
isFloat := false
for i := 0; i < len(value); i++ {
c := value[i]
// Allow leading sign characters
if i == 0 && (c == '+' || c == '-') {
continue
}
// Check for decimal point to identify floats
if c == '.' {
if isFloat { // Multiple decimal points invalidate number
isNumber = false
break
}
isFloat = true
continue
}
// Non-digit character invalidates number
if c < '0' || c > '9' {
isNumber = false
break
}
}
// Attempt numeric conversion if valid number detected
if isNumber {
if isFloat {
if floatVal, err := strconv.ParseFloat(value, 64); err == nil {
return floatVal
}
} else {
if intVal, err := strconv.Atoi(value); err == nil {
return intVal
}
}
}
// Default to returning the original string if no conversion succeeded
return value
}