title: Firebreath and UTF-16
body: <p>I'm working on an international plugin, and I've run into trouble with UTF-16 strings. I'm trying to store logs to %APPDATA% using FB::FactoryBase::GetLoggingMethods. Currently it's defined like this:</p>
  
  <pre><code>void getLoggingMethods(FB::Log::LogMethodList&amp; outMethods) {
    try {
      boost::filesystem::path appDataPath = FB::System::getLocalAppDataPath("AppName");
      boost::filesystem::path logDirPath = appDataPath / "Logs";
  
      if(!exists(logDirPath)) {
          // create the directory
          boost::filesystem::create_directories(logDirPath);
      }
  
      if (exists(logDirPath) &amp;&amp; is_directory(logDirPath)) {
          boost::filesystem::path logPath = logDirPath / "app_name.log";
  
      outMethods.push_back(std::make_pair(FB::Log::LogMethod_File, logPath.string()));
          }
      } catch(...) { /* safely fail here */ }
  }
  </code></pre>
  
  <p>The problem occurs when the user has a UTF-16 character in their username. This throws an exception.</p>
  
  <p>But, <code>outMethods.push_back</code> requires a <code>std::string</code> for input. Converting from <code>std::wstring</code> to <code>std::string</code> loses that UTF-16 character (which makes the path invalid.)</p>
  
  <p>Any ideas?</p>
  
  <p>EDIT: managed to get it working by giving boost::filesystem::path a LPCWSTR for its constructor.</p>
  
  <pre><code>boost::filesystem::path appDataPath = 
      FB::utf8_to_wstring(FB::System::getLocalAppDataPath("AppName")).c_str();
  
  boost::filesystem::path logDirPath = appDataPath / "Logs";
  
  if(!exists(logDirPath)) {
       // create the directory
       boost::filesystem::create_directories(logDirPath);
  }
  
  if (exists(logDirPath) &amp;&amp; is_directory(logDirPath)) {
      boost::filesystem::path logPath = logDirPath / "app_name.log";
  
      outMethods.push_back(
           std::make_pair(
               FB::Log::LogMethod_File, FB::wstring_to_utf8(logPath.wstring())
           )
      );
   }
  </code></pre>