has_icu_test.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. *
  3. * Copyright (c) 2010
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. #include <unicode/uversion.h>
  12. #include <unicode/utypes.h>
  13. #include <unicode/uchar.h>
  14. #include <unicode/coll.h>
  15. #include <boost/scoped_ptr.hpp>
  16. #include <iostream>
  17. #include <iomanip>
  18. #if defined(_MSC_VER) && !defined(_DLL)
  19. //#error "Mixing ICU with a static runtime doesn't work"
  20. #endif
  21. void print_error(UErrorCode err, const char* func)
  22. {
  23. std::cerr << "Error from function " << func << " with error: " << ::u_errorName(err) << std::endl;
  24. }
  25. int main()
  26. {
  27. // To detect possible binary mismatches between the installed ICU build, and whatever
  28. // C++ std lib's we're using, we need to:
  29. // * Make sure we call ICU C++ API's
  30. // * Make sure we call std lib C++ API's as well (cout).
  31. // * Be sure this program is run, not just built.
  32. UErrorCode err = U_ZERO_ERROR;
  33. UChar32 c = ::u_charFromName(U_UNICODE_CHAR_NAME, "GREEK SMALL LETTER ALPHA", &err);
  34. std::cout << (int)c << std::endl;
  35. if(err > 0)
  36. {
  37. print_error(err, "u_charFromName");
  38. return err;
  39. }
  40. U_NAMESPACE_QUALIFIER Locale l;
  41. boost::scoped_ptr<U_NAMESPACE_QUALIFIER Collator> p_col(U_NAMESPACE_QUALIFIER Collator::createInstance(l, err));
  42. if(err > 0)
  43. {
  44. print_error(err, "Collator::createInstance");
  45. return err;
  46. }
  47. return err > 0 ? err : 0;
  48. }