title: Unicode case folding to upper case
body: <p>I'm trying to implement a library for reading Microsoft CFB (Compound File Binary) Format files, according to the official specification of that format. The specification is available <a href="http://msdn.microsoft.com/en-us/library/dd942138.aspx">from this site</a>.</p>
  
  <p>In a nutshell - some of the structures of the file are stored in a red-black tree. I've got a problem with the comparison predicate used for storing these structures in that tree. The specification says that, if the names (the strings are stored as UTF-16, the standard in Windows APIs) of these structures are different, it is necessary to iterate through every UTF-16 code point and :</p>
  
  <blockquote>
    <p>(...) convert to <strong>upper-case</strong> with the Unicode Default Case Conversion
    Algorithm, simple case conversion variant (<strong>simple case foldings</strong>), with the following notes.&lt;2> Compare each upper-cased UTF-16 code point binary value.</p>
  </blockquote>
  
  <p>The <code>&lt;2&gt;</code> reference says that :</p>
  
  <blockquote>
    <p>or Windows XP and Windows Server 2003: The compound file implementation
    conforms to the Unicode 3.0.1 Default Case Conversion Algorithm, simple case folding
    (<a href="http://www.unicode.org/Public/3.1-Update1/CaseFolding-4.txt">http://www.unicode.org/Public/3.1-Update1/CaseFolding-4.txt</a>) with the following exceptions.</p>
  </blockquote>
  
  <p>However, when I looked up the referenced case folding file, and read the <a href="http://www.unicode.org/reports/tr21/tr21-5.html">UTR #21 "Case Mapping"</a> referenced there, I realized that the case folding is defined as an operation that bears much more resemblance to lower-casing, rather than upper-casing.</p>
  
  <p>By using <code>CaseFolding-4.txt</code>, we can obtain the case folding mappings of upper-case letters to lower-case ones. The mapping is always 1-to-1, since full foldings (those that expand to multiple characters) aren't needed here. However, the reverse mapping of lower-case letters to upper-case ones isn't straightforward anymore. For example, </p>
  
  <pre><code>0392; C; 03B2; # GREEK CAPITAL LETTER BETA
  03D0; C; 03B2; # GREEK BETA SYMBOL
  </code></pre>
  
  <p>Thus, we have no way of knowing whether <code>03B2</code> should be converted to <code>0392</code> or <code>03D0</code>. Does the standard define something like folding to upper-case? Maybe I should use case folding, and then convert to upper-case? Or have I understood the specification completely wrong?</p>