Results 1 to 3 of 3

Thread: Detect utf8 text/html bool....

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Detect utf8 text/html bool....

    on my small qt4 html editor ... http://ciz.ch/svnciz/forms_shop/html_editor/ part of a crm ...
    if html txt file is ut8 qt transorf txt a 2° way to utf8 ....
    the result >>>> öäü^$ö䠣£ and not autodetect

    If i cann detect or isoeu or utf8 i can manage ond open file on correct codecForMib..

    QTextCodec *codecutf8 = QTextCodec::codecForMib(106);



    I running this small line of php code to check if text is ut8...
    If is possibel to make same on qt4?

    Qt Code:
    1. /* on web page go all to unicode and can show china text on utf8 meta.. */
    2. public static function utf8_check($Str) {
    3. for ($i=0; $i<strlen($Str); $i++) {
    4. if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
    5. elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
    6. elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
    7. elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
    8. elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
    9. elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
    10. else return false; # Does not match any model
    11. for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
    12. if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
    13. return false;
    14. }
    15. }
    16. return true;
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Detect utf8 text/html bool....

    I'm very sorry to say this, but I have a little request for you. Could you try to form better english sentences? I suggest shorter sentences, no abbreviations and simpler words. Also try to form full sentences and preview your posts and correct spelling errors before you submit the post (using a spell checker enabled browser (like Firefox or Konqueror) may come in handy). Sometimes it is very hard to understand what you mean, which may (and I think it does) cause difficulties to answer your questions.

    Now to answer your question. Yes, you can do the same in Qt by scanning each character of the file looking for "known" entities, but it may be very time consuming and there are surely better ways to do this. In most cases you can ask the user to specify which encoding a file uses. An alternative is to look for the encoding knowing the structure of the file in question. For example xml files should begin with the language and encoding declaration. Html files also have a set place where encoding may be specified. Other formats also often have a way to specify encoding.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Detect utf8 text/html bool....

    I understand that my English not being perfect and cause problems...
    Currently I speak 4 languages.... excluded English....
    Italian qt forum not exist... and German forum leaves to wish ...
    Portugues not exist ... French forum is slow to load ...

    With the English spelling check if they are put also of the variable ones qt,
    in sure translations it comes to laugh.

Similar Threads

  1. Thread Problem
    By qball2k5 in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2006, 17:31

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.