1

For last two days I've been trying to convert utf-8 string to cp437 string and I've already tried this answer.

Example situation would be converting char *utf8="\xC2\xBB" to char *cp437="\xAF" (or 175 decimal if you will).

I came up with many variations of this:

struct ConsoleOutputWrapper {
    boost::locale::generator generator;

    std::string c_output; // Charset name
    std::locale l_output; // Locale

    ConsoleOutputWrapper() :
        generator(),
        c_output("CP437")
    {
        generator.locale_cache_enabled(true);
        l_output = generator(c_output);
    }

    void operator<<(const char* str)
    {
        std::cout << boost::locale::conv::from_utf<char>(str, l_output);
    }
};

// Test
ConsoleOutputWrapper k;
k << "\xc2\xbb";

But the best conversion I've got to was > instead of ยป.

Any ideas how to convert special characters like these using boost?

Community
  • 1
  • 1
Vyktor
  • 20,559
  • 6
  • 64
  • 96
  • You would have to check the documentation but boost may not have a good mapping for that. You might want to try the [ICU library](http://site.icu-project.org/) instead โ€“ Mgetz Jul 25 '13 at 15:54
  • @Mgetz I'd consider that to be a perfectly valid answer :) although I prefer some references for things like this. Anyway as far as I can tell, [boost can be told to be compiled with ICU](http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/building_boost_locale.html). โ€“ Vyktor Jul 25 '13 at 16:01
  • If I had them I would have posted as an answer, generally though people seem to be recommending ICU for handling character set handling in C++ so I thought I would mention it so you could make up your own mind. โ€“ Mgetz Jul 25 '13 at 16:05

0 Answers0