title: What are "Best Practices" for a Cross-Platform string class to implement good model portability?
body: <p>There are a myriad of discussion threads on the subject of cross-platform Unicode string usage, but it seems there's is a wide range of opinion, without addressing some specific concerns that've been vexing me on a specific project I'm working on:</p>
  
  <p>I have a large cross platform C++ code base that goes back almost twenty years.  It contains a hodge-podge of all manner of string implementations, including:</p>
  
  <ul>
  <li><code>char*</code></li>
  <li>Pascal-style strings</li>
  <li><code>std::string</code></li>
  <li>several custom cross-platform classes with overlapping functionality</li>
  <li><code>CFString</code></li>
  <li>all manner of constant strings</li>
  </ul>
  
  <p>This code base is in the process of being rewritten to entirely use Unicode strings and implementing a strong MVC architecture, with the hope that the model will be fully portable (Mac OS / IOS / Android / Windows 7 &amp; 8 / Unix).</p>
  
  <p>While persistent data is being written as XML/UTF-8, there are some dilemmas regarding string usage in run-time objects:</p>
  
  <ol>
  <li><p>I'd like to create a class that cleanly hides the implementation of storage, allocation and common string operations.  Through the miracle of C++ operator and assignment overloading I'm hoping to be able to substitute a class instance to replace all the different string parameters that functions can accept.  This would allow for an incremental conversion of the code base.</p></li>
  <li><p>We are constantly scanning / parsing / analyzing strings, and I worry that using a strictly UTF-8 underlying implementation for persistent objects might have performance issues.  If not, would the modern std::string found in Microsoft's VC++ and GNU's G++ be a simple underlying implementation?</p></li>
  <li><p>The Mac OS / IOS versions ultimately need to have their strings "converted" to CFString.  The CF functions are rich and highly optimized.  I'm thinking it would be a good strategy to have my own class create CFStrings by providing CF with a buffer (for example, <code>CFStringCreateWithCharactersNoCopy</code> or <code>CFStringCreateMutableWithExternalCharactersNoCopy</code>).  Seems as if this could reduce the amount of conversion/allocation CFString would normally require after fetching data from the model — ALTHOUGH perhaps in a proper MVC implementation the Controller/View shouldn't have access to actual strings owned by the model?</p></li>
  <li><p>Does C++ 11 change the picture for any of these cross-platform string issues?</p></li>
  </ol>
  
  <p>I would've guessed that these issues should have been solved long ago — but from reviewing the responses on this site (and others) I can't see that it has.  </p>