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. html encoding
Forum Updated to NodeBB v4.3 + New Features

html encoding

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 2.7k Views 3 Watching
  • 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #2

    https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped

    (Z(:^

    1 Reply Last reply
    2
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #3

      Hm although that probably won't work for é character :/

      (Z(:^

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #4

        Perhaps QUrl would work better here https://doc.qt.io/qt-5/qurl.html#toPercentEncoding

        (Z(:^

        1 Reply Last reply
        0
        • mrdebugM mrdebug

          Hi, is there a function to translate a standard charset word to html? For example:

          "perché" -> "perché"
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #5

          @mrdebug
          you can traverse the string char-wise and replace each unicode character >= 128 with &#<num> or &#x<unicode-hex-val>
          For the named entities (like &eacute;) you once will need to create a static replacement map.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          6
          • JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #6

            @sierdzio

            Perhaps QUrl would work better here https://doc.qt.io/qt-5/qurl.html#toPercentEncoding

            I have been known in the past to "cheat" by using url encoding rules on HTML (e.g. in JavaScript) like @sierdzio suggests. But be aware the rules are not the same (HTML encoing != URL encoding), it's naughty and does not work in all cases.

            Like @raven-worx says, if you want things like &eacute; you have to do this by hand every time, following voluminous lists like the reference he gives. Why languages/libraries do not seem to supply a useful function for this because it gets asked/wanted a lot, I do not know.

            1 Reply Last reply
            3
            • mrdebugM Offline
              mrdebugM Offline
              mrdebug
              wrote on last edited by
              #7

              Many thanks for your support. I need only a function to translate the IoT device descriptions in a correct html format to send notification emails.
              So this function is enough for me.

              QString TextToHTML(QString Value) {
                  Value.replace("à", "&agrave;");
                  Value.replace("è", "&egrave;");
                  Value.replace("é", "&eacute;");
                  Value.replace("ì", "&igrave;");
                  Value.replace("ò", "&ograve;");
                  Value.replace("ù", "&agrave;");
                  return Value;
              }
              

              This function is not so cool but could be enough.

              Need programmers to hire?
              www.labcsp.com
              www.denisgottardello.it
              GMT+1
              Skype: mrdebug

              JonBJ raven-worxR 2 Replies Last reply
              0
              • mrdebugM mrdebug

                Many thanks for your support. I need only a function to translate the IoT device descriptions in a correct html format to send notification emails.
                So this function is enough for me.

                QString TextToHTML(QString Value) {
                    Value.replace("à", "&agrave;");
                    Value.replace("è", "&egrave;");
                    Value.replace("é", "&eacute;");
                    Value.replace("ì", "&igrave;");
                    Value.replace("ò", "&ograve;");
                    Value.replace("ù", "&agrave;");
                    return Value;
                }
                

                This function is not so cool but could be enough.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #8

                @mrdebug
                Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like < -> &lt; ? I always do at least the 4: &lt;, &amp;, &quot; & &apos;. @sierdzio 's https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped will do you for that. You might like to call that [at the start of, not the end!] in your TextToHTML() function.

                aha_1980A 1 Reply Last reply
                0
                • mrdebugM mrdebug

                  Many thanks for your support. I need only a function to translate the IoT device descriptions in a correct html format to send notification emails.
                  So this function is enough for me.

                  QString TextToHTML(QString Value) {
                      Value.replace("à", "&agrave;");
                      Value.replace("è", "&egrave;");
                      Value.replace("é", "&eacute;");
                      Value.replace("ì", "&igrave;");
                      Value.replace("ò", "&ograve;");
                      Value.replace("ù", "&agrave;");
                      return Value;
                  }
                  

                  This function is not so cool but could be enough.

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by raven-worx
                  #9

                  @mrdebug said in html encoding:
                  instead of

                  Value.replace("à", "&agrave;");
                  

                  better do

                  Value.replace( QChar(0x00C0)/*à*/,  QStringLiteral("&agrave;"));
                  

                  it's more robust.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @mrdebug
                    Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like < -> &lt; ? I always do at least the 4: &lt;, &amp;, &quot; & &apos;. @sierdzio 's https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped will do you for that. You might like to call that [at the start of, not the end!] in your TextToHTML() function.

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @JonB said in html encoding:

                    @mrdebug
                    Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like < -> &lt; ? I always do at least the 4: &lt;, &amp;, &quot; & &apos;.

                    That is, as @sierdzio already pointed out, https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped

                    Qt has to stay free or it will die.

                    JonBJ 1 Reply Last reply
                    1
                    • aha_1980A aha_1980

                      @JonB said in html encoding:

                      @mrdebug
                      Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like < -> &lt; ? I always do at least the 4: &lt;, &amp;, &quot; & &apos;.

                      That is, as @sierdzio already pointed out, https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #11

                      @aha_1980 Yep, missed that, corrected my post.

                      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