Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Why there is no toTitleCase for QString
QtWS25 Last Chance

[Solved] Why there is no toTitleCase for QString

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 7.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paucoma
    wrote on last edited by
    #1

    Hi Everyone!
    I would like to reformat the case of some text which I recieve at an undetermined format. For Example:

    • illUm QUI dOLOrEm eum ASPeriores REPELLAT

    I have searched for the commonly know function toTitleCase in the Qt database and "found QChar":http://doc.qt.nokia.com/4.7-snapshot/qchar.html#toTitleCase to have this function. In the description of the function:
    [quote]QChar QChar::toTitleCase () const
    Returns the title case equivalent if the character is lowercase or uppercase; otherwise returns the character itself. [/quote]

    • I don't quite understand what this does, or how it should be used.
      ** if you look at a single character alone how will it know if it needs to be titleCased or not?
    • Is there a function under another name which does the same ?
      ** I'm Looking For A Basic Caps Letter At The Begining Of Each Word In The String.

    I was thinking of making a simple algorithm myself to get this done, but if the function already exists then I don't need to reinvent the wheel. :)

    Proposed Algorithm:
    @
    QString str = "illUm QUI dOLOrEm eum ASPeriores REPELLAT";
    QRegExp re("\W\w");
    int pos=-1;
    str = str.toLower();
    QChar * base = str.data();
    QChar * ch;
    do{
    pos++;
    ch = base + pos;
    pos = str.indexOf(re, pos);
    *ch = ch->toUpper();
    }while(pos >= 0);
    @

    Thanks for any constructive criticism / comments / suggestions / contributions, and a great weekend to everyone!

    Edit: Code Error, and better Regular Expression added

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      This is part of what the "unicode standard":http://www.unicode.org/versions/Unicode6.0.0/ch05.pdf#G21180 has to say about titlecase:

      bq. digraph compatibility characters, such as U+01F3 “dz” latin small letter dz, require one form when being uppercased, U+01F1 “DZ” latin capital letter dz, and another form when being titlecased, U+01F2 “Dz” latin capital letter d with small letter z. The latter form is informally referred to as a titlecase character, because it is mixed case, with the first letter uppercase.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        paucoma
        wrote on last edited by
        #3

        Aha!
        Now I understand what TitleCase refers to, thanks for that reference.

        Having read a bit now on how complex an actual proper title casing function would be I see why QString does not incorporate it.

        A solution, for someone who would need proper title casing (not my case), would be adding a style and grammar check library.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          [quote author="Pau" date="1301255549"]Aha!
          Now I understand what TitleCase refers to, thanks for that reference.

          Having read a bit now on how complex an actual proper title casing function would be I see why QString does not incorporate it.

          A solution, for someone who would need proper title casing (not my case), would be adding a style and grammar check library.
          [/quote]

          And of course you would have to adapt it to the localization and internationalization settings to respect the different title casing in different languages.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved