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

Unicode support #215

Closed
rudolfninja opened this issue Sep 4, 2017 · 7 comments
Closed

Unicode support #215

rudolfninja opened this issue Sep 4, 2017 · 7 comments
Assignees

Comments

@rudolfninja
Copy link

rudolfninja commented Sep 4, 2017

I tried your lib and it seemed very user friendly, thank you for that.
But I faced with problem handling files with uncode (cyrrilic) symbols.
Is it planned to add unicode support or is there any workaround to make your lib "understand" unicode?
I need to write unicode-strings in cells, but there is no suitable function.

Thanks.

@tfussell
Copy link
Owner

tfussell commented Sep 4, 2017

Hi @rudolfninja, I'm glad to hear that it's easy to use. Unicode is supported throughout the library. For the most part, std::string is used to hold UTF-8 encoded strings. It can be difficult to create a string literal containing unicode characters in a source file. Where exactly are you having trouble using Cyrillic characters? Filenames? Cell values?

@rudolfninja
Copy link
Author

rudolfninja commented Sep 4, 2017

When I'm trying to write Russian text to cell or when I'm trying to open(save) file with Russian name.
Bad conversation exception is thrown from path.cpp
#ifdef _MSC_VER std::wstring path::wstring() const { std::wstring_convert<std::codecvt_utf8<wchar_t>> convert; return convert.from_bytes(string()); } #endif
When trying to write Russian symbols to file I have GENX_BAD_UTF8 exception

@tfussell
Copy link
Owner

tfussell commented Sep 4, 2017

How are you initializing the filename string? If it's a string literal in the source file, you need to use the appropriate prefix to ensure the correct encoding is used, probably L"" or u8"". See here for more info http://en.cppreference.com/w/cpp/language/string_literal . You also need to save the file with the correct encoding (in VS, File->Save with encoding->UTF-8). If you're getting the string from an argument or somewhere else, you need to make sure it's correctly encoded when you receive it.

@rudolfninja
Copy link
Author

I'm getting string as a command line argument. I'll try to find the way to check it somehow

@tfussell
Copy link
Owner

tfussell commented Sep 4, 2017

Linux or Windows? If Windows, you'll probably need to use the Windows-specific entry point that passes arguments as strings of wchar_ts, wmain:

int wmain(int argc, wchar_t *argv[])
{
    const auto arg1 = std::wstring(argv[1]);
    ...
}

If needed, convert a wstring to string with a library like utfcpp or use the built-in (but deprecated) codecvt like this:

#include <codevt>
#include <locale>
...
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
const auto utf8_string = converter.to_bytes(wchar_string);

@rudolfninja
Copy link
Author

std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; const auto utf8_string = converter.to_bytes(wchar_string);
Solved the problem! Thanks.

@tfussell
Copy link
Owner

tfussell commented Sep 4, 2017

Glad to hear it!

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

2 participants