collation.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.6"/>
  7. <title>Boost.Locale: Collation</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="resize.js"></script>
  13. <script type="text/javascript" src="navtree.js"></script>
  14. <script type="text/javascript">
  15. $(document).ready(initResizable);
  16. $(window).load(resizeHeight);
  17. </script>
  18. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  19. </head>
  20. <body>
  21. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  22. <div id="titlearea">
  23. <table cellspacing="0" cellpadding="0">
  24. <tbody>
  25. <tr style="height: 56px;">
  26. <td id="projectlogo"><img alt="Logo" src="boost-small.png"/></td>
  27. <td style="padding-left: 0.5em;">
  28. <div id="projectname">Boost.Locale
  29. </div>
  30. </td>
  31. </tr>
  32. </tbody>
  33. </table>
  34. </div>
  35. <!-- end header part -->
  36. <!-- Generated by Doxygen 1.8.6 -->
  37. <div id="navrow1" class="tabs">
  38. <ul class="tablist">
  39. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  40. <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  41. <li><a href="modules.html"><span>Modules</span></a></li>
  42. <li><a href="namespaces.html"><span>Namespaces</span></a></li>
  43. <li><a href="annotated.html"><span>Classes</span></a></li>
  44. <li><a href="files.html"><span>Files</span></a></li>
  45. <li><a href="examples.html"><span>Examples</span></a></li>
  46. </ul>
  47. </div>
  48. </div><!-- top -->
  49. <div id="side-nav" class="ui-resizable side-nav-resizable">
  50. <div id="nav-tree">
  51. <div id="nav-tree-contents">
  52. <div id="nav-sync" class="sync"></div>
  53. </div>
  54. </div>
  55. <div id="splitbar" style="-moz-user-select:none;"
  56. class="ui-resizable-handle">
  57. </div>
  58. </div>
  59. <script type="text/javascript">
  60. $(document).ready(function(){initNavTree('collation.html','');});
  61. </script>
  62. <div id="doc-content">
  63. <div class="header">
  64. <div class="headertitle">
  65. <div class="title">Collation </div> </div>
  66. </div><!--header-->
  67. <div class="contents">
  68. <div class="textblock"><p>Boost.Locale provides a <a class="el" href="classboost_1_1locale_1_1collator.html">collator</a> class, derived from <code>std::collate</code>, that adds support for primary, secondary, tertiary, quaternary and identical comparison levels. They can be approximately defined as:</p>
  69. <ol type="1">
  70. <li>Primary &ndash; ignore accents and character case, comparing base letters only. For example "facade" and "Façade" are the same.</li>
  71. <li>Secondary &ndash; ignore character case but consider accents. "facade" and "façade" are different but "Façade" and "façade" are the same.</li>
  72. <li>Tertiary &ndash; consider both case and accents: "Façade" and "façade" are different. Ignore punctuation.</li>
  73. <li>Quaternary &ndash; consider all case, accents, and punctuation. The words must be identical in terms of Unicode representation.</li>
  74. <li>Identical &ndash; as quaternary, but compare code points as well.</li>
  75. </ol>
  76. <p>There are two ways of using the <a class="el" href="classboost_1_1locale_1_1collator.html">collator</a> facet: directly, by calling its member functions <a class="el" href="classboost_1_1locale_1_1collator.html#ab90dc7bb909a71d3cd9a5e8d7b2eb80e">compare</a>, <a class="el" href="classboost_1_1locale_1_1collator.html#a8dc6443fb193616332ca50f207a9b189">transform</a> and <a class="el" href="classboost_1_1locale_1_1collator.html#a89752e2023643f972b6cc8024340d5d4">hash</a>, or indirectly by using the <a class="el" href="structboost_1_1locale_1_1comparator.html">comparator</a> template class in STL algorithms.</p>
  77. <p>For example:</p>
  78. <div class="fragment"><div class="line">wstring a=L<span class="stringliteral">&quot;Façade&quot;</span>, b=L<span class="stringliteral">&quot;facade&quot;</span>;</div>
  79. <div class="line"><span class="keywordtype">bool</span> eq = 0 == use_facet&lt;collator&lt;wchar_t&gt; &gt;(loc).compare(collator_base::secondary,a,b);</div>
  80. <div class="line">wcout &lt;&lt; a &lt;&lt;L<span class="stringliteral">&quot; and &quot;</span>&lt;&lt;b&lt;&lt;L<span class="stringliteral">&quot; are &quot;</span> &lt;&lt; (eq ? L<span class="stringliteral">&quot;identical&quot;</span> : L<span class="stringliteral">&quot;different&quot;</span>)&lt;&lt;endl;</div>
  81. </div><!-- fragment --><p><code>std::locale</code> is designed to be useful as a comparison class in STL collections and algorithms. To get similar functionality with comparison levels, you must use the comparator class.</p>
  82. <div class="fragment"><div class="line">std::map&lt;std::string,std::string,comparator&lt;char,collator_base::secondary&gt; &gt; strings;</div>
  83. <div class="line"><span class="comment">// Now strings uses the default system locale for string comparison</span></div>
  84. </div><!-- fragment --><p>You can also set a specific locale or level when creating and using the <a class="el" href="structboost_1_1locale_1_1comparator.html">comparator</a> class:</p>
  85. <div class="fragment"><div class="line">comparator&lt;char&gt; comp(some_locale,some_level);</div>
  86. <div class="line">std::map&lt;std::string,std::string,comparator&lt;char&gt; &gt; strings(comp);</div>
  87. </div><!-- fragment --> </div></div><!-- contents -->
  88. </div><!-- doc-content -->
  89. <li class="footer">
  90. &copy; Copyright 2009-2012 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0.
  91. </li>
  92. </ul>
  93. </div>
  94. </body>
  95. </html>