Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Matt Austern wrote a paper on <a href="http://lafstern.org/matt/col2_new.pdf" rel="nofollow">"How to do case-insensitive string comparison"</a> that handles locales properly. It may contain the information on locales and facets that you're looking for.</p> <p>Otherwise, if you're just looking to reverse the usual comparison order of a couple of characters, shouldn't using <code>std::lexicographical_compare</code> with your own comparison function object do the job?</p> <pre><code>bool mycomp( char c1, char c2 ) { // Return 0x5F &lt; 0x30 if ( ( c1 == '_' ) &amp;&amp; ( c2 == '0' ) ) return true; if ( ( c1 == '0' ) &amp;&amp; ( c2 == '_' ) ) return false; return ( c1 &lt; c2 ); } std::string w1 = "word0"; std::string w2 = "word_"; bool t1 = std::lexicographical_compare( w1.begin(), w1.end(), w2.begin(), w2.end() ); bool t2 = std::lexicographical_compare( w1.begin(), w1.end(), w2.begin(), w2.end(), mycomp ); </code></pre> <p><code>"word0"</code> evaluates less than <code>"word_"</code> in the first case, and greater in the second, which is what you're after.</p> <p>If you're already doing something similar, that's the easiest way to go.</p> <p><strong>Edit</strong>: On the subject of using <code>char_traits</code> to accomplish this, Austern's article notes:</p> <blockquote> <p>The Standard Library type <code>std::string</code> uses the traits parameter for all comparisons, so, by providing a traits parameter with equality and less than redefined appropriately, you can instantiate basic_string in such a way so that the <code>&lt;</code> and <code>==</code> operators do what you need. You can do it, but it isn't worth the trouble.</p> <p>You won't be able to do I/O, at least not without a lot of pain. You won't be able use ordinary stream objects like <code>cin</code> and <code>cout</code>.</p> </blockquote> <p>He goes on to list several other good reasons why modifying <code>char_traits</code> to perform this comparison isn't a good idea.</p> <p>I highly recommend that you read Austern's paper.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload