title: How to convert unicode characters to uppercase in C++
body: <p>I'm learning about unicode in C++ and I have a hard time getting it to work properly. I try to treat the individual characters as uint64_t. It works if all I need it for is to print out the characters, but the problem is that I need to convert them to uppercase. I could store the uppercase letters in an array and simply use the same index as I do for the lowercase letters, but I'm looking for a more elegant solution. I found this similar <a href="https://stackoverflow.com/questions/17991431/convert-a-unicode-string-in-c-to-upper-case#17993266">question</a> but most of the answers used wide characters, which is not something I can use. Here is what I have attempted:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;locale&gt;
  #include &lt;string&gt;
  #include &lt;cstdint&gt;
  #include &lt;algorithm&gt;
  
  // hacky solution to store a multibyte character in a uint64_t
  #define E(c) ((((uint64_t) 0 | (uint32_t) c[0]) &lt;&lt; 32) | (uint32_t) c[1])
  
  typedef std::string::value_type char_t;
  char_t upcase(char_t ch) {
      return std::use_facet&lt;std::ctype&lt;char_t&gt;&gt;(std::locale()).toupper(ch);
  }
  
  std::string toupper(const std::string &amp;src) {
      std::string result;
      std::transform(src.begin(), src.end(), std::back_inserter(result), upcase);
      return result;
  }
  
  const uint64_t VOWS_EXTRA[]
  {
  E("å")  , E("ä"), E("ö"), E("ĳ"), E("ø"), E("æ")
  };
  
  int main(void) {
      char name[5];
      std::locale::global(std::locale("sv_SE.UTF8"));
      name[0] = (VOWS_EXTRA[3] &gt;&gt; 32) &amp; ~((uint32_t)0);
      name[1] = VOWS_EXTRA[3] &amp; ~((uint32_t)0);
      name[2] = '\0';
      std::cout &lt;&lt; toupper(name) &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>I expect this to print out the character <code>Ĳ</code> but in reality it prints out the same character as it was in the beginning (<code>ĳ</code>).</p>
  
  <hr>
  
  <p>(<strong>EDIT</strong>: OK, so I read more about the unicode support in standard C++ <a href="https://stackoverflow.com/questions/17103925/how-well-is-unicode-supported-in-c11">here</a>. It seems like my best bet is to use something like ICU or Boost.locale for this task. C++ essentially treats std::string as a blob of binary data so doesn't seem to be an easy task to uppercase unicode letters properly. I think that my hacky solution using uint64_t isn't in any way more useful than the C++ standard library if not even worse. I'd be grateful for an example on how to achieve the behaviour stated above using ICU.)</p>