3

I have some troubles with using boost::locale (1.49) on Debian 7 GNU/Linux (version of GCC is 4.6.3-1). The code is saved in cp1251. Using functions like "isalpha" (or "boost::algorithm::is_alpha") ends up with exception (bad_cast). Looks like that there's no proper facet for this check. Here's the code:

#include <iostream>

#include <boost/locale.hpp>

int main ()
{
  boost::locale::generator gen;
  std::locale loc(gen.generate("ru_RU.cp1251"));
  unsigned char debug501 = 'Б';
  bool debug500 = std::isalpha(debug501, loc);
  std::cout<< debug500;

  return 0;
}

It runs with no exception on Windows 7 with Visual Studio 2008. However, there's still one trouble: "debug500" is set to false in this case. It works fine only when locale is generated like this: std::locale loc(".1251"). But the same issue appears when locale is generated by boost: std::locale loc(boost::locale::generator().generate("ru_RU.cp1251"));. I would be thankful if someone could explain what's wrong with the code and/or how I can make a similar check (isalpha) using boost and std with cp1251 locale.

Nemo
  • 155
  • 1
  • 7

1 Answers1

0

Replace:

unsigned char debug501 = 'Б';

with:

char debug501 = 'Б';
Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
  • Thanks for the answer, there's no exception now. However, there's still one trouble: "debug500" is set false in this case. I was wrong about Visual Studio, it works fine when locale is generated like this:`std::locale loc(".1251")`. But the same issue appears when locale is generated by boost: `std::locale loc(boost::locale::generator().generate("ru_RU.cp1251"));`. – Nemo May 22 '12 at 07:30