File: has_icu_test.cpp

package info (click to toggle)
boost1.62 1.62.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 686,420 kB
  • sloc: cpp: 2,609,004; xml: 972,558; ansic: 53,674; python: 32,437; sh: 8,829; asm: 3,071; cs: 2,121; makefile: 964; perl: 859; yacc: 472; php: 132; ruby: 94; f90: 55; sql: 13; csh: 6
file content (52 lines) | stat: -rw-r--r-- 1,512 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 *
 * Copyright (c) 2010
 * John Maddock
 *
 * Use, modification and distribution are subject to the 
 * Boost Software License, Version 1.0. (See accompanying file 
 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 *
 */

#include <unicode/uversion.h>
#include <unicode/utypes.h>
#include <unicode/uchar.h>
#include <unicode/coll.h>
#include <boost/scoped_ptr.hpp>
#include <iostream>
#include <iomanip>

#if defined(_MSC_VER) && !defined(_DLL)
//#error "Mixing ICU with a static runtime doesn't work"
#endif

void print_error(UErrorCode err, const char* func)
{
   std::cerr << "Error from function " << func << " with error: " << ::u_errorName(err) << std::endl;
}

int main()
{
   // To detect possible binary mismatches between the installed ICU build, and whatever
   // C++ std lib's we're using, we need to:
   // * Make sure we call ICU C++ API's
   // * Make sure we call std lib C++ API's as well (cout).
   // * Be sure this program is run, not just built.
   UErrorCode err = U_ZERO_ERROR;
   UChar32 c = ::u_charFromName(U_UNICODE_CHAR_NAME, "GREEK SMALL LETTER ALPHA", &err);
   std::cout << (int)c << std::endl;
   if(err > 0)
   {
      print_error(err, "u_charFromName");
      return err;
   }
   U_NAMESPACE_QUALIFIER Locale l;
   boost::scoped_ptr<U_NAMESPACE_QUALIFIER Collator> p_col(U_NAMESPACE_QUALIFIER Collator::createInstance(l, err));
   if(err > 0)
   {
      print_error(err, "Collator::createInstance");
      return err;
   }
   return err > 0 ? err : 0;
}