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

Support wmain and wchar_t* argv #8

Open
adishavit opened this issue Nov 8, 2016 · 7 comments
Open

Support wmain and wchar_t* argv #8

adishavit opened this issue Nov 8, 2016 · 7 comments

Comments

@adishavit
Copy link
Owner

On Windows, support wmain and wchar_t* argv[]

@adishavit adishavit self-assigned this Nov 8, 2016
@adishavit
Copy link
Owner Author

This can be done by converting it all into a a template on the char type.
Will do if there's interest.

@adishavit adishavit removed their assignment Mar 7, 2017
@MrSapps
Copy link

MrSapps commented Sep 25, 2017

hmm would probably be better to construct from the wchar_t and then convert to utf8 instead?

@adishavit
Copy link
Owner Author

Maybe, but remember that there are a lot of std::string usages too for all the accessors and istreams.

I never actually needed this nor seem a compelling use case. As far as I can see it is very low priority.
If someone really needs this use case, then they are more than welcome to try and implement it :-).

@Shidell
Copy link

Shidell commented Feb 26, 2019

I would like to implement a wmain/wchar_t/wstring solution--it looks like #15 might go hand-in-hand for Windows developers and/or anyone using Unicode.

Thoughts on a good way to implement without stepping on toes? For #15, I thought a preprocessor definition at the start allowing Windows developers to indicate as such might be appropriate, and then expose a Windows-specific parse() function (parse(mode)?) that would automatically use Window's ArgC/ArgV with the specified mode.

As for this issue, supporting wmain/wchar_t, what do we think about making a second preprocessor directive that specifies string (ANSI) or wstring (UNICODE)? I suppose we could get fancy and overload each method to support string or wstring, and then convert if/as necessary, too. That would eliminate the need for preprocessor directives, but would increase Argh!'s length quite a bit.

@adishavit
Copy link
Owner Author

As I said above it could be templated on wchar_t and then use wide strings inside the class. I'm not sure everything will work with wide strings.

Regardless, please, no macros (preprocessor flags).
Maybe start with a argh::windows::parser Windows-specific specialization namespace to not step on any toes and refactor from there...

Try a few approaches, see what works and what feels minimal yet expressive.
Add unit-tests.
Good luck!

@Shidell
Copy link

Shidell commented Mar 7, 2019

This is my first time writing templated code, and I'm struggling with it. I made an attempt here, but wasn't very successful.

I know you're opposed to macros, but it's what I know, so I made a second fork for a proof-of-concept here. UNICODE is generally already defined for Windows devs, but I thought it'd be easy enough to specify and/or change the gates so the dev who wants to use Argh! can select either.

As a side discussion (but related), with respect to #15, when the default constructor(s) are modified to support unicode, Windows devs can simply pass the "__wargv" macro.

For example:

argh::parser cmdl = argh::parser(__wargv);

@BeErikk
Copy link

BeErikk commented May 7, 2020

I've made a draft solution by changing the parser class to a template class, like this:

   template<typename CharType = char>
   class parser

and then

   using Tstring = std::basic_string<CharType, std::char_traits<CharType>, std::allocator<CharType>>;
   using Tstring_view = std::basic_string_view<CharType>;
   using Tistringstream = std::basic_istringstream<CharType, std::char_traits<CharType>, std::allocator<CharType>>;
   using Tostringstream = std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType>>;

The solution thus allows existing code to pass unaltered (as char default) and allow using strings with wchar_t, u8string, u16string and u32string. Tested with supplied test.

Note: I had to change code layout and move function implementation into the class, sorry for that. I also patched the code to support both - and / delimiters

My files zipped: argh_wide.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants