/usr/share/doc/libghc-text-icu-doc/html/src/Data-Text-ICU-Collate-Pure.html is in libghc-text-icu-doc 0.7.0.1-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>Data/Text/ICU/Collate/Pure.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{-# LANGUAGE DeriveDataTypeable, ForeignFunctionInterface #-}</span>
<a name="line-2"></a><span class='hs-comment'>-- |</span>
<a name="line-3"></a><span class='hs-comment'>-- Module : Data.Text.ICU.Collate.Pure</span>
<a name="line-4"></a><span class='hs-comment'>-- Copyright : (c) 2010 Bryan O'Sullivan</span>
<a name="line-5"></a><span class='hs-comment'>--</span>
<a name="line-6"></a><span class='hs-comment'>-- License : BSD-style</span>
<a name="line-7"></a><span class='hs-comment'>-- Maintainer : bos@serpentine.com</span>
<a name="line-8"></a><span class='hs-comment'>-- Stability : experimental</span>
<a name="line-9"></a><span class='hs-comment'>-- Portability : GHC</span>
<a name="line-10"></a><span class='hs-comment'>--</span>
<a name="line-11"></a><span class='hs-comment'>-- Pure string collation functions for Unicode, implemented as</span>
<a name="line-12"></a><span class='hs-comment'>-- bindings to the International Components for Unicode (ICU)</span>
<a name="line-13"></a><span class='hs-comment'>-- libraries.</span>
<a name="line-14"></a><span class='hs-comment'>--</span>
<a name="line-15"></a><span class='hs-comment'>-- For the impure collation API (which is richer, but less easy to</span>
<a name="line-16"></a><span class='hs-comment'>-- use), see the "Data.Text.ICU.Collate" module.</span>
<a name="line-17"></a>
<a name="line-18"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span><span class='hs-varop'>.</span><span class='hs-conid'>ICU</span><span class='hs-varop'>.</span><span class='hs-conid'>Collate</span><span class='hs-varop'>.</span><span class='hs-conid'>Pure</span>
<a name="line-19"></a> <span class='hs-layout'>(</span>
<a name="line-20"></a> <span class='hs-comment'>-- * Unicode collation API</span>
<a name="line-21"></a> <span class='hs-comment'>-- $api</span>
<a name="line-22"></a> <span class='hs-conid'>Collator</span>
<a name="line-23"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>collator</span>
<a name="line-24"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>collatorWith</span>
<a name="line-25"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>collate</span>
<a name="line-26"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>collateIter</span>
<a name="line-27"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>sortKey</span>
<a name="line-28"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>uca</span>
<a name="line-29"></a> <span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-30"></a>
<a name="line-31"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span> <span class='hs-layout'>(</span><span class='hs-varid'>forM_</span><span class='hs-layout'>)</span>
<a name="line-32"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-layout'>(</span><span class='hs-conid'>ByteString</span><span class='hs-layout'>)</span>
<a name="line-33"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span> <span class='hs-layout'>(</span><span class='hs-conid'>Text</span><span class='hs-layout'>)</span>
<a name="line-34"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span><span class='hs-varop'>.</span><span class='hs-conid'>ICU</span><span class='hs-varop'>.</span><span class='hs-conid'>Collate</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span> <span class='hs-layout'>(</span><span class='hs-conid'>Collator</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-35"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span><span class='hs-varop'>.</span><span class='hs-conid'>ICU</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span> <span class='hs-layout'>(</span><span class='hs-conid'>CharIterator</span><span class='hs-layout'>,</span> <span class='hs-conid'>LocaleName</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-36"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-conid'>Unsafe</span> <span class='hs-layout'>(</span><span class='hs-varid'>unsafePerformIO</span><span class='hs-layout'>)</span>
<a name="line-37"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Text</span><span class='hs-varop'>.</span><span class='hs-conid'>ICU</span><span class='hs-varop'>.</span><span class='hs-conid'>Collate</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>IO</span>
<a name="line-38"></a>
<a name="line-39"></a><span class='hs-comment'>-- $api</span>
<a name="line-40"></a><span class='hs-comment'>--</span>
<a name="line-41"></a>
<a name="line-42"></a><a name="collator"></a><span class='hs-comment'>-- | Create an immutable 'Collator' for comparing strings.</span>
<a name="line-43"></a><span class='hs-comment'>--</span>
<a name="line-44"></a><span class='hs-comment'>-- If 'Root' is passed as the locale, UCA collation rules will be</span>
<a name="line-45"></a><span class='hs-comment'>-- used.</span>
<a name="line-46"></a><span class='hs-definition'>collator</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LocaleName</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Collator</span>
<a name="line-47"></a><span class='hs-definition'>collator</span> <span class='hs-varid'>loc</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafePerformIO</span> <span class='hs-varop'>$</span> <span class='hs-conid'>C</span> <span class='hs-varop'>`fmap`</span> <span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-varid'>open</span> <span class='hs-varid'>loc</span>
<a name="line-48"></a>
<a name="line-49"></a><a name="collatorWith"></a><span class='hs-comment'>-- | Create an immutable 'Collator' with the given 'Attribute's.</span>
<a name="line-50"></a><span class='hs-definition'>collatorWith</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>LocaleName</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-conid'>Attribute</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Collator</span>
<a name="line-51"></a><span class='hs-definition'>collatorWith</span> <span class='hs-varid'>loc</span> <span class='hs-varid'>atts</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafePerformIO</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
<a name="line-52"></a> <span class='hs-varid'>mc</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-varid'>open</span> <span class='hs-varid'>loc</span>
<a name="line-53"></a> <span class='hs-varid'>forM_</span> <span class='hs-varid'>atts</span> <span class='hs-varop'>$</span> <span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-varid'>setAttribute</span> <span class='hs-varid'>mc</span>
<a name="line-54"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-conid'>C</span> <span class='hs-varid'>mc</span><span class='hs-layout'>)</span>
<a name="line-55"></a>
<a name="line-56"></a><a name="collate"></a><span class='hs-comment'>-- | Compare two strings.</span>
<a name="line-57"></a><span class='hs-definition'>collate</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Collator</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Text</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Text</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ordering</span>
<a name="line-58"></a><span class='hs-definition'>collate</span> <span class='hs-layout'>(</span><span class='hs-conid'>C</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafePerformIO</span> <span class='hs-varop'>$</span> <span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-varid'>collate</span> <span class='hs-varid'>c</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
<a name="line-59"></a><span class='hs-comment'>{-# INLINE collate #-}</span>
<a name="line-60"></a>
<a name="line-61"></a><a name="collateIter"></a><span class='hs-comment'>-- | Compare two 'CharIterator's.</span>
<a name="line-62"></a><span class='hs-comment'>--</span>
<a name="line-63"></a><span class='hs-comment'>-- If either iterator was constructed from a 'ByteString', it does not</span>
<a name="line-64"></a><span class='hs-comment'>-- need to be copied or converted beforehand, so this function can be</span>
<a name="line-65"></a><span class='hs-comment'>-- quite cheap.</span>
<a name="line-66"></a><span class='hs-definition'>collateIter</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Collator</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>CharIterator</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>CharIterator</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Ordering</span>
<a name="line-67"></a><span class='hs-definition'>collateIter</span> <span class='hs-layout'>(</span><span class='hs-conid'>C</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafePerformIO</span> <span class='hs-varop'>$</span> <span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-varid'>collateIter</span> <span class='hs-varid'>c</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span>
<a name="line-68"></a><span class='hs-comment'>{-# INLINE collateIter #-}</span>
<a name="line-69"></a>
<a name="line-70"></a><a name="sortKey"></a><span class='hs-comment'>-- | Create a key for sorting the 'Text' using the given 'Collator'.</span>
<a name="line-71"></a><span class='hs-comment'>-- The result of comparing two 'ByteString's that have been</span>
<a name="line-72"></a><span class='hs-comment'>-- transformed with 'sortKey' will be the same as the result of</span>
<a name="line-73"></a><span class='hs-comment'>-- 'collate' on the two untransformed 'Text's.</span>
<a name="line-74"></a><span class='hs-definition'>sortKey</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Collator</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Text</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ByteString</span>
<a name="line-75"></a><span class='hs-definition'>sortKey</span> <span class='hs-layout'>(</span><span class='hs-conid'>C</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unsafePerformIO</span> <span class='hs-varop'>.</span> <span class='hs-conid'>IO</span><span class='hs-varop'>.</span><span class='hs-varid'>sortKey</span> <span class='hs-varid'>c</span>
<a name="line-76"></a><span class='hs-comment'>{-# INLINE sortKey #-}</span>
<a name="line-77"></a>
<a name="line-78"></a><a name="uca"></a><span class='hs-comment'>-- | A 'Collator' that uses the Unicode Collation Algorithm (UCA).</span>
<a name="line-79"></a><span class='hs-definition'>uca</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Collator</span>
<a name="line-80"></a><span class='hs-definition'>uca</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>collator</span> <span class='hs-conid'>Root</span>
<a name="line-81"></a><span class='hs-comment'>{-# NOINLINE uca #-}</span>
</pre></body>
</html>
|