CamelCase fails to lower-case if the first word is a single character
magiconair opened this issue · 3 comments
package main
import (
"fmt"
"github.com/pascaldekloe/name"
)
func main() {
fmt.Println(name.CamelCase("E Stop", false))
fmt.Println(name.CamelCase("E-Stop", false))
fmt.Println(name.CamelCase("Emerg Stop", false))
}
https://play.golang.org/p/ei0guTJGOvw
Output:
EStop
EStop
emergStop
The algorithm correctly recognises the 'E' in 'E Stop' and 'E-Stop' as an abbreviation, thus the uppercase is preserved. There's even a test for this specific case at
Line 20 in 2e12052
How should "ABC thing" render? The "aBCThing" option doesn't look right. Of course, I could make an exception for single letters… 🤔
If the upper parameter is used to generate Go identifiers that are private then the first character must be lower case. That’s how we use the lib.
Yah, that sounds like a fair assumption. We can sacrifice the casing of the first letter since the second casing makes it clear whether the letter was an abbreviation to some extent (except for single letter words). So the pascal case of ABC will be aBC then, agreed?