Skip to content

telegraf/internal/internal.go/SnakeCase misparses "ConsumedLCUs" #16496

@cj-marko-raiha

Description

@cj-marko-raiha

Relevant telegraf.conf

Tried out function directly with the input, so, no telegraf.conf necessary.

Logs from Telegraf

Tried out function directly with the input, so, no logs necessary.

System info

The latest telegraf master repo version

Docker

No response

Steps to reproduce

` package main

import "fmt"
import "unicode"

// SnakeCase converts the given string to snake case following the Golang format:
// acronyms are converted to lower-case and preceded by an underscore.
func SnakeCase(in string) string {
runes := []rune(in)
length := len(runes)

             var out []rune                                                                                                                                                
             for i := 0; i < length; i++ {                                                                                                                                 
                 if i > 0 && unicode.IsUpper(runes[i]) && ((i+1 < length && unicode.IsLower(runes[i+1])) || unicode.IsLower(runes[i-1])) {                                 
                                 out = append(out, '_')                                                                                                                    
                                                                                                                                                                           
                 }                                                                                                                                                         
                         out = append(out, unicode.ToLower(runes[i]))                                                                                                      
                                                                                                                                                                           
             }                                                                                                                                                             
                                                                                                                                                                           
                 return string(out)                                                                                                                                        

}

func main() {
fmt.Println(SnakeCase("ConsumedLCUs"))
}
`

% go run testSnakeCase.go consumed_lc_us %

Expected behavior

consumed_lcus

Actual behavior

consumed_lc_us

Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions