Results 1 to 2 of 2

Thread: QUrl and EUC-JP

  1. #1
    Join Date
    Feb 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QUrl and EUC-JP

    Hi!

    I have the next bash script to url encoding japanese text:

    Qt Code:
    1. echo "$UTF8_TEXT" | iconv -f UTF-8 -t EUC-JP | od --width=512 -t x1 -A n | sed -e 's/ 0a$//g' -e 's/ /\%/g'
    To copy to clipboard, switch view to plain text mode 

    I take a japanese name in "UTF-8", encoded in "EUC-JP" using "iconv" and, finally, generate a % encoding usind "od" and "sed". For example:

    UTF-8 text: 宇多田ヒカル
    encoded text: %b1%a7%c2%bf%c5%c4%a5%d2%a5%ab%a5%eb

    I try using QUrl in Javascript for a week but I fail . My last try was:

    Qt Code:
    1. var codecName = new QByteArray("EUC-JP");
    2. var codec = new QTextCodec.codecForName(codecName);
    3. var url = new QUrl("http://music.goo.ne.jp/lyric/db.php");
    4. url.addQueryItem("a", codec.fromUnicode(artist));
    5. url.addQueryItem("k", codec.fromUnicode(title));
    6. url.addQueryItem("l", "");
    7. url.addQueryItem("s", "");
    8. url.addQueryItem("c", "");
    9. url.addQueryItem("submit", "");
    To copy to clipboard, switch view to plain text mode 

    When I try to download the html page, server searching fails for incorrect enconding. The site require % encoding in EUC-JP to works.

    For context, I'm trying to convert a bash script I'm using to download japanese lyrics from music.goo.ne.jp to an Amarok 2 script.

    Thank's in advance.

  2. #2
    Join Date
    Feb 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QUrl and EUC-JP

    I solved my problem using Amarok.Lyrics.fromUtf8(), QUrl.setEncodedQuery() and a custom function.
    Qt Code:
    1. encodedTitle = new QByteArray(Amarok.Lyrics.fromUtf8(title, "EUC-JP"));
    2. var url = new QUrl(URL_SEARCH + "/lyric/db.php");
    3. url.setEncodedQuery(new QByteArray("a=" + ba2p(encodedArtist));"
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. function ba2p(ba) {
    2. var str = '';
    3. for (i = 0; i < ba.length(); i++) {
    4. str += '%' + toHex(ba.at(i));
    5. }
    6. return str;
    7. }
    To copy to clipboard, switch view to plain text mode 

Tags for this Thread

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.