• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 #include <unicode/uversion.h>
13 #include <unicode/utypes.h>
14 #include <unicode/uchar.h>
15 #include <unicode/coll.h>
16 #include <boost/scoped_ptr.hpp>
17 #include <iostream>
18 #include <iomanip>
19 
20 #if defined(_MSC_VER) && !defined(_DLL)
21 //#error "Mixing ICU with a static runtime doesn't work"
22 #endif
23 
print_error(UErrorCode err,const char * func)24 void print_error(UErrorCode err, const char* func)
25 {
26    std::cerr << "Error from function " << func << " with error: " << ::u_errorName(err) << std::endl;
27 }
28 
main()29 int main()
30 {
31    // To detect possible binary mismatches between the installed ICU build, and whatever
32    // C++ std lib's we're using, we need to:
33    // * Make sure we call ICU C++ API's
34    // * Make sure we call std lib C++ API's as well (cout).
35    // * Be sure this program is run, not just built.
36    UErrorCode err = U_ZERO_ERROR;
37    UChar32 c = ::u_charFromName(U_UNICODE_CHAR_NAME, "GREEK SMALL LETTER ALPHA", &err);
38    std::cout << (int)c << std::endl;
39    if(err > 0)
40    {
41       print_error(err, "u_charFromName");
42       return err;
43    }
44    U_NAMESPACE_QUALIFIER Locale l;
45    boost::scoped_ptr<U_NAMESPACE_QUALIFIER Collator> p_col(U_NAMESPACE_QUALIFIER Collator::createInstance(l, err));
46    if(err > 0)
47    {
48       print_error(err, "Collator::createInstance");
49       return err;
50    }
51    return err > 0 ? err : 0;
52 }
53