Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PillString case insensitive #21

Closed
livingsilver94 opened this issue May 1, 2019 · 5 comments · Fixed by #22
Closed

Make PillString case insensitive #21

livingsilver94 opened this issue May 1, 2019 · 5 comments · Fixed by #22
Labels
enhancement New feature or request

Comments

@livingsilver94
Copy link

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.

@dmarkham
Copy link
Owner

dmarkham commented May 1, 2019

Can you show me a sample of what your trying to do?

@livingsilver94
Copy link
Author

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".

@dmarkham dmarkham added the enhancement New feature or request label May 1, 2019
@dmarkham
Copy link
Owner

dmarkham commented May 1, 2019

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.

dmarkham added a commit that referenced this issue May 4, 2019
@dmarkham
Copy link
Owner

dmarkham commented May 4, 2019

@livingsilver94 I need more testing on this. But this seems like the cleanest way to pull this together.

dmarkham added a commit that referenced this issue May 4, 2019
@livingsilver94
Copy link
Author

Thank you for implementing it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants