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

Add char type #449

Merged
merged 1 commit into from
Sep 30, 2020
Merged

Add char type #449

merged 1 commit into from
Sep 30, 2020

Conversation

phlptp
Copy link
Collaborator

@phlptp phlptp commented Mar 28, 2020

Add support for a char type in the options.

This was technically supported before but in that the option type was accepted but it was always interpreted as an int, which is not necessarily what is desired. The added conversion interprets single character strings as the character, and otherwise defaults to a numerical conversion.

This issue came up a couple times in our usage, when character inputs unexpectedly produced errors when trying to define an option for a separation character or delimiter.

@phlptp phlptp requested a review from henryiii March 28, 2020 23:01
@codecov
Copy link

codecov bot commented Mar 29, 2020

Codecov Report

Merging #449 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #449   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines         3724      3729    +5     
=========================================
+ Hits          3724      3729    +5     
Impacted Files Coverage Δ
include/CLI/TypeTools.hpp 100.00% <100.00%> (ø)
include/CLI/Validators.hpp 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b059cb...58fd5d1. Read the comment docs.

@phlptp
Copy link
Collaborator Author

phlptp commented Mar 29, 2020

This has become a little more complicated than originally intended. The issue arose with handling enumerations with a char type, which wouldn't want to allow single characters. So that required discriminated those cases in the lexical cast. Which led to a separate function for integral conversions and some other code cleanup that could be done as a result. which led to some tweaks to some of the validators.

@phlptp
Copy link
Collaborator Author

phlptp commented Mar 29, 2020

One remaining question: In the char conversions with single digits '0' - '9' should these be treated as the numerical equivalent or the character? treating them as numbers would be completely backwards compatible, but questionable whether that is needed or not when moving to 2.0. Not sure I have a strong preference, my use case wouldn't be impacted and enum:char are handled separately.

@henryiii
Copy link
Collaborator

So would 03 be the way to get the char value 3? Then 3 probably could the be char 3, as otherwise you can't get the char 3 without looking up it's numerical code?

@phlptp
Copy link
Collaborator Author

phlptp commented May 21, 2020

If we treated single numerical values as character ['0'-'9'] the ways to get the numerical value if that is what you wanted would be, using 3 as an example:
"03", "+3", "0x03" I think the octal and binary equivalent might work as well

@henryiii
Copy link
Collaborator

Do you have a stronger opinion now about the best choice here, or are you still torn?

@phlptp
Copy link
Collaborator Author

phlptp commented May 21, 2020

My inclination is that taking it as an actual char is preferable, since otherwise it would be complicated to actually get the character '3',

my only hesitancy is that it does break backwards compatibility. which should be fine if the next release is 2.0.

@henryiii
Copy link
Collaborator

We may make a 1.9.1, but I think we've already sailed past 1.10. The downside is I'll have to get two or three large changes in that I really want in 2.0.

@henryiii
Copy link
Collaborator

I think we've already sailed past 1.10

Feel free to correct me if I'm wrong, I need to compile the changelog.

@phlptp
Copy link
Collaborator Author

phlptp commented May 21, 2020

yeah I think there were a few changes that already broke backwards compatibility in a few circumstances, so we were definitely on the path to a 2.0 release.

@henryiii henryiii added this to the v2.0 milestone Jun 2, 2020
…s the actual numerical conversion using the lower level function to avoid catching exceptions internally.

add a test for char options

add support for char types to the lexical cast, to allow single character types that make sense, add a integral_conversion operations to simplify the conversions from string to integers and allow discrimination in a few cases with enumerations.
@phlptp
Copy link
Collaborator Author

phlptp commented Sep 30, 2020

@henryiii Was there anything you wanted me to do with this or are you just waiting for a 2.0 release?

@henryiii
Copy link
Collaborator

I was a little indecisive about "1" being char 1 or value 1. Rereading it, I think the point that there's a way to get a number, but not a good way to get a char is reasonable enough to argue for this being best.

@henryiii henryiii merged commit 438eabe into CLIUtils:master Sep 30, 2020
@henryiii henryiii deleted the add_char_type branch September 30, 2020 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants