collation.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 filetype=cpp.doxygen
  9. /*!
  10. \page collation Collation
  11. Boost.Locale provides a \ref boost::locale::collator "collator" class, derived from \c std::collate, that adds support for
  12. primary, secondary, tertiary, quaternary and identical comparison levels. They can be approximately defined as:
  13. -# Primary -- ignore accents and character case, comparing base letters only. For example "facade" and "Façade" are the same.
  14. -# Secondary -- ignore character case but consider accents. "facade" and "façade" are different but "Façade" and "façade" are the same.
  15. -# Tertiary -- consider both case and accents: "Façade" and "façade" are different. Ignore punctuation.
  16. -# Quaternary -- consider all case, accents, and punctuation. The words must be identical in terms of Unicode representation.
  17. -# Identical -- as quaternary, but compare code points as well.
  18. There are two ways of using the \ref boost::locale::collator "collator" facet: directly, by calling its member functions \ref boost::locale::collator::compare() "compare", \ref boost::locale::collator::transform() "transform" and \ref
  19. boost::locale::collator::hash() "hash", or indirectly by using the \ref boost::locale::comparator "comparator" template
  20. class in STL algorithms.
  21. For example:
  22. \code
  23. wstring a=L"Façade", b=L"facade";
  24. bool eq = 0 == use_facet<collator<wchar_t> >(loc).compare(collator_base::secondary,a,b);
  25. wcout << a <<L" and "<<b<<L" are " << (eq ? L"identical" : L"different")<<endl;
  26. \endcode
  27. \c std::locale is designed to be useful as a comparison class in STL collections and algorithms.
  28. To get similar functionality with comparison levels, you must use the comparator class.
  29. \code
  30. std::map<std::string,std::string,comparator<char,collator_base::secondary> > strings;
  31. // Now strings uses the default system locale for string comparison
  32. \endcode
  33. You can also set a specific locale or level when creating and using the \ref boost::locale::comparator "comparator" class:
  34. \code
  35. comparator<char> comp(some_locale,some_level);
  36. std::map<std::string,std::string,comparator<char> > strings(comp);
  37. \endcode
  38. */