Closed livingsilver94 closed 5 years ago
Can you show me a sample of what your trying to do?
type Pill int
const (
Placebo Pill = iota
IDK
)
Now, IDK.String()
returns "IDK"
if no transformation is performed, and that's OK, but if I wanted to do this:
myPill := PillString("idk")
I would get an error because "idk"
is lowercase. Suppose that the string comes from a CLI command: some users could write "idk", while others could write "IDK". I don't want to transform every pill to uppercase though because Placebo must stay as it is.
Same rationale for Placebo, even: some could write "Placebo", others "placebo".
So I like the feature. I do not yet like my options on how I would implement this.
I want to keep things compatible with people relying on case-sensitivity not matter how silly that sounds.
I'll see what a patch will look like. Unless someone get there first.
@livingsilver94 I need more testing on this. But this seems like the cleanest way to pull this together.
Thank you for implementing it :+1:
It would be useful to perform string -> enum conversion in a case-insensitive fashion. While I could convert my string to lowercase and have all of my values lowercase as well, some of them are acronyms which looks ugly if not written with capital letters.