0

I have read that ICU library is used as the default backend in boost::locale. If so, Can we use the UnicodeString type of ICU in boost? Can someone please provide an example..

EDIT: This is what I tried at last.. Here instead of storing to wstring, I need a UnicodeString.

#include <boost/locale.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <fcntl.h>
#include <io.h>
int main()
{

    boost::locale::localization_backend_manager my = boost::locale::localization_backend_manager::global();
    my.select("icu");



    _setmode(_fileno(stdout), _O_WTEXT); // for output

    std::locale::global(boost::locale::generator(my).generate(""));


    boost::filesystem::path::imbue(std::locale());
    boost::filesystem::wifstream hello("I:\\a.txt");//Contents of this file can be strings in regional language

    if (hello.is_open())
    {

        for (std::wstring s; getline(hello, s); )
        {
            std::wcout << s;//need a UnicodeString instead of s.
            std::wstring cmd = L"I:\\";
            cmd += s;
            boost::filesystem::wifstream hello1(cmd);
            if (hello1.is_open())
            {
                std::wstring i;
                while(getline(hello1,i))
                    std::wcout << i;
            }
            hello1.close();

        }
    }
    hello.close();
}
Jackzz
  • 1,417
  • 4
  • 24
  • 53
  • `icu::UnicodeString` is just a type, so you can use it. What exactly are you trying to achieve? Are you having specific issues using it together with other boost libraries? – Christian.K Jul 05 '16 at 13:01
  • If you enable and build Boost against ICU, boost::locale will use ICU as it's backing implementation -- conversions/etc. will be done by ICU. What are you having an issue with? – NuSkooler Jul 06 '16 at 23:52
  • @NuSkooler I built Boost against ICU.Now I want to attain unicode support for my application, say, filename i want to open can be in some regional language, its contents can be in regional language, etc. I need read a string in regional language. But I dont want to use `string` or `wstring` to store it. I need `UnicodeString`. Should I include any specific header file for this other than `locale.hpp`? – Jackzz Jul 07 '16 at 04:51
  • @Christian.K: Simple `icu::UnicodeString`? It gives me error.. – Jackzz Jul 07 '16 at 04:51
  • What error? Please indicate in your question what you have tried, and the particular error you got. – Christian.K Jul 07 '16 at 04:52
  • @Christian.K: `'icu' : is not a class or namespace name`.. In which namespace can I find icu? – Jackzz Jul 07 '16 at 04:56
  • Sorry, but frankly this is exhausting. Did you include the relevant header files? Please update your question with the relevant code you used to attempt using UnicodeString. Also check http://stackoverflow.com/help/mcve. – Christian.K Jul 07 '16 at 04:58
  • @Christian.K: I m sorry. but I havent used boost locale yet and this is my first try. I have updated the question with code – Jackzz Jul 07 '16 at 05:06
  • @Jackzz: Are you aware that `wchar_t`, `wstring`, and other such `w`-based-things are *not* required to be a Unicode-encoded format? Nor are they required to be a *specific* Unicode format? And thus, when you read that (presumably Unicode-encoded) file, you are likely to get garbage? – Nicol Bolas Jul 07 '16 at 05:35
  • @NicolBolas: Sorry.. I am not so used with this Unicode related stuff :( . – Jackzz Jul 07 '16 at 05:37
  • Attempting to use UnicodeString *directly* is a bit different. ICU provides APIs for file I/O. If you want to use boost::filesystem as in your example you will get *something*, but likely not the format you expect (ICU internal UnicodeString format). You need to convert it. And for such, you will need to know what the input format starts out. E.g. on Linux, APIs will generally give you UTF-8 & therefor you can do UnicodeString::fromUTF8() for example. – NuSkooler Jul 07 '16 at 17:12
  • @NuSkooler: but isn't that a ICU API?How to call it using boost? I am actually trying to develop a cross platform application with unicode support. – Jackzz Jul 08 '16 at 04:43

0 Answers0