Results 1 to 4 of 4

Thread: Replacing polish diacritics in the string

  1. #1
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Replacing polish diacritics in the string

    What would you propose if I said that I need to the replace polish diacritics in the string.

    I was thinking of using const array of these chars
    and iterating over the string (or using regexp) and replacing found diacritics with their equivalents.
    for example string like this "koło" should be passed further as "kolo" which means that character on the 3 position ł should be replaced by l?

    or

    preparing simple QValidator but I never used that . I found it has member setLocale() which might be useful.

    What would you suggest and what are your opinions about my ideas
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Replacing polish diacritics in the string

    First solution that comes to my mind is to create a QMap<QChar,QChar> with polish diactrics <-> desired characted mapping, and use QString::replace() :
    Qt Code:
    1. void removeDiactrics( QString * str ){
    2. foreach( QChar c, _diactrics.keys() ){
    3. str->replace(c, _diacrtics[c]);
    4. }
    5. }
    To copy to clipboard, switch view to plain text mode 

    This is maybe not the best solution for this problem, and I'd really like to see some comments on this from others.

    QValidator is ok if you want to check the string input while user is typing, for example in QLineEdit, and QLocale is used for string <-> numbers conversions in different languages, so I dont see how this may help here. Maybe I undestood you wrong, but I was thinking about diacrtics replacement in any QString object anywhere in program.

  3. The following user says thank you to stampede for this useful post:

    kornicameister (8th February 2011)

  4. #3
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Replacing polish diacritics in the string

    to be precise I need everywhere user wants to search for something in the database
    and he is typing a criteria.

    No matter what he has typed (big letters mixed with small letters, polish diacritics or no polish diacritics ) the searching must return valid results as the db holds rough data.

    Solution you came up with is better than mine, and thanks, because If I got you correctly what you propose is to have map where keys are polish diacritics, right ?
    It is better than const array, however I will make this map constant.

    One problem left is if there is a need to encapsulate such simple functionality in the class. But I think I will do so, which will leave the open way to maybe extend it
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  5. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Replacing polish diacritics in the string

    Great I could be of any help
    map where keys are polish diacritics
    Yes, exactly.

Similar Threads

  1. Replacing QtScript with QML
    By inpoculis789 in forum Newbie
    Replies: 0
    Last Post: 19th July 2010, 13:59
  2. Problem replacing a value in a QList.
    By bbad68 in forum Newbie
    Replies: 4
    Last Post: 29th January 2010, 17:14
  3. Qt for S60, problem with bold polish characters
    By Wiktor in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 26th August 2009, 09:37
  4. QDevelop needs Dutch and Polish translators
    By jlbrd in forum Qt-based Software
    Replies: 0
    Last Post: 4th December 2007, 17:54
  5. Replacing One image with another
    By merry in forum Qt Tools
    Replies: 6
    Last Post: 8th February 2007, 13:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.